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

"An unhandled exception was thrown by the Error Prone static analysis plugin" #4736

Closed
sikchi opened this issue Dec 21, 2024 · 2 comments
Closed

Comments

@sikchi
Copy link

sikchi commented Dec 21, 2024

Following up on the exception message below:

An unhandled exception was thrown by the Error Prone static analysis plugin.
     Please report this at https://github.com/google/error-prone/issues/new and include the following:
     error-prone version: 2.36.0
     BugPattern: ComputeIfAbsentAmbiguousReference
     Stack Trace:
     java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
  	at jdk.compiler/com.sun.tools.javac.util.List.get(List.java:476)
  	at com.google.errorprone.bugpatterns.ComputeIfAbsentAmbiguousReference.matchMethodInvocation(ComputeIfAbsentAmbiguousReference.java:60)
  	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:509)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:824)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:170)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1832)
  	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.visitVariable(TreeScanner.java:243)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitVariable(ErrorProneScanner.java:1017)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitVariable(ErrorProneScanner.java:170)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1040)
  	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:591)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitBlock(ErrorProneScanner.java:170)
  	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:818)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:170)
  	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:619)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:170)
  	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:631)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:170)
  	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:227)
  	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:136)
  	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:183)
  	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1140)
  	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:193)
  	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.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
  	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
  	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
  	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
  	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
  	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
  	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
  	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
  	at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
  	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
  	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)
  	at org.codehaus.classworlds.Launcher.main(Launcher.java:41)

@cushon
Copy link
Collaborator

cushon commented Dec 21, 2024

Thanks for the report, can you share a repro, or any context about the specific code that the check crashed on?

Looking at the implementation, perhaps it was a custom Map implementation that defined an overload of computeIfAbsent with only one argument?

@sikchi
Copy link
Author

sikchi commented Dec 21, 2024

Yes. here's the code snippet. calling lru.computeIfAbsent() results in above exception.

private static final class LRU extends LinkedHashMap<Key, V>
{
private static final float LOAD_FACTOR = 0.75f;
private final int cacheSize;
private final Function<List, List> getValues;

  private LRU (int cacheSize, Function<List<Key>, List<V>> getValues)
  {
     super((int) (cacheSize / LOAD_FACTOR), LOAD_FACTOR, true);
     this.cacheSize = cacheSize;
     this.getValues = getValues;
  }

  private List<V> computeIfAbsent (List<Key> keyList)
  {
     int n = keyList.size();
     ArrayList<V> values = new ArrayList<>(n);
     IntArrayList notFoundIndexes = new IntArrayList();
     List<Key> notFound = new ArrayList<>();
     for (int i = 0; i < n; i++)
     {
        Key key = keyList.get(i);
        V value = get(key);
        values.add(value);
        if (value == null)
        {
           notFoundIndexes.add(i);
           notFound.add(key);
        }
     }
     List<V> valuesToAdd = getValues.apply(notFound);
     for (int ii = 0; ii < notFoundIndexes.size(); ii++)
     {
        int i = notFoundIndexes.getInt(ii);
        Key key = keyList.get(i);
        V value = valuesToAdd.get(ii);
        putUnique(key, value);
        values.set(i, value);
     }
     List<V> result = Collections.unmodifiableList(values);
     return result;
  }

  private void putUnique (Key key, V value)
  {
     V previousValue = putIfAbsent(key, value);
     if (previousValue != null)
     {
        throw new UnsupportedOperationException("dup insertion attempted: key=" + key
              + ", previousValue=" + previousValue + ", value=" + value);
     }
  }

  @Override protected final boolean removeEldestEntry (Map.Entry<Key, V> eldest)
  {
     boolean result = (this.size() > cacheSize);
     return result;
  }

}

copybara-service bot pushed a commit that referenced this issue Jan 3, 2025
Amusing bug. Fixes external #4736.

PiperOrigin-RevId: 711440699
copybara-service bot pushed a commit that referenced this issue Jan 3, 2025
Amusing bug. Fixes external #4736.

PiperOrigin-RevId: 711698771
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