-
Notifications
You must be signed in to change notification settings - Fork 917
Description
Apache NetBeans version
Apache NetBeans 28
What happened
The following ClassCastException repeatedly occurred during code completion in a file with syntax errors, intermittently breaking code completion:
java.lang.ClassCastException: class com.sun.tools.javac.code.Symbol$ClassSymbol cannot be cast to class javax.lang.model.element.ExecutableElement (com.sun.tools.javac.code.Symbol$ClassSymbol and javax.lang.model.element.ExecutableElement are in unnamed module of loader org.netbeans.StandardModule$OneModuleClassLoader @1426fa1e)
at org.netbeans.modules.java.completion.JavaCompletionTask.getSmartTypesImpl(JavaCompletionTask.java:5999)
at org.netbeans.modules.java.completion.JavaCompletionTask.getSmartTypes(JavaCompletionTask.java:5728)
at org.netbeans.modules.java.completion.JavaCompletionTask.addMembers(JavaCompletionTask.java:4083)
at org.netbeans.modules.java.completion.JavaCompletionTask.insideMemberSelect(JavaCompletionTask.java:1909)
at org.netbeans.modules.java.completion.JavaCompletionTask.resolve(JavaCompletionTask.java:380)
at org.netbeans.modules.java.completion.BaseTask.run(BaseTask.java:96)
at org.netbeans.modules.java.completion.JavaCompletionTask.run(JavaCompletionTask.java:67)
at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:586)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:197)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:180)
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:83)
[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:1403)
at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018)
Language / Project Type / NetBeans Component
No response
How to reproduce
I can't provide the code where this happened (large file in a large proprietary code base), but the situation was that additional parameters were added to an existing method (temporarily breaking call sites for that method in the same source file), and the ClassCastException occurred while performing code completion within the argument list of one of the callers (while trying to add the new arguments for the new method parameters).
Similar to:
void foo()
{
bar(arg1, arg2, newArg2.<code completion here> );
}
void bar( A arg1, B arg2, C newArg3, D newArg4, E newArg5)
{
... also some syntax errors here ...
}Closing the source file and reopening it, and first filling null for the multiple missing method arguments before re-attempting code completion, made code completion working again.
Did this work correctly in an earlier version?
No / Don't know
Operating System
Windows
JDK
JDK 21
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
While I can't provide a reproducible example, maybe the mismatched types causing the ClassCastException and the stacktrace are sufficient to track down where the bug is.
Are you willing to submit a pull request?
No