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.
Build: NetBeans IDE 7.0 Beta 2 (Build 201102140001) VM: Java HotSpot(TM) Client VM, 19.0-b09, Java(TM) SE Runtime Environment, 1.6.0_23-b05 OS: Windows XP User Comments: err: Reindent where the last line of the region is only a '\n' Stacktrace: java.lang.NullPointerException at org.netbeans.modules.java.source.save.Reindenter.reindent(Reindenter.java:169) at org.netbeans.modules.editor.indent.TaskHandler$MimeItem.runTask(TaskHandler.java:546) at org.netbeans.modules.editor.indent.TaskHandler.runTasks(TaskHandler.java:316) at org.netbeans.modules.editor.indent.IndentImpl.reindent(IndentImpl.java:260) at org.netbeans.modules.editor.indent.api.Indent.reindent(Indent.java:171) at org.netbeans.modules.jvi.impl.NbBuffer.reindent(NbBuffer.java:214)
Created attachment 107229 [details] stacktrace
Created attachment 107234 [details] proposed fix The NPE occurs because at Reindenter:164 Integer newIndent = newIndents.get(startOffset); there is no map entry for startOffset of the last line, so newIndent is set to null. This occurs when the last line of the range is a single '\n'. In that case the while loop at Reindenter:139 while (endOffset < region.getEndOffset()) { never executes the loop body for the last line of the range and so the map entry is never created. For example, my test case has three lines with startOffsets list of {53,70,76} and region.getEndOffset() is 76. The "while(76 < 76)" fails. Changing the condition to "<=" results in an infinite loop. The attached patch insures that the body is executed for each line; and simplifies the logic at the expense of adding an it.next;it.previous for each loop. BTW, the bug with the while condition arises because IndentImpl:288 doc.createPosition(lineElem.getEndOffset() - 1)); subtracts one from the offset. Also see IndentImpl:278.
Adding "blocks" to jVi umbrella. The supplied is pretty straightforward. Can it be evaluated?
Fixed in jet-main. Thanks for the patch. http://hg.netbeans.org/jet-main/rev/b005ac22e5dd
Integrated into 'main-golden', will be available in build *201103300400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/b005ac22e5dd User: Dusan Balek <dbalek@netbeans.org> Log: Issue #197021: NullPointerException at org.netbeans.modules.java.source.save.Reindenter.reindent - fixed.