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

NullPointerException when using matcher in Refaster since 2.16 #3484

Closed
PhilippWendler opened this issue Oct 13, 2022 · 3 comments
Closed

NullPointerException when using matcher in Refaster since 2.16 #3484

PhilippWendler opened this issue Oct 13, 2022 · 3 comments

Comments

@PhilippWendler
Copy link

I have the following Refaster rule that produces a NullPointerException when being applied to one of our projects with Error Prone 2.16, but not with 2.15.0:

package org.sosy_lab.refaster.rules.guava.immutable;

import com.google.common.collect.ImmutableCollection;
import com.google.errorprone.matchers.CompileTimeConstantExpressionMatcher;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.google.errorprone.refaster.annotation.Matches;

class ImmutableCollectionBuilderAddAll<E> {

  @BeforeTemplate
  void addInLoop(
      Iterable<E> source,
      @Matches(CompileTimeConstantExpressionMatcher.class) ImmutableCollection.Builder<E> target) {
    for (E e : source) {
      target.add(e);
    }
  }

  @AfterTemplate
  void addAll(Iterable<E> source, ImmutableCollection.Builder<E> target) {
    target.addAll(source);
  }
}

The compiled version of this rule that I am using is in rule.zip.

I am using OpenJDK 11.0.16 on Ubuntu 22.04, as mentioned with Error Prone 2.16.

The stack trace is

[javac] An exception has occurred in the compiler (11.0.16). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) a
 checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
[javac] java.lang.NullPointerException
[javac]     at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:889)
[javac]     at com.google.errorprone.VisitorState.withPath(VisitorState.java:223)
[javac]     at com.google.errorprone.refaster.UMatches.makeVisitorState(UMatches.java:99)
[javac]     at com.google.errorprone.refaster.UMatches.matches(UMatches.java:85)
[javac]     at com.google.errorprone.refaster.UMatches.lambda$defaultAction$0(UMatches.java:60)
[javac]     at com.google.errorprone.refaster.Choice$2.condition(Choice.java:117)
[javac]     at com.google.errorprone.refaster.UMatches.defaultAction(UMatches.java:60)
[javac]     at com.google.errorprone.refaster.UMatches.defaultAction(UMatches.java:36)
[javac]     at jdk.compiler/com.sun.source.util.SimpleTreeVisitor.visitIdentifier(SimpleTreeVisitor.java:587)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2272)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:35)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:31)
[javac]     at com.google.errorprone.refaster.Unifier.unifyNullable(Unifier.java:118)
[javac]     at com.google.errorprone.refaster.Unifier.lambda$unifications$0(Unifier.java:108)
[javac]     at com.google.errorprone.refaster.Choice$2.thenChoose(Choice.java:122)
[javac]     at com.google.errorprone.refaster.UMemberSelect.visitIdentifier(UMemberSelect.java:72)
[javac]     at com.google.errorprone.refaster.UMemberSelect.visitIdentifier(UMemberSelect.java:34)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2272)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:35)
[javac]     at com.google.errorprone.refaster.UMethodInvocation.visitMethodInvocation(UMethodInvocation.java:56)
[javac]     at com.google.errorprone.refaster.UMethodInvocation.visitMethodInvocation(UMethodInvocation.java:35)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1666)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:35)
[javac]     at com.google.errorprone.refaster.UExpressionStatement.visitExpressionStatement(UExpressionStatement.java:43)
[javac]     at com.google.errorprone.refaster.UExpressionStatement.visitExpressionStatement(UExpressionStatement.java:30)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1476)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:35)
[javac]     at com.google.errorprone.refaster.USimpleStatement.apply(USimpleStatement.java:50)
[javac]     at com.google.errorprone.refaster.USimpleStatement.apply(USimpleStatement.java:30)
[javac]     at com.google.errorprone.refaster.Choice$2.thenChoose(Choice.java:122)
[javac]     at com.google.errorprone.refaster.UBlock.unifyStatementList(UBlock.java:55)
[javac]     at com.google.errorprone.refaster.UBlock.visitBlock(UBlock.java:76)
[javac]     at com.google.errorprone.refaster.UBlock.visitBlock(UBlock.java:35)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1048)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:35)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:31)
[javac]     at com.google.errorprone.refaster.Unifier.unifyNullable(Unifier.java:118)
[javac]     at com.google.errorprone.refaster.Unifier.lambda$unifications$0(Unifier.java:108)
[javac]     at com.google.errorprone.refaster.Choice$2.thenChoose(Choice.java:122)
[javac]     at com.google.errorprone.refaster.UEnhancedForLoop.visitEnhancedForLoop(UEnhancedForLoop.java:72)
[javac]     at com.google.errorprone.refaster.UEnhancedForLoop.visitEnhancedForLoop(UEnhancedForLoop.java:31)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:1188)
[javac]     at com.google.errorprone.refaster.UTree.unify(UTree.java:35)
[javac]     at com.google.errorprone.refaster.USimpleStatement.apply(USimpleStatement.java:50)
[javac]     at com.google.errorprone.refaster.USimpleStatement.apply(USimpleStatement.java:30)
[javac]     at com.google.errorprone.refaster.Choice$2.thenChoose(Choice.java:122)
[javac]     at com.google.errorprone.refaster.BlockTemplate.matchesStartingAtBeginning(BlockTemplate.java:120)
[javac]     at com.google.errorprone.refaster.BlockTemplate.matchesStartingAnywhere(BlockTemplate.java:169)
[javac]     at com.google.errorprone.refaster.BlockTemplate.match(BlockTemplate.java:101)
[javac]     at com.google.errorprone.refaster.RefasterScanner.scan(RefasterScanner.java:107)
[javac]     at com.google.errorprone.refaster.RefasterScanner.scan(RefasterScanner.java:51)
[javac]     at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
[javac]     at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:206)
[javac]     at com.google.errorprone.refaster.RefasterScanner.visitMethod(RefasterScanner.java:88)
[javac]     at com.google.errorprone.refaster.RefasterScanner.visitMethod(RefasterScanner.java:51)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)
[javac]     at com.google.errorprone.refaster.RefasterScanner.visitClass(RefasterScanner.java:75)
[javac]     at com.google.errorprone.refaster.RefasterScanner.visitClass(RefasterScanner.java:51)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
[javac]     at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:86)
[javac]     at com.google.errorprone.refaster.RefasterScanner.scan(RefasterScanner.java:132)
[javac]     at com.google.errorprone.refaster.RefasterScanner.scan(RefasterScanner.java:51)
[javac]     at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
[javac]     at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
[javac]     at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144)
[javac]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
[javac]     at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:86)
[javac]     at com.google.errorprone.refaster.RefasterScanner.scan(RefasterScanner.java:132)
[javac]     at com.google.errorprone.refaster.RefasterRule.apply(RefasterRule.java:139)
[javac]     at com.google.errorprone.CompositeCodeTransformer.apply(CompositeCodeTransformer.java:45)
[javac]     at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:152)
[javac]     at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
[javac]     at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1414)
[javac]     at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1361)
[javac]     at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960)
[javac]     at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
[javac]     at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
[javac]     at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
[javac]     at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
[javac] Compile failed; see the compiler error output for details.

The crash does not occur if I remove @Matches(CompileTimeConstantExpressionMatcher.class). We have other (working) rules with @Matches, so maybe it is related only to CompileTimeConstantExpressionMatcher?

Unfortunately, it is hard to debug further because I do not know a way how to find out which of our 2800 Java files causes this. If I run the compiler with verbose=true, the last lines before the crash are

...
[javac] [checking org.sosy_lab.cpachecker.util.variableclassification.PartitionTest]                                                                                  
[javac] [checking org.sosy_lab.cpachecker.util.variableclassification.VariableClassificationBuilder]                                                                  
[javac] [loading /home/wendler/git/cpachecker/lib/java/runtime/error_prone_annotations.jar(/com/google/errorprone/annotations/CompileTimeConstant.class)]             
[javac] [loading modules/java.xml/javax/xml/transform/TransformerFactoryConfigurationError.class]                                                                     
[javac] [loading modules/java.xml/javax/xml/transform/TransformerConfigurationException.class]                                                                        
[javac] [total 18070ms]                                                                          

However, it does not seem as if VariableClassificationBuilder is the problematic class because the crash still occurs if I delete basically all source code from this class except for empty methods. The annotation CompileTimeConstant is not used in our code base (but maybe in libraries).

So if you have some hints on what could I do to find out the problematic source code, I would be happy to debug this further.

Alternatively, here is how this could be reproduced locally:

If there is anything else I could do to help debugging this, please let me know.

@cpovirk
Copy link
Member

cpovirk commented Oct 13, 2022

Thanks, and sorry. (I added that null check....) I believe @nick-someone has been looking at an internal report we just got about this a couple days ago.

copybara-service bot pushed a commit that referenced this issue Oct 14, 2022
PiperOrigin-RevId: 481211730
copybara-service bot pushed a commit that referenced this issue Oct 14, 2022
PiperOrigin-RevId: 481216285
@cpovirk
Copy link
Member

cpovirk commented Oct 14, 2022

(The above change by @cushon works around this. I don't know if he has plans to go further at this point.)

@cushon
Copy link
Collaborator

cushon commented Oct 26, 2022

I don't know if he has plans to go further at this point.

Not at the moment :)

@cushon cushon closed this as completed Oct 26, 2022
sosy-bot pushed a commit to sosy-lab/cpachecker that referenced this issue Dec 16, 2022
Somehow the NullPointerException that we previously only saw with
Error Prone 2.16 (google/error-prone#3484)
has now started to appear with Error Prone 2.15 as well.
We will wait for Error Prone 2.17 and then try again.

This is not critical as Refaster suggestions come with a patch,
so even if lots of issues are introduced in the meantime,
we can easily fix them all automatically later on.

git-svn-id: https://svn.sosy-lab.org/software/cpachecker/trunk@42571 4712c6d2-40bb-43ae-aa4b-fec3f1bdfe4c
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

No branches or pull requests

3 participants