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

Resource Leak processor throws an exception when @MustCall is annotated on a Type Variable #4815

Closed
weijunkong opened this issue Jul 20, 2021 · 5 comments
Assignees
Labels

Comments

@weijunkong
Copy link

Commands
./checker-framework-3.16.0/checker/bin/javac -processor resourceleak MustCallBug.java

Inputs

\\ MustCallBug.java
import java.util.List;
import org.checkerframework.checker.mustcall.qual.MustCall;
import org.checkerframework.checker.mustcall.qual.Owning;

public class MustCallBug {
  public <T extends Component> void initialize(
      List<T> list,
      @Owning @MustCall("initialize") T object) {
    object.initialize();
    list.add(object);
  }

  private static class Component {
    void initialize() {}
  }
}

Outputs

error: Unexpected null argument:  areSameByName(null, @org.checkerframework.checker.calledmethods.qual.CalledMethodsBottom)
  ; The Checker Framework crashed.  Please report the crash.
  Compilation unit: MustCallBug.java
  Last visited tree at line 5 column 1:
  public class MustCallBug {
  Exception: java.lang.Throwable; java.lang.Throwable
        at org.checkerframework.javacutil.BugInCF.<init>(BugInCF.java:32)
        at org.checkerframework.javacutil.AnnotationUtils.areSameByName(AnnotationUtils.java:131)
        at org.checkerframework.javacutil.AnnotationUtils.areSame(AnnotationUtils.java:110)
        at org.checkerframework.common.accumulation.AccumulationAnnotatedTypeFactory$AccumulationQualifierHierarchy.isSubtype(AccumulationAnnotatedTypeFactory.java:467)
        at org.checkerframework.checker.resourceleak.MustCallConsistencyAnalyzer.calledMethodsSatisfyMustCall(MustCallConsistencyAnalyzer.java:1581)
        at org.checkerframework.checker.resourceleak.MustCallConsistencyAnalyzer.checkMustCall(MustCallConsistencyAnalyzer.java:1494)
        at org.checkerframework.checker.resourceleak.MustCallConsistencyAnalyzer.handleSuccessorBlocks(MustCallConsistencyAnalyzer.java:1286)
        at org.checkerframework.checker.resourceleak.MustCallConsistencyAnalyzer.analyze(MustCallConsistencyAnalyzer.java:203)
        at org.checkerframework.checker.resourceleak.ResourceLeakAnnotatedTypeFactory.postAnalyze(ResourceLeakAnnotatedTypeFactory.java:109)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.analyze(GenericAnnotatedTypeFactory.java:1543)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.performFlowAnalysis(GenericAnnotatedTypeFactory.java:1391)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.checkAndPerformFlowAnalysis(GenericAnnotatedTypeFactory.java:1812)
        at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.preProcessClassTree(GenericAnnotatedTypeFactory.java:412)
        at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:479)
        at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:190)
        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:989)
        at org.checkerframework.common.basetype.BaseTypeChecker.typeProcess(BaseTypeChecker.java:542)
        at org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:188)
        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:1394)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1351)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:947)
        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)
1 error

Expectation
Checker Framework should be able to handle this example and not throw an exception.

@mernst mernst added the crash label Jul 20, 2021
mernst added a commit that referenced this issue Jul 20, 2021
@mernst
Copy link
Member

mernst commented Jul 20, 2021

Thank you for reporting the crash! We appreciate it.

I have committed the test case as checker/tests/resourceleak/Issue4815.java.

The crash does not occur when running the Must Call Checker with -processor mustcall.

@kelloggm
Copy link
Contributor

#4821 resolves the crash. A false positive error is still issued by the checker (which isn't ideal), but I think that's a separate issue (I don't think the Called Methods Checker handles type variables very precisely).

@msridhar
Copy link
Contributor

Should we file a follow-up issue to fix the false positive, or keep this issue open for that problem as well?

@kelloggm
Copy link
Contributor

I think a follow up issue would be better. I'll wait until this one is closed, though.

@kelloggm
Copy link
Contributor

Closed in favor of #4837, which describes only the false positive. The crash (which this issue represents) has been fixed.

wmdietl pushed a commit to eisop/checker-framework that referenced this issue Aug 3, 2021
wmdietl pushed a commit to eisop/checker-framework that referenced this issue Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants