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

IOOBE when editing Java file with temporarily missing comma in method parameter list

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 11.3
    • None
    • java - Editor
    • NetBeans 11.3 with nbjavac plugin installed

    Description

      If, during editing, a comma is momentarily deleted in the parameter list of a method (in certain cases), an error dialog shows up showing an IndexOutOfBoundsException in SemanticHighlighterBase$DetectorVisitor.addParameterInlineHint. A minimized example exhibiting this behavior is as follows:

      public class BugSemanticHighlighterBase {
        private Object testMethod(final String arg1 final String arg2) {
          return new String("");
        }
      }
      

      This example causes the IDE to throw the following exception:

      java.lang.IndexOutOfBoundsException: -1
      	at com.sun.tools.javac.util.List.get(List.java:482)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.addParameterInlineHint(SemanticHighlighterBase.java:1241)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitLiteral(SemanticHighlighterBase.java:1180)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitLiteral(SemanticHighlighterBase.java:424)
      	at com.sun.tools.javac.tree.JCTree$JCLiteral.accept(JCTree.java:2410)
      	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:69)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:1199)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:424)
      	at com.sun.source.util.TreeScanner.scan(TreeScanner.java:106)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:78)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitNewClass(SemanticHighlighterBase.java:1085)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitNewClass(SemanticHighlighterBase.java:424)
      	at com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1820)
      	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:69)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:1199)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:424)
      	at com.sun.source.util.TreeScanner.visitReturn(TreeScanner.java:495)
      	at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1663)
      	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:69)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:1199)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:424)
      	at com.sun.source.util.TreeScanner.scan(TreeScanner.java:106)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:78)
      	at com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:249)
      	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1048)
      	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:69)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:1199)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:424)
      	at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:91)
      	at com.sun.source.util.TreeScanner.scan(TreeScanner.java:106)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:78)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitClass(SemanticHighlighterBase.java:1124)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitClass(SemanticHighlighterBase.java:424)
      	at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:822)
      	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:69)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:1199)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:424)
      	at com.sun.source.util.TreeScanner.scan(TreeScanner.java:106)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:78)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitCompilationUnit(SemanticHighlighterBase.java:797)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.visitCompilationUnit(SemanticHighlighterBase.java:424)
      	at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:603)
      	at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
      	at org.netbeans.api.java.source.support.CancellableTreePathScanner.scan(CancellableTreePathScanner.java:69)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase$DetectorVisitor.scan(SemanticHighlighterBase.java:1199)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase.process(SemanticHighlighterBase.java:251)
      	at org.netbeans.modules.java.editor.semantic.SemanticHighlighter.process(SemanticHighlighter.java:56)
      	at org.netbeans.modules.java.editor.base.semantic.SemanticHighlighterBase.run(SemanticHighlighterBase.java:118)
      	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:515)
      	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)
      

      A similar (in the few first 18 calls) stack trace is caused by the following code which is actually syntactically correct (but which has a type error), every time an edit is made (2020-05-02: PR submitter confirms that this case is handled by the merged PR as well.):

      public class FooTest {
        public void someMethod() {
          List<String> someFoo = listOf(transform(null, s -> new Integer(5)));
        }
      
        public static <E> List<E> listOf(E element) {
          throw new UnsupportedOperationException();
        }
      
        public static <F, T> Iterable<T> transform(
            Iterable<F> fromIterable, Function<? super F, ? extends T> function)
        {
          throw new UnsupportedOperationException();
        }
      }
      

      Attachments

        Issue Links

          Activity

            People

              graben Benjamin Graf
              ebakke Eirik Bakke
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

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