Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class declaration in method causes crash with -Ainfer #3461

Closed
jwaataja opened this issue Jul 9, 2020 · 0 comments · Fixed by #3462
Closed

Class declaration in method causes crash with -Ainfer #3461

jwaataja opened this issue Jul 9, 2020 · 0 comments · Fixed by #3462
Assignees

Comments

@jwaataja
Copy link
Contributor

jwaataja commented Jul 9, 2020

This bug was introduced by #3441. I get a crash when a class is declared inside a method with -Ainfer.

public class ClassInMethod {
    public void method() {
        class Inner {
            Object o = null;
        }
    }
}
$CHECKERFRAMEWORK/checker/bin/javac -processor Nullnesschecker -Ainfer=stubs ClassInMethod.java
error: SourceChecker.typeProcess: unexpected Throwable (ClassCastException) while processing ClassInMethod.java; message: class com.sun.tools.javac.code.Symbol$MethodSymbol cannot be cast to class javax.lang.model.element.TypeElement (com.sun.tools.javac.code.Symbol$MethodSymbol is in module jdk.compiler of loader 'app'; javax.lang.model.element.TypeElement is in module java.compiler of loader 'platform')
  ; The Checker Framework crashed.  Please report the crash.
  Compilation unit: ClassInMethod.java
  Last visited tree at line 4 column 24:
              Object o = null;
  Exception: java.lang.ClassCastException: class com.sun.tools.javac.code.Symbol$MethodSymbol cannot be cast to class javax.lang.model.element.TypeElement (com.sun.tools.javac.code.Symbol$MethodSymbol is in module jdk.compiler of loader 'app'; javax.lang.model.element.TypeElement is in module java.compiler of loader 'platform'); java.lang.ClassCastException: class com.sun.tools.javac.code.Symbol$MethodSymbol cannot be cast to class javax.lang.model.element.TypeElement (com.sun.tools.javac.code.Symbol$MethodSymbol is in module jdk.compiler of loader 'app'; javax.lang.model.element.TypeElement is in module java.compiler of loader 'platform')
  	at org.checkerframework.common.wholeprograminference.SceneToStubWriter.getTypeElementsForClasses(SceneToStubWriter.java:509)
  	at org.checkerframework.common.wholeprograminference.SceneToStubWriter.printClassDefinitions(SceneToStubWriter.java:465)
  	at org.checkerframework.common.wholeprograminference.SceneToStubWriter.printClass(SceneToStubWriter.java:715)
  	at org.checkerframework.common.wholeprograminference.SceneToStubWriter.writeImpl(SceneToStubWriter.java:655)
  	at org.checkerframework.common.wholeprograminference.SceneToStubWriter.write(SceneToStubWriter.java:92)
  	at org.checkerframework.common.wholeprograminference.scenelib.ASceneWrapper.writeToFile(ASceneWrapper.java:147)
  	at org.checkerframework.common.wholeprograminference.WholeProgramInferenceScenesStorage.writeScenes(WholeProgramInferenceScenesStorage.java:110)
  	at org.checkerframework.common.wholeprograminference.WholeProgramInferenceScenes.writeResultsToFile(WholeProgramInferenceScenes.java:438)
  	at org.checkerframework.framework.type.AnnotatedTypeFactory.postProcessClassTree(AnnotatedTypeFactory.java:1123)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:328)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:166)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at org.checkerframework.framework.source.SourceVisitor.scan(SourceVisitor.java:88)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:289)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:166)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:248)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1032)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at org.checkerframework.framework.source.SourceVisitor.scan(SourceVisitor.java:88)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:289)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:166)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:206)
  	at org.checkerframework.framework.source.SourceVisitor.visitMethod(SourceVisitor.java:106)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitMethod(BaseTypeVisitor.java:732)
  	at org.checkerframework.checker.initialization.InitializationVisitor.visitMethod(InitializationVisitor.java:333)
  	at org.checkerframework.checker.initialization.InitializationVisitor.visitMethod(InitializationVisitor.java:51)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at org.checkerframework.framework.source.SourceVisitor.scan(SourceVisitor.java:88)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:289)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:166)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:187)
  	at org.checkerframework.framework.source.SourceVisitor.visitClass(SourceVisitor.java:94)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.processClassTree(BaseTypeVisitor.java:374)
  	at org.checkerframework.checker.initialization.InitializationVisitor.processClassTree(InitializationVisitor.java:293)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:327)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:166)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
  	at org.checkerframework.framework.source.SourceVisitor.visit(SourceVisitor.java:82)
  	at org.checkerframework.framework.source.SourceChecker.typeProcess(SourceChecker.java:901)
  	at org.checkerframework.common.basetype.BaseTypeChecker.typeProcess(BaseTypeChecker.java:512)
  	at org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:190)
  	at jdk.compiler/com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:828)
  	at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1418)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1375)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
  	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
  	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
  	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
  	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
ClassInMethod.java:4: error: [assignment.type.incompatible] incompatible types in assignment.
            Object o = null;
                       ^
  found   : null
  required: @Initialized @NonNull Object
2 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant