Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-885

NPE on invalid Java source code

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 9.0
    • ?
    • java - Editor
    • Linux, NetBeans 9.0 RC1 (and predecessors).

    Description

      I sometimes like to write some code using hints for completion like this:

      package test;
      import java.io.File;

      public class Test {

          public void test()

      {         File[] files = new File[0];         for (file : files)     }

      }

      This results in NullPointerExceptions on editing, formatting, or even just re-opening the file.

      Additionally to bug resolution I'd like to know how to write tests for such situations, so I'd be glad if You could append a diff for the changes.

      Relevant part of stacktrace:

      java.lang.NullPointerException
      SEVERE [org.openide.util.Exceptions]
      java.lang.NullPointerException
          at jdk.compiler/com.sun.tools.javac.tree.Pretty.visitVarDef(Pretty.java:636)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:950)
          at jdk.compiler/com.sun.tools.javac.tree.Pretty.printExpr(Pretty.java:194)
          at jdk.compiler/com.sun.tools.javac.tree.Pretty.printExpr(Pretty.java:209)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree.toString(JCTree.java:429)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl.createBreadcrumbs(BreadCrumbsNodeImpl.java:260)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.scan(BreadCrumbsNodeImpl.java:535)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.scan(BreadCrumbsNodeImpl.java:514)
          at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
          at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
          at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:248)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)
          at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:86)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.scan(BreadCrumbsNodeImpl.java:539)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.visitMethod(BreadCrumbsNodeImpl.java:544)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.visitMethod(BreadCrumbsNodeImpl.java:514)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3.run(BreadCrumbsNodeImpl.java:514)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3.run(BreadCrumbsNodeImpl.java:503)
          at org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:501)
          at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:586)
          at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:130)
          at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:114)
          at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:181)
          at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:178)
          at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:153)
          at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:335)
          at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:118)
          at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:67)
          at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:178)
          at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:81)
          at org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:451)
          at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:422)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl.getChildren(BreadCrumbsNodeImpl.java:503)
          at org.netbeans.modules.java.navigation.BreadCrumbsScanningTask.rootAndSelection(BreadCrumbsScanningTask.java:114)
          at org.netbeans.modules.java.navigation.BreadCrumbsScanningTask.run(BreadCrumbsScanningTask.java:82)
          at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:561)
      [catch] at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:786)
          at org.openide.util.lookup.Lookups.executeWith(Lookups.java:279)
          at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702)
          at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663)
          at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
          at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
          at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
          at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
          at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
          at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
      SEVERE [org.openide.util.Exceptions]
      java.lang.NullPointerException
      SEVERE [null]: Last record repeated again.
      SEVERE [org.openide.util.Exceptions]
      java.lang.NullPointerException
          at jdk.compiler/com.sun.tools.javac.tree.Pretty.visitVarDef(Pretty.java:636)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:950)
          at jdk.compiler/com.sun.tools.javac.tree.Pretty.printExpr(Pretty.java:194)
          at jdk.compiler/com.sun.tools.javac.tree.Pretty.printExpr(Pretty.java:209)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree.toString(JCTree.java:429)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl.createBreadcrumbs(BreadCrumbsNodeImpl.java:260)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.scan(BreadCrumbsNodeImpl.java:535)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.scan(BreadCrumbsNodeImpl.java:514)
          at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
          at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
          at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:248)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1026)
          at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:86)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.scan(BreadCrumbsNodeImpl.java:539)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.visitMethod(BreadCrumbsNodeImpl.java:544)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3$1.visitMethod(BreadCrumbsNodeImpl.java:514)
          at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3.run(BreadCrumbsNodeImpl.java:514)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl$3.run(BreadCrumbsNodeImpl.java:503)
          at org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:501)
          at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:586)
          at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:130)
          at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:114)
          at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:181)
          at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:178)
          at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:153)
          at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:335)
          at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:118)
          at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:67)
          at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:178)
          at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:81)
          at org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:451)
          at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:422)
          at org.netbeans.modules.java.navigation.BreadCrumbsNodeImpl.getChildren(BreadCrumbsNodeImpl.java:503)
          at org.netbeans.modules.java.navigation.BreadCrumbsScanningTask.rootAndSelection(BreadCrumbsScanningTask.java:114)
          at org.netbeans.modules.java.navigation.BreadCrumbsScanningTask.run(BreadCrumbsScanningTask.java:82)
          at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:561)
      [catch] at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:786)
          at org.openide.util.lookup.Lookups.executeWith(Lookups.java:279)
          at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702)
          at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663)
          at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
          at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
          at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
          at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
          at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
          at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
      SEVERE [org.openide.util.Exceptions]
      java.lang.NullPointerException
      SEVERE [null]: Last record repeated again.
      SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor org.netbeans.modules.java.editor.imports.ClipboardHandler$7
      java.lang.NullPointerException
      Caused: org.openide.util.RequestProcessor$FastItem: task failed due to
      WARNING [org.netbeans.modules.versioning.util.Utils]: associateEncoding() no file object available for /tmp/vcs-1527659156240/vcs-1527660513965/testGenerate123456789.pass
      INFO [org.netbeans.modules.parsing.impl.TaskProcessor]: Task: CancelableTaskWrapper[task: org.netbeans.modules.java.hints.spiimpl.hints.HintsTask@5cf81cb0, phase: RESOLVED, priority: 500] : class org.netbeans.modules.java.source.JavaSourceAccessor$CancelableTaskWrapper ignored cancel for 99 ms.
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$1 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$2 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$3 ]
      WARNING [org.openide.util.WeakListenerImpl]: Can't remove java.beans.PropertyChangeListener using method org.netbeans.modules.editor.NbEditorDocument.removePropertyChangeListener from org.netbeans.modules.editor.NbEditorDocument@7b5f8694, mimeType='text/plain', kitClass=null, length=343, version=1, file=org.openide.loaders.DefaultDataObject@3c3c4426[/home/peter/incubator-netbeans/java.editor/test/unit/data/goldenfiles/org/netbeans/modules/java/editor/codegen/DelegateMethodGeneratorTest/1.8/testGenerate133625d.pass@583f1c3d:20e7cfa5]
      INFO [org.netbeans.modules.parsing.impl.TaskProcessor]: Task: CancelableTaskWrapper[task: org.netbeans.modules.java.hints.spiimpl.hints.HintsTask@319ddcff, phase: RESOLVED, priority: 500] : class org.netbeans.modules.java.source.JavaSourceAccessor$CancelableTaskWrapper ignored cancel for 123 ms.
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$1 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$2 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$3 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$1 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$2 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$3 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$1 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$2 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$3 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$1 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$2 ]
      INFO [org.netbeans.api.java.source.ElementHandle]: Resolved type is null for kind = CLASS
      INFO [org.netbeans.api.java.source.ElementHandle]: Cannot resolve: ElementHandle[kind=CLASS; sigs=org.netbeans.modules.java.editor.codegen.DelegateMethodGeneratorTest$3 ]
      SEVERE [org.openide.util.Exceptions]
      java.lang.NullPointerException
      SEVERE [null]: Last record repeated again.
      WARNING [org.netbeans.modules.java.source.tasklist.IncorrectErrorBadges]: Incorrect error badges detected, file=/home/peter/NetBeansProjects/SampleExporter/src/main/java/org/example/ds/Test.java.
      WARNING [org.netbeans.modules.java.source.tasklist.IncorrectErrorBadges]: Going to recompute root=/home/peter/NetBeansProjects/SampleExporter/src/main/java, files in error=[].
      WARNING [org.netbeans.modules.java.source.indexing.JavaIndex]: VanillaCompileWorker caused an exception
      Root: /home/peter/NetBeansProjects/SampleExporter/src/main/java

       

      As You can see, not every NPE presents a stacktrace.

      Attachments

        Activity

          People

            jlahoda Jan Lahoda
            epdv Peter Nabbefeld
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: