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

NPE with nested instanceof patterns #4349

Closed
martint opened this issue Mar 26, 2024 · 0 comments
Closed

NPE with nested instanceof patterns #4349

martint opened this issue Mar 26, 2024 · 0 comments

Comments

@martint
Copy link

martint commented Mar 26, 2024

The following code:

public class ErrorProneBug
{
    record Struct(Object a) {}

    private ErrorProneBug() {}

    public static void method(Object x, Object y)
    {
        if (x instanceof Struct(Integer a1)) {
            if (y instanceof Struct(Integer a2)) {
                System.out.println("hello");
            }
        }
    }
}

Causes a failure:

error-prone version: 2.26.1
BugPattern: NestedInstanceOfConditions
Stack Trace:
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.isPrimitive()" because "t" is null
   	at jdk.compiler/com.sun.tools.javac.code.Types.eraseNotNeeded(Types.java:2388)
   	at jdk.compiler/com.sun.tools.javac.code.Types.erasure(Types.java:2381)
   	at com.google.errorprone.bugpatterns.NestedInstanceOfConditions$NestedInstanceOfMatcher.matches(NestedInstanceOfConditions.java:125)
   	at com.google.errorprone.matchers.Contains$FirstMatchingScanner.scan(Contains.java:58)
   	at com.google.errorprone.matchers.Contains$FirstMatchingScanner.scan(Contains.java:45)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)
   	at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:272)
   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1104)
   	at com.google.errorprone.matchers.Contains.matches(Contains.java:41)
   	at com.google.errorprone.bugpatterns.NestedInstanceOfConditions.matchIf(NestedInstanceOfConditions.java:72)
   	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:653)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitIf(ErrorProneScanner.java:150)
   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1584)
   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)
   	at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:272)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:520)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:150)
   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1104)
   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:96)
   	at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:224)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:740)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:150)
   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:948)
   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:96)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)
   	at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:203)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:548)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:150)
   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:855)
   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)
   	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)
   	at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:152)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:560)
   	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:623)
   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:66)
   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:58)
   	at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)
   	at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:156)
   	at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:133)
   	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1436)
   	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1383)
   	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:963)
   	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
   	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
   	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
   	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
   	at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
   	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:214)
   	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1228)
   	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:215)
   	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
   	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
   	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
   	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
   	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
   	at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
   	at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
   	at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
   	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
   	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
   	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:193)
   	at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:180)
   	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
   	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
   	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
   	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
   	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
   	at java.base/java.lang.Thread.run(Thread.java:1583)
copybara-service bot pushed a commit that referenced this issue May 14, 2024
Fixes external #4349

PiperOrigin-RevId: 633567893
copybara-service bot pushed a commit that referenced this issue May 14, 2024
Fixes external #4349

PiperOrigin-RevId: 633572373
@cushon cushon closed this as completed May 31, 2024
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

2 participants