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

NPE in code completion when in incorrect cast syntax

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 11.3
    • None
    • java - Source
    • None
    • NetBeans 11.3 on Windows (OS shouldn't matter)

    Description

      In the following class, put the cursor after "dat" and invoke code completion (Ctrl+Space). This situation often happens from muscle memory while typing a cast. A NPE will result:

      public class TestFoo {
        private String someMethod(Object someArg) {
          if (someArg instanceof String)
            return (String dat); // To see parser error, open code completion with cursor after "dat
          return null;
        }
      }
      

      The desired behavior is to just ignore the incorrect syntax, and perform no completion. Instead, the following exception is shown:

      java.lang.NullPointerException
      	at org.netbeans.modules.java.completion.BaseTask.getEnvImpl(BaseTask.java:389)
      	at org.netbeans.modules.java.completion.BaseTask.getCompletionEnvironment(BaseTask.java:270)
      	at org.netbeans.modules.java.completion.JavaCompletionTask.resolve(JavaCompletionTask.java:297)
      	at org.netbeans.modules.java.completion.BaseTask.run(BaseTask.java:94)
      	at org.netbeans.modules.java.completion.JavaCompletionTask.run(JavaCompletionTask.java:60)
      	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)
      Caused: org.netbeans.modules.parsing.spi.ParseException
      	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:186)
      	at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:81)
      [catch] at org.netbeans.modules.editor.java.JavaCompletionProvider$JavaCompletionQuery.query(JavaCompletionProvider.java:193)
      	at org.netbeans.spi.editor.completion.support.AsyncCompletionTask.run(AsyncCompletionTask.java:198)
      	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)
      
      

      Reporting this bug in case a pattern emerges where various kinds of errors like this pop up instead of being silently ignored.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ebakke Eirik Bakke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 10m
                10m