eisop / checker-framework

Pluggable type-checking for Java
https://eisop.github.io/
Other
19 stars 19 forks source link

`ApplyFakeOverrides` erase the annotation of return type #786

Open Ao-senXiong opened 5 months ago

Ao-senXiong commented 5 months ago

Script

./checker/bin/javac -cp "framework/build/classes/java/main:framework/build/classes/java/test" -processorpath "checker/dist/checker.jar:framework/build/classes/java/test" -processor viewpointtest.ViewpointTestChecker Test.java

code

import javax.lang.model.element.TypeElement;

public class Test {
    void test(TypeElement element) {
        element.asType();
    }
}

Stacktrace:

error: Error in AnnotatedTypeMirror.fromExpression(ViewpointTestAnnotatedTypeFactory, element.asType()): Unexpected null argument:  compareByName(null, @viewpointtest.quals.ReceiverDependentQual)
  ; The Checker Framework crashed.  Please report the crash.  Version: Checker Framework 3.42.0-eisop4-SNAPSHOT, branch clearAnnotation-only-typevar, 2024-06-20, commit b5fc573, dirty=true. 
  Checker: class viewpointtest.ViewpointTestChecker
  Visitor: class org.checkerframework.common.basetype.BaseTypeVisitor
  Compilation unit: Tester.java
  Last visited tree at line 6 column 1:
  public class Tester {
  Exception: org.checkerframework.javacutil.BugInCF: Unexpected null argument:  compareByName(null, @viewpointtest.quals.ReceiverDependentQual); org.checkerframework.javacutil.BugInCF: Unexpected null argument:  compareByName(null, @viewpointtest.quals.ReceiverDependentQual)
        at org.checkerframework.javacutil.AnnotationUtils.compareByName(AnnotationUtils.java:135)
        at org.checkerframework.javacutil.AnnotationUtils.areSameByName(AnnotationUtils.java:162)
        at org.checkerframework.javacutil.AnnotationUtils.areSame(AnnotationUtils.java:113)
        at viewpointtest.ViewpointTestViewpointAdapter.combineAnnotationWithAnnotation(ViewpointTestViewpointAdapter.java:40)
        at org.checkerframework.framework.type.AbstractViewpointAdapter.combineAnnotationWithType(AbstractViewpointAdapter.java:313)
        at org.checkerframework.framework.type.AbstractViewpointAdapter.combineTypeWithType(AbstractViewpointAdapter.java:245)
        at org.checkerframework.framework.type.AbstractViewpointAdapter.viewpointAdaptMethod(AbstractViewpointAdapter.java:176)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.methodFromUse(AnnotatedTypeFactory.java:2570)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.methodFromUse(AnnotatedTypeFactory.java:2512)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.methodFromUse(GenericAnnotatedTypeFactory.java:2299)
        at org.checkerframework.framework.type.TypeFromExpressionVisitor.visitMethodInvocation(TypeFromExpressionVisitor.java:413)
        at org.checkerframework.framework.type.TypeFromExpressionVisitor.visitMethodInvocation(TypeFromExpressionVisitor.java:81)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1666)
        at jdk.compiler/com.sun.source.util.SimpleTreeVisitor.visit(SimpleTreeVisitor.java:80)
        at org.checkerframework.framework.type.TypeFromTree.fromExpression(TypeFromTree.java:42)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.fromExpression(AnnotatedTypeFactory.java:1852)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.getAnnotatedType(AnnotatedTypeFactory.java:1495)
        at org.checkerframework.framework.flow.CFAbstractTransfer.getValueFromFactory(CFAbstractTransfer.java:215)
        at org.checkerframework.framework.flow.CFAbstractTransfer.visitMethodInvocation(CFAbstractTransfer.java:999)
        at org.checkerframework.framework.flow.CFAbstractTransfer.visitMethodInvocation(CFAbstractTransfer.java:97)
        at org.checkerframework.dataflow.cfg.node.MethodInvocationNode.accept(MethodInvocationNode.java:124)
        at org.checkerframework.dataflow.analysis.AbstractAnalysis.callTransferFunction(AbstractAnalysis.java:356)
        at org.checkerframework.dataflow.analysis.ForwardAnalysisImpl.callTransferFunction(ForwardAnalysisImpl.java:393)
        at org.checkerframework.dataflow.analysis.ForwardAnalysisImpl.performAnalysisBlock(ForwardAnalysisImpl.java:157)
        at org.checkerframework.dataflow.analysis.ForwardAnalysisImpl.performAnalysis(ForwardAnalysisImpl.java:110)
        at org.checkerframework.framework.flow.CFAbstractAnalysis.performAnalysis(CFAbstractAnalysis.java:150)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.analyze(GenericAnnotatedTypeFactory.java:1624)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.performFlowAnalysis(GenericAnnotatedTypeFactory.java:1513)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.checkAndPerformFlowAnalysis(GenericAnnotatedTypeFactory.java:2101)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.preProcessClassTree(GenericAnnotatedTypeFactory.java:435)
        at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:591)
        at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:195)
        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:89)
        at org.checkerframework.framework.source.SourceChecker.typeProcess(SourceChecker.java:1136)
        at org.checkerframework.common.basetype.BaseTypeChecker.typeProcess(BaseTypeChecker.java:556)
        at org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:193)
        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:1417)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374)
        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)
  Caused by: java.lang.Throwable
        at org.checkerframework.javacutil.BugInCF.<init>(BugInCF.java:34)
        ... 47 more

  Underlying Exception: java.lang.Throwable; java.lang.Throwable
        at org.checkerframework.javacutil.BugInCF.<init>(BugInCF.java:34)
        at org.checkerframework.javacutil.AnnotationUtils.compareByName(AnnotationUtils.java:135)
        at org.checkerframework.javacutil.AnnotationUtils.areSameByName(AnnotationUtils.java:162)
        at org.checkerframework.javacutil.AnnotationUtils.areSame(AnnotationUtils.java:113)
        at viewpointtest.ViewpointTestViewpointAdapter.combineAnnotationWithAnnotation(ViewpointTestViewpointAdapter.java:40)
        at org.checkerframework.framework.type.AbstractViewpointAdapter.combineAnnotationWithType(AbstractViewpointAdapter.java:313)
        at org.checkerframework.framework.type.AbstractViewpointAdapter.combineTypeWithType(AbstractViewpointAdapter.java:245)
        at org.checkerframework.framework.type.AbstractViewpointAdapter.viewpointAdaptMethod(AbstractViewpointAdapter.java:176)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.methodFromUse(AnnotatedTypeFactory.java:2570)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.methodFromUse(AnnotatedTypeFactory.java:2512)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.methodFromUse(GenericAnnotatedTypeFactory.java:2299)
        at org.checkerframework.framework.type.TypeFromExpressionVisitor.visitMethodInvocation(TypeFromExpressionVisitor.java:413)
        at org.checkerframework.framework.type.TypeFromExpressionVisitor.visitMethodInvocation(TypeFromExpressionVisitor.java:81)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1666)
        at jdk.compiler/com.sun.source.util.SimpleTreeVisitor.visit(SimpleTreeVisitor.java:80)
        at org.checkerframework.framework.type.TypeFromTree.fromExpression(TypeFromTree.java:42)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.fromExpression(AnnotatedTypeFactory.java:1852)
        at org.checkerframework.framework.type.AnnotatedTypeFactory.getAnnotatedType(AnnotatedTypeFactory.java:1495)
        at org.checkerframework.framework.flow.CFAbstractTransfer.getValueFromFactory(CFAbstractTransfer.java:215)
        at org.checkerframework.framework.flow.CFAbstractTransfer.visitMethodInvocation(CFAbstractTransfer.java:999)
        at org.checkerframework.framework.flow.CFAbstractTransfer.visitMethodInvocation(CFAbstractTransfer.java:97)
        at org.checkerframework.dataflow.cfg.node.MethodInvocationNode.accept(MethodInvocationNode.java:124)
        at org.checkerframework.dataflow.analysis.AbstractAnalysis.callTransferFunction(AbstractAnalysis.java:356)
        at org.checkerframework.dataflow.analysis.ForwardAnalysisImpl.callTransferFunction(ForwardAnalysisImpl.java:393)
        at org.checkerframework.dataflow.analysis.ForwardAnalysisImpl.performAnalysisBlock(ForwardAnalysisImpl.java:157)
        at org.checkerframework.dataflow.analysis.ForwardAnalysisImpl.performAnalysis(ForwardAnalysisImpl.java:110)
        at org.checkerframework.framework.flow.CFAbstractAnalysis.performAnalysis(CFAbstractAnalysis.java:150)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.analyze(GenericAnnotatedTypeFactory.java:1624)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.performFlowAnalysis(GenericAnnotatedTypeFactory.java:1513)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.checkAndPerformFlowAnalysis(GenericAnnotatedTypeFactory.java:2101)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.preProcessClassTree(GenericAnnotatedTypeFactory.java:435)
        at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:591)
        at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:195)
        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:89)
        at org.checkerframework.framework.source.SourceChecker.typeProcess(SourceChecker.java:1136)
        at org.checkerframework.common.basetype.BaseTypeChecker.typeProcess(BaseTypeChecker.java:556)
        at org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:193)
        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:1417)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374)
        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)

Reason (Java 11):

image

Java 17:

image
Ao-senXiong commented 5 months ago

apprently, this clearAnnotations clear everything https://github.com/eisop/checker-framework/blob/481040f5af69012d3b410e1844f31d84fff7b7c4/framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileParser.java#L1524.

wmdietl commented 5 months ago

A side comment: you are using ./checker/bin/javac which automatically adds all CF jar files. You only need to add the directories with the test annotations, if they are necessary.

Ao-senXiong commented 5 months ago

A side comment: you are using ./checker/bin/javac which automatically adds all CF jar files. You only need to add the directories with the test annotations, if they are necessary.

Thanks, I have updated the description.

Ao-senXiong commented 2 months ago

Based on the furthur debugging, looks like this issue is related to stubTypes field is different in Java 11 and Java 17 https://github.com/eisop/checker-framework/blob/f8fd1a87488065d38dbf7442d2d2a1d8f9e66674/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java#L2687

Ao-senXiong commented 2 months ago

More specificly, this field in AnnotationFileElementTypes.AnnotationFileParser. https://github.com/eisop/checker-framework/blob/f8fd1a87488065d38dbf7442d2d2a1d8f9e66674/framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileParser.java#L308