[
https://issues.apache.org/jira/browse/NETBEANS-2221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16838628#comment-16838628
]
Mark Herkrath edited comment on NETBEANS-2221 at 5/17/19 8:34 AM:
------------------------------------------------------------------
I am running into the same issue all the time and have done some analysis:
Code of {{org.netbeans.modules.java.source.builder.TreeFactory}}, where the
ClassCastException happens:
{code:java}
public ExpressionTree Type(TypeMirror type) {
Type t = (Type) type;
JCExpression tp;
switch (type.getKind()) {
...
case ERROR:
tp = make.at(NOPOS).Ident(((ErrorType) type).tsym.name);
break;
default:
return make.at(NOPOS).Type((Type)type);
}
return tp.setType(t);
} {code}
The getKind() implementation of ClassType used to always return DECLARED.
However since Java 11, the getKind() implementation of ClassType has been
changed:
{code:java}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
tsym.apiComplete();
return tsym.kind == TYP ? TypeKind.DECLARED : TypeKind.ERROR;
} {code}
See [http://hg.openjdk.java.net/jdk/jdk/rev/cc2673fa8c20] due to
[https://bugs.openjdk.java.net/browse/JDK-8187950]
The same change was done as part of nb-java here:
[https://hg.netbeans.org/main/nb-java-x/diff/cc2673fa8c20/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java],
as part of [https://hg.netbeans.org/main/nb-java-x/rev/cc2673fa8c20].
As a result, the cast to ErrorType for getKind() == ERROR isn't always valid
anymore, and may throw ClassCastExceptions like this one.
Could it be possible that the nb-java change is part of the nb-java used for
NetBeans 11, but not yet for the version used for NetBeans 10? It's not clear
to me which tags are used.
was (Author: herkrath):
I am running into the same issue all the time and have done some analysis:
Code of {{org.netbeans.modules.java.source.builder.TreeFactory}}, where the
ClassCastException happens:
{code:java}
public ExpressionTree Type(TypeMirror type) {
Type t = (Type) type;
JCExpression tp;
switch (type.getKind()) {
...
case ERROR:
tp = make.at(NOPOS).Ident(((ErrorType) type).tsym.name);
break;
default:
return make.at(NOPOS).Type((Type)type);
}
return tp.setType(t);
} {code}
The getKind() implementation of ClassType used to always return DECLARED.
However since Java 11, the getKind() implementation of ClassType has been
changed:
{code:java}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
tsym.apiComplete();
return tsym.kind == TYP ? TypeKind.DECLARED : TypeKind.ERROR;
} {code}
See [http://hg.openjdk.java.net/jdk/jdk/rev/cc2673fa8c20] due to
[https://bugs.openjdk.java.net/browse/JDK-8187950]
As a result, the cast to ErrorType for getKind() == ERROR isn't always valid
anymore. The strange thing is that I get the same error with Java 8u212 by
Oracle (i.e. NB is running with that version and the Java version of my project
is also set accordingly). Maybe it was back-ported but it's not clear to me if
their com.sun.tools sources are publicly accessible somewhere. I don't see that
change in the Java 8 release notes. Alternatively, NetBeans is using Java 11
for de-compilation for whatever reason. I have at least added it as a Java
Platform.
> ClassCastException when try to open class from not opened module
> ----------------------------------------------------------------
>
> Key: NETBEANS-2221
> URL: https://issues.apache.org/jira/browse/NETBEANS-2221
> Project: NetBeans
> Issue Type: Bug
> Affects Versions: 11.0
> Reporter: Tomas Huryn
> Priority: Major
>
> When I try to open a class from project which has not been opened before I
> get the exception:
> WARNING [org.openide.filesystems.Ordering]: Not all children in / marked with
> the position attribute:
> [org-netbeans-modules-lsp-client-bindings-HyperlinkProviderImpl.instance],
> but some are: [HyperlinkProviderImpl.instance,
> org-netbeans-modules-editor-url-HyperlinkImpl.instance]
> WARNING [org.netbeans.modules.parsing.impl.TaskProcessor]:
> ParserManager.parse called in AWT event thread by:
> org.netbeans.modules.java.classfile.CodeGenerator.generateCode(CodeGenerator.java:152)
> Even though the source level of is set to: 11, java.util.zip.CRC32C cannot
> be found on the system module path:
> Changing source level to 1.8
> SEVERE [global]
> java.lang.ClassCastException: class com.sun.tools.javac.code.Type$ClassType
> cannot be cast to class com.sun.tools.javac.code.Type$ErrorType
> (com.sun.tools.javac.code.Type$ClassType and
> com.sun.tools.javac.code.Type$ErrorType are in unnamed module of loader
> org.netbeans.StandardModule$OneModuleClassLoader @4f09236a)
> at
> org.netbeans.modules.java.source.builder.TreeFactory.Type(TreeFactory.java:863)
> at org.netbeans.api.java.source.TreeMaker.Type(TreeMaker.java:1119)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.computeAnnotationTree(CodeGenerator.java:449)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.computeMods(CodeGenerator.java:411)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.visitType(CodeGenerator.java:373)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.visitType(CodeGenerator.java:285)
> at com.sun.tools.javac.code.Symbol$ClassSymbol.accept(Symbol.java:1473)
> at
> javax.lang.model.util.AbstractElementVisitor6.visit(AbstractElementVisitor6.java:106)
> at
> org.netbeans.modules.java.classfile.CodeGenerator.generateCode(CodeGenerator.java:275)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$1.run(CodeGenerator.java:232)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$1.run(CodeGenerator.java:152)
> at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:672)
> at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:662)
> 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.api.java.source.JavaSource.runModificationTask(JavaSource.java:683)
> at
> org.netbeans.modules.java.classfile.CodeGenerator.generateCode(CodeGenerator.java:152)
> at
> org.netbeans.modules.java.classfile.BinaryElementOpenImpl.open(BinaryElementOpenImpl.java:44)
> at
> org.netbeans.api.java.source.ui.ElementOpen.binaryOpen(ElementOpen.java:118)
> at org.netbeans.api.java.source.ui.ElementOpen.open(ElementOpen.java:99)
> at
> org.netbeans.modules.java.source.ui.JavaTypeDescription.open(JavaTypeDescription.java:121)
> at
> org.netbeans.modules.jumpto.type.GoToTypeAction.actionPerformed(GoToTypeAction.java:153)
> at
> org.openide.windows.TopComponent.processKeyBinding(TopComponent.java:1151)
> at
> java.desktop/javax.swing.JComponent.processKeyBindings(JComponent.java:2962)
> at
> java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2862)
> at java.desktop/java.awt.Component.processEvent(Component.java:6409)
> at java.desktop/java.awt.Container.processEvent(Container.java:2263)
> at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5008)
> at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
> at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
> at
> java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1950)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:871)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1140)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1010)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:836)
> at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4889)
> at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
> at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
> at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
> at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
> at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
> at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
> at java.base/java.security.AccessController.doPrivileged(Native Method)
> at
> java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
> at
> java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
> at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
> at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
> at java.base/java.security.AccessController.doPrivileged(Native Method)
> at
> java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
> at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
> at
> org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:136)
> [catch] at
> java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
> at
> java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
> Even though the source level of is set to: 11, java.util.zip.CRC32C cannot
> be found on the system module path:
> Changing source level to 1.8
> SEVERE [global]
> java.lang.ClassCastException: class com.sun.tools.javac.code.Type$ClassType
> cannot be cast to class com.sun.tools.javac.code.Type$ErrorType
> (com.sun.tools.javac.code.Type$ClassType and
> com.sun.tools.javac.code.Type$ErrorType are in unnamed module of loader
> org.netbeans.StandardModule$OneModuleClassLoader @4f09236a)
> at
> org.netbeans.modules.java.source.builder.TreeFactory.Type(TreeFactory.java:863)
> at org.netbeans.api.java.source.TreeMaker.Type(TreeMaker.java:1119)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.computeAnnotationTree(CodeGenerator.java:449)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.computeMods(CodeGenerator.java:411)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.visitType(CodeGenerator.java:373)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$TreeBuilder.visitType(CodeGenerator.java:285)
> at com.sun.tools.javac.code.Symbol$ClassSymbol.accept(Symbol.java:1473)
> at
> javax.lang.model.util.AbstractElementVisitor6.visit(AbstractElementVisitor6.java:106)
> at
> org.netbeans.modules.java.classfile.CodeGenerator.generateCode(CodeGenerator.java:275)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$1.run(CodeGenerator.java:232)
> at
> org.netbeans.modules.java.classfile.CodeGenerator$1.run(CodeGenerator.java:152)
> at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:672)
> at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:662)
> 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.api.java.source.JavaSource.runModificationTask(JavaSource.java:683)
> at
> org.netbeans.modules.java.classfile.CodeGenerator.generateCode(CodeGenerator.java:152)
> at
> org.netbeans.modules.java.classfile.BinaryElementOpenImpl.open(BinaryElementOpenImpl.java:44)
> at
> org.netbeans.api.java.source.ui.ElementOpen.binaryOpen(ElementOpen.java:118)
> at org.netbeans.api.java.source.ui.ElementOpen.open(ElementOpen.java:99)
> at
> org.netbeans.modules.java.source.ui.JavaTypeDescription.open(JavaTypeDescription.java:121)
> at
> org.netbeans.modules.jumpto.type.GoToTypeAction.actionPerformed(GoToTypeAction.java:153)
> at
> org.openide.windows.TopComponent.processKeyBinding(TopComponent.java:1151)
> at
> java.desktop/javax.swing.JComponent.processKeyBindings(JComponent.java:2962)
> at
> java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2862)
> at java.desktop/java.awt.Component.processEvent(Component.java:6409)
> at java.desktop/java.awt.Container.processEvent(Container.java:2263)
> at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5008)
> at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
> at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
> at
> java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1950)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:871)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1140)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1010)
> at
> java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:836)
> at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4889)
> at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
> at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
> at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
> at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
> at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
> at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
> at java.base/java.security.AccessController.doPrivileged(Native Method)
> at
> java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
> at
> java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
> at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
> at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
> at java.base/java.security.AccessController.doPrivileged(Native Method)
> at
> java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
> at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
> at
> org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:136)
> [catch] at
> java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
> at
> java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
> at
> java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists