lovubuntu / checker-framework

Automatically exported from code.google.com/p/checker-framework
0 stars 0 forks source link

Nested Aggregate Checker Initialization #343

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
$ javac -version
javac 1.8.0_11
$ cat Test.java 
public class Test {}
$ cat AggregateCheckerEx.java 
import org.checkerframework.checker.fenum.FenumChecker;
import org.checkerframework.checker.nullness.NullnessChecker;
import org.checkerframework.checker.regex.RegexChecker;
import org.checkerframework.framework.source.AggregateChecker;
import org.checkerframework.framework.source.SourceChecker;
import java.util.Arrays;
import java.util.Collection;

public class AggregateCheckerEx extends AggregateChecker {
    @Override
    protected Collection<Class<? extends SourceChecker>> getSupportedCheckers() {
        return Arrays.asList(
            NullnessChecker.class,
            FenumChecker.class,
            RegexChecker.class
        );
    }
}
$ javac AggregateCheckerEx.java -classpath 
/opt/checker-framework-1.8.3/checker/dist/checker.jar:/usr/lib/jvm/java-8-oracle
/lib/tools.jar
$ javac -processor AggregateCheckerEx Test.java -classpath 
/opt/checker-framework-1.8.3/checker/dist/checker.jar:/usr/lib/jvm/java-8-oracle
/lib/tools.jar:. -AprintErrorStack
error: SourceChecker.typeProcessingStart: unexpected Throwable 
(NullPointerException)
  Exception: java.lang.NullPointerException; Stack trace: com.sun.source.util.Trees.instance(Trees.java:75)
  org.checkerframework.framework.source.SourceVisitor.<init>(SourceVisitor.java:47)
  org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:182)
  org.checkerframework.checker.initialization.InitializationVisitor.<init>(InitializationVisitor.java:72)
  org.checkerframework.checker.nullness.NullnessVisitor.<init>(NullnessVisitor.java:87)
  org.checkerframework.checker.nullness.AbstractNullnessChecker.createSourceVisitor(AbstractNullnessChecker.java:57)
  org.checkerframework.checker.nullness.AbstractNullnessChecker.createSourceVisitor(AbstractNullnessChecker.java:14)
  org.checkerframework.framework.source.AggregateVisitor.<init>(AggregateChecker.java:180)
  org.checkerframework.framework.source.AggregateChecker.createSourceVisitor(AggregateChecker.java:161)
  org.checkerframework.framework.source.AggregateVisitor.<init>(AggregateChecker.java:180)
  org.checkerframework.framework.source.AggregateChecker.createSourceVisitor(AggregateChecker.java:161)
  org.checkerframework.framework.source.SourceChecker.initChecker(SourceChecker.java:703)
  org.checkerframework.framework.source.AggregateChecker.initChecker(AggregateChecker.java:77)
  org.checkerframework.framework.source.SourceChecker.typeProcessingStart(SourceChecker.java:664)
  org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:183)
  com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:681)
  com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:111)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1340)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1299)
  com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:904)
  com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:863)
  com.sun.tools.javac.main.Main.compile(Main.java:523)
  com.sun.tools.javac.main.Main.compile(Main.java:381)
  com.sun.tools.javac.main.Main.compile(Main.java:370)
  com.sun.tools.javac.main.Main.compile(Main.java:361)
  com.sun.tools.javac.Main.compile(Main.java:56)
  com.sun.tools.javac.Main.main(Main.java:42)
1 error

I guess it happens because of NullnessChecker is AggregateChecker itself.
I believe AggregateChecker should call init() method on the child checkers 
recursively or set processing environment recursively.

This is my suggestion for AggregateChecker class:
@Override
protected void setProcessingEnvironment(ProcessingEnvironment env) {
    this.processingEnv = env;
    for (SourceChecker checker : checkers) {
        checker.setProcessingEnvironment(env);
    }
}

Unfortunately I can neither override init of AggregateChecker (because it is 
declared final) nor override setProcessingEnvironment() (package-local), is it 
by design?

Please provide any additional information below.

Reported by Daniil Ovchinnikov

Original issue reported on code.google.com by mcart...@cs.washington.edu on 23 Jul 2014 at 2:42

GoogleCodeExporter commented 9 years ago

Original comment by mcarthur...@gmail.com on 25 Jul 2014 at 8:03

GoogleCodeExporter commented 9 years ago

Original comment by mcarthur...@gmail.com on 2 Aug 2014 at 12:00