This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 159502 - javax.swing.text.BadLocationException: end=61 > length()=60
Summary: javax.swing.text.BadLocationException: end=61 > length()=60
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: issues@editor
URL: http://statistics.netbeans.org/except...
Keywords:
: 164183 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-03-03 10:34 UTC by Exceptions Reporter
Modified: 2009-11-25 07:21 UTC (History)
12 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 146269


Attachments
stacktrace (7.25 KB, text/plain)
2009-03-03 10:34 UTC, Exceptions Reporter
Details
Stack trace where the length works a wrong way (1.68 KB, text/plain)
2009-11-24 04:40 UTC, Nikita Krjukov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Exceptions Reporter 2009-03-03 10:34:28 UTC
Build: NetBeans IDE Dev (Build 200902231810)
VM: Java HotSpot(TM) Client VM, 11.2-b01, Java(TM) SE Runtime Environment, 1.6.0_12-b04
OS: Windows XP, 5.1, x86

User Comments:
jdwyah: large rhtml file

GUEST: Editing an ERB file trying to insert a link_to tag.

GUEST: Editing rhtml file



Stacktrace: 
javax.swing.text.BadLocationException: end=61 > length()=60
        at org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(DocumentUtilities.java:333)
        at org.netbeans.modules.ruby.rhtml.EmbeddedSectionsHighlighting.isWhitespace(EmbeddedSectionsHighlighting.java:147)
        at org.netbeans.modules.ruby.rhtml.EmbeddedSectionsHighlighting.access$200(EmbeddedSectionsHighlighting.java:77)
        at org.netbeans.modules.ruby.rhtml.EmbeddedSectionsHighlighting$Highlights.moveNext(EmbeddedSectionsHighlighting.java:216)
        at org.netbeans.spi.editor.highlighting.support.OffsetsBag.addAllHighlightsImpl(OffsetsBag.java:723)
        at org.netbeans.spi.editor.highlighting.support.OffsetsBag.addAllHighlights(OffsetsBag.java:184)
Comment 1 Exceptions Reporter 2009-03-03 10:34:32 UTC
Created attachment 77612 [details]
stacktrace
Comment 2 Exceptions Reporter 2009-03-07 16:32:35 UTC
This issue has already 10 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=146269
Comment 3 Vitezslav Stejskal 2009-03-24 17:21:06 UTC
Easily reproducible:

1. in an empty rhtml file type <%, the closing %> will automatically be added, so the line will look like <%|%>
2. press enter and this exception will pop up
Comment 4 Vitezslav Stejskal 2009-03-24 17:21:55 UTC
local changeset: 4f89b3155bc7
Comment 5 Vitezslav Stejskal 2009-03-26 13:35:27 UTC
I had to revert http://hg.netbeans.org/jet-main/rev/4f89b3155bc7, because it was causing commit-validation failuers.

http://hg.netbeans.org/jet-main/rev/c20cf3c564dd
Comment 6 Quality Engineering 2009-03-27 03:33:58 UTC
Integrated into 'main-golden', will be available in build *200903261933* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/4f89b3155bc7
User: Vita Stejskal <vstejskal@netbeans.org>
Log: #159502 - allow access to the artificial '\n' at the end of a document
Comment 7 Martin Schovanek 2009-05-04 10:40:11 UTC
Still reproducible by vstejskal steps.
Comment 8 Martin Schovanek 2009-05-04 12:37:45 UTC
40 duplicates => P2
Comment 9 Erno Mononen 2009-05-07 12:45:01 UTC
Vito, how do you think this should be fixed if not like in 4f89b3155bc7? AFAICT this is not a regression in ruby.rhtml.
Comment 10 Vitezslav Stejskal 2009-05-11 10:29:25 UTC
I don't know, will have to have a closer look.
Comment 11 Vitezslav Stejskal 2009-05-13 16:33:47 UTC
Ok, I'm not able to think of anything better that the original fix. IMO it's a correct fix and AFAICT the test that was
affected by it has been changed in the way that it's now passing even with the original fix. So, I pushed the original
fix. Just for the record the affected test is org.netbeans.test.xml.schema.AcceptanceTestCase.checkSourceCRC().

http://hg.netbeans.org/jet-main/rev/2b54697873bc
Comment 12 Quality Engineering 2009-05-14 07:54:52 UTC
Integrated into 'main-golden', will be available in build *200905140201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/2b54697873bc
User: Vita Stejskal <vstejskal@netbeans.org>
Log: #159502: another attempt to fix document's CharSequence; org.netbeans.test.xml.schema.AcceptanceTestCase.checkSourceCRC() now ignores EOL characters and so should not fail again due to this change
Comment 13 Alexander Simon 2009-05-14 12:11:11 UTC
Fix results in cnd unit test falure see IZ#165147
Comment 14 Erno Mononen 2009-05-22 15:34:14 UTC
*** Issue 164183 has been marked as a duplicate of this issue. ***
Comment 15 Nikita Krjukov 2009-11-24 04:38:32 UTC
I have strong objections about the way the issue has been fixed. 
It looks harmless because changes so small. But it can affect many places in sources. Try find usage of the AbstractCharSequence.length(). 

I've managed to resolve that the reason of 22 JUnit tests in XDM model are failed because of this fix. The problem happens because of the XMLLexer gets a length increased by 1 (see my attachment with the stack trace) and eventually the redundant /n appears in the model. 

I'm pretty sure that the bug #168113 caused by this fix. And I have seen the same behavior in different XML editors. 

Another problem is the change of the length meaning. So it can be considered as an API modification. I think it had to pass the API review.
Comment 16 Nikita Krjukov 2009-11-24 04:40:54 UTC
Created attachment 91591 [details]
Stack trace where the length works a wrong way
Comment 17 David Strupl 2009-11-25 02:40:35 UTC
Please reopen only in case you know how to fix the original problems that are described in the comment inside the method. If the correct solution is to change line highlighting API please reopen only after that API has been changed so we can use it.
Comment 18 Sergey Lunegov 2009-11-25 04:44:56 UTC
It's strange requirement. Issue still exists. And it should be open till will be fixed.
Comment 19 Miloslav Metelka 2009-11-25 07:21:09 UTC
The final committed fix (with confessed extra newline at doc.getLength()+1 in the CharSequence returned by DocumentUtilities.getText(doc)) was the best fix that we were able to find and we are not going to change it unless someone else will provide us with a better fix. Vita S. and I have discussed the pros and cons of this fix carefully since we were aware of most of the consequences and agreed on it.
 The original problem is of course the fact that Swing's AbstractDocument allows things like
doc.getText(0, doc.getLength() + 1);
doc.createPosition(doc.getLength() + 1);
lastParagraphElement.getEndOffset() == doc.getLength() + 1
 and we may only find a best response to this weirdness in our CharSequence view of the document.
If you need our help with fixing problems caused by this fix please file a separate issue. Thanks.