Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 197021 - NullPointerException at
NullPointerException at
Product: editor
Classification: Unclassified
Component: Formatting & Indentation
All All
: P3 (vote)
: 7.0.1
Assigned To: Dusan Balek
Depends on:
Blocks: 179047
  Show dependency treegraph
Reported: 2011-03-23 21:18 UTC by err
Modified: 2011-03-30 08:44 UTC (History)
0 users

See Also:
Issue Type: DEFECT

stacktrace (3.06 KB, text/plain)
2011-03-23 21:18 UTC, err
proposed fix (2.34 KB, patch)
2011-03-24 05:11 UTC, err
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description err 2011-03-23 21:18:06 UTC
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'

   at org.netbeans.modules.editor.indent.TaskHandler$MimeItem.runTask(
   at org.netbeans.modules.editor.indent.TaskHandler.runTasks(
   at org.netbeans.modules.editor.indent.IndentImpl.reindent(
   at org.netbeans.modules.editor.indent.api.Indent.reindent(
   at org.netbeans.modules.jvi.impl.NbBuffer.reindent(
Comment 1 err 2011-03-23 21:18:11 UTC
Created attachment 107229 [details]
Comment 2 err 2011-03-24 05:11:06 UTC
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.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.
Comment 3 err 2011-03-28 12:33:26 UTC
Adding "blocks" to jVi umbrella.

The supplied is pretty straightforward. Can it be evaluated?
Comment 4 Dusan Balek 2011-03-29 13:09:04 UTC
Fixed in jet-main. Thanks for the patch.
Comment 5 Quality Engineering 2011-03-30 08:44:19 UTC
Integrated into 'main-golden', will be available in build *201103300400* on (upload may still be in progress)
User: Dusan Balek <>
Log: Issue #197021: NullPointerException at - fixed.

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo