Duplicate inner classes causes exception and sometimes hangs
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 12.6
### What happened
Creating two same-named inner classes in a class causes an exception.
I realize that it is dumb to create two classes with the same name. It was actually caused by Netbeans. I updated a class and told the IDE to generate tests for the new methods. Since the class is abstract, it needs an Impl class for the test. The test already had one. Netbeans created a second one.
At work, if I try to save the file, it hang the IDE. I have to kill -9.
At home, it shows an error with this exception:
```
Caused: java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.hasTag(com.sun.tools.javac.code.TypeTag)" because the return value of "com.sun.tools.javac.code.Type.getEnclosingType()" is null
at jdk.compiler/com.sun.tools.javac.code.Symbol.hasOuterInstance(Symbol.java:504)
at org.netbeans.modules.java.source.PostFlowAnalysis.visitClassDef(PostFlowAnalysis.java:114)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at org.netbeans.modules.java.source.PostFlowAnalysis.scan(PostFlowAnalysis.java:104)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitClassDef(TreeScanner.java:119)
at org.netbeans.modules.java.source.PostFlowAnalysis.visitClassDef(PostFlowAnalysis.java:116)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at org.netbeans.modules.java.source.PostFlowAnalysis.scan(PostFlowAnalysis.java:104)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitTopLevel(TreeScanner.java:66)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:544)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at org.netbeans.modules.java.source.PostFlowAnalysis.scan(PostFlowAnalysis.java:104)
at org.netbeans.modules.java.source.PostFlowAnalysis.analyze(PostFlowAnalysis.java:90)
at org.netbeans.modules.java.source.parsing.JavacParser.moveToPhase(JavacParser.java:729)
at org.netbeans.modules.java.source.parsing.JavacParser.getResult(JavacParser.java:515)
at org.netbeans.modules.java.source.parsing.JavacParser.getResult(JavacParser.java:139)
at org.netbeans.modules.parsing.impl.TaskProcessor.callGetResult(TaskProcessor.java:608)
at org.netbeans.modules.parsing.impl.SourceCache.getResult(SourceCache.java:239)
at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:775)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:279)
at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702)
[catch] at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
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)
```
### How to reproduce
1. Create a class
2. Create an inner class
3. Make another copy of that inner class below the first one in the same class
```java
public class Outer {
public class Inner {
}
public class Inner {
}
}
```
### Did this work correctly in an earlier version?
No
### Operating System
Fedora 35 Linux
### JDK
OpenJDK 17.0.2
### Apache NetBeans packaging
Apache NetBeans provided installer
### Anything else
_No response_
### Are you willing to submit a pull request?
_No response_
### Code of Conduct
Yes
Contributor guide
Research direction
Reproduce the issue with the provided Outer and duplicate Inner classes, then start at org.netbeans.modules.java.source.PostFlowAnalysis.visitClassDef in PostFlowAnalysis.java and follow the stack trace into JavacParser. Done means the duplicate-class source no longer causes the reported NullPointerException or hangs the IDE.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100