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 236147 - IndexOutOfBoundsException: Invalid line index=352 >= lineCount=352
Summary: IndexOutOfBoundsException: Invalid line index=352 >= lineCount=352
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Painting & Printing (show other bugs)
Version: 7.4
Hardware: All All
: P1 normal with 1 vote (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
: 237892 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-09-19 13:48 UTC by janario
Modified: 2013-11-15 07:58 UTC (History)
23 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 204003


Attachments
stacktrace (1.34 KB, text/plain)
2013-09-19 13:48 UTC, janario
Details
stacktrace (1.34 KB, text/plain)
2013-09-27 13:21 UTC, Alexander Simon
Details
stacktrace (1.34 KB, text/plain)
2013-10-02 15:15 UTC, ehsavoie
Details
stacktrace (1.34 KB, text/plain)
2013-10-23 07:50 UTC, akobberup
Details
stacktrace (2.83 KB, text/plain)
2013-10-23 12:08 UTC, unai
Details
stacktrace (2.84 KB, text/plain)
2013-10-23 12:11 UTC, unai
Details
stacktrace (2.83 KB, text/plain)
2013-10-23 12:14 UTC, unai
Details
stacktrace (1.34 KB, text/plain)
2013-10-31 15:55 UTC, akobberup
Details
stacktrace (1.34 KB, text/plain)
2013-11-01 10:32 UTC, csjunker
Details
stacktrace (2.02 KB, text/plain)
2013-11-04 15:50 UTC, Jesse Glick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description janario 2013-09-19 13:48:23 UTC
This issue was reported manually by mentlicher.
It already has 18 duplicates 


Build: NetBeans IDE Dev (Build 20130918-f923276dee99)
VM: Java HotSpot(TM) 64-Bit Server VM, 23.25-b01, Java(TM) SE Runtime Environment, 1.7.0_25-b15
OS: Linux

User Comments:
janario: .

jenjen: Click File -> Open

Why can't a text editor open files?  What program manager idiot decided that was not a needed feature?

GUEST: debugging maven web project

rodrigorsantos: <Please provide a description of the problem or the steps to reproduce>

janario: .

GUEST: Opening a WebService file

rodrigorsantos: <Please provide a description of the problem or the steps to reproduce>

GUEST: Opening netbeans after reinstallation to the nightly build 201309050001. Opend file is web.xml (active), persistence.xml, properties-files, pom.xml file and java. multiple maven and an ant project is open.

jenjen: sigh

GUEST: starting an maven tomcat project in debug mode

janario: attaching debug

janario: After deploy application

rodrigorsantos: <Please provide a description of the problem or the steps to reproduce>

rodrigorsantos: <Please provide a description of the problem or the steps to reproduce>

jenjen: Trying to open a file

janario: .

GUEST: Attempting to debug web services client

jbsabmello: x




Stacktrace: 
java.lang.IndexOutOfBoundsException: Invalid line index=352 >= lineCount=352
   at org.netbeans.modules.editor.lib2.document.LineRootElement.getElement(LineRootElement.java:84)
   at org.openide.text.NbDocument$DocumentRenderer.run(NbDocument.java:923)
   at org.netbeans.editor.BaseDocument.render(BaseDocument.java:1391)
   at org.openide.text.NbDocument$DocumentRenderer.renderToInt(NbDocument.java:898)
   at org.openide.text.NbDocument.findLineOffset(NbDocument.java:201)
   at org.openide.text.PositionRef$Manager$DocumentRenderer.run(PositionRef.java:1033)
Comment 1 janario 2013-09-19 13:48:27 UTC
Created attachment 140252 [details]
stacktrace
Comment 2 Alexander Simon 2013-09-27 13:21:44 UTC
Created attachment 140554 [details]
stacktrace

start IDE from IDE
Comment 3 ehsavoie 2013-10-02 15:15:53 UTC
Created attachment 140740 [details]
stacktrace

debugging
Comment 4 djdevin 2013-10-16 16:51:53 UTC
My file had 197 lines (at one point) but netbeans seemed to have it down as 194 lines. It wouldn't open in the IDE.

When I manually added more lines to the file the file opened as normal.

It might also have to do with adding a breakpoint on a line that no longer exists as I was debugging the bottom of that file.
Comment 5 djdevin 2013-10-16 17:26:38 UTC
(In reply to djdevin from comment #4)
> My file had 197 lines (at one point) but netbeans seemed to have it down as
> 194 lines. It wouldn't open in the IDE.
> 
> When I manually added more lines to the file the file opened as normal.
> 
> It might also have to do with adding a breakpoint on a line that no longer
> exists as I was debugging the bottom of that file.




Clarification:

Netbeans was trying to do something with line 197
On disk, custom.module had 194 lines

At some point in the past, it did have 197 lines and there was a debug breakpoint on one of those.
Comment 6 akobberup 2013-10-23 07:50:53 UTC
Created attachment 141449 [details]
stacktrace

starting a debug session..
Comment 7 unai 2013-10-23 12:08:54 UTC
Created attachment 141470 [details]
stacktrace

Installed EasyPMD, first time scan
Comment 8 unai 2013-10-23 12:11:54 UTC
Created attachment 141471 [details]
stacktrace

Refreshing EasyPMD actions
Comment 9 unai 2013-10-23 12:14:54 UTC
Created attachment 141472 [details]
stacktrace

EasyPMD scanning
Comment 10 akobberup 2013-10-31 15:55:46 UTC
Created attachment 141754 [details]
stacktrace

trying to debug file
Comment 11 csjunker 2013-11-01 10:32:00 UTC
Created attachment 141768 [details]
stacktrace

debug main project.
Comment 12 Jesse Glick 2013-11-04 15:50:25 UTC
Created attachment 141839 [details]
stacktrace

Just browsing source code.
Comment 13 Miloslav Metelka 2013-11-13 12:52:19 UTC
I was able to reproduce the problem:
1) Create .java source with a method that contains e.g. 20 empty lines followed by a code on which a breakpoint can be placed e.g. System.err.println().
2) Put a breakpoint on the code.
3) Open Breakpoints window a notice a line where the breakpoint is placed.
4) Shutdown IDE
5) Open the .java source in external editor and delete the empty lines.
6) Open IDE - the Breakponints window should still show the original line number.
7) Doubleclick the breakpoint and the IOOBE should be thrown.

This is an effect of issue 228855. PositionRef.Manager.toMemory() is no longer called upon document opening. It's only called upon CloneableEditor opening which is too late for this specific case. It contains a fallback for the case when the line number is outside of document:

                     case LINE_KIND_TO_MEMORY: {
                         // try to find the right position
                         try {
                             retObject = NbDocument.createPosition(
                                     mgr.getDoc(),
NbDocument.findLineOffset(mgr.getDoc(), argLine) + argColumn,
                                     argInsertAfter ?
Position.Bias.Backward : Position.Bias.Forward
                                 );
                         } catch (BadLocationException e) {
                             retObject = mgr.getDoc().getEndPosition();
                         } catch (IndexOutOfBoundsException e) {
                             retObject = mgr.getDoc().getEndPosition();
                         }

So the solution should probably be to add a similar fallback to PositionRef.getOffset().

http://hg.netbeans.org/jet-main/rev/a2706cef352f
Comment 14 Miloslav Metelka 2013-11-13 12:55:40 UTC
*** Bug 237892 has been marked as a duplicate of this bug. ***
Comment 15 Miloslav Metelka 2013-11-13 12:56:20 UTC
Marking as P1 since one of the dup issue was also P1.
Comment 16 Quality Engineering 2013-11-14 03:19:26 UTC
Integrated into 'main-silver', will be available in build *201311140002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/a2706cef352f
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #236147 - IndexOutOfBoundsException: Invalid line index=352 >= lineCount=352.
Comment 17 Miloslav Metelka 2013-11-14 13:23:04 UTC
In release74:
a2706cef352f transplanted to b15df9ad855c
Comment 18 squib 2013-11-14 15:57:12 UTC
Is it possible to provide EXCEPTIONS_REPORT 74patch1-fixed as single jar to patch the current installed netbeans?
Comment 19 Jiri Prox 2013-11-14 16:01:22 UTC
The IDE will update automatically once the patch will be released.
Comment 20 Quality Engineering 2013-11-15 01:36:14 UTC
Integrated into 'releases/release74', will be available in build *201311142201* or newer. Wait for official and publicly available build.

Changeset: http://hg.netbeans.org/releases/rev/b15df9ad855c
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #236147 - IndexOutOfBoundsException: Invalid line index=352 >= lineCount=352.
(transplanted from a2706cef352f3a3cda4d6568545cf93eef21730c)