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

ArrayIndexOutOfBoundsException on finding references #297

Open
nya3jp opened this issue Dec 15, 2024 · 0 comments · May be fixed by #298
Open

ArrayIndexOutOfBoundsException on finding references #297

nya3jp opened this issue Dec 15, 2024 · 0 comments · May be fixed by #298

Comments

@nya3jp
Copy link

nya3jp commented Dec 15, 2024

Finding references of types occasionally causes ArrayIndexOutOfBoundsException. This is a small repro case:

public class VarTypeReferences {
    private static class Foo {
        public void foo() {}
    }

    public void run() {
        var foo = new Foo();
        foo.foo();
    }
}

Finding references of Foo causes ArrayIndexOutOfBoundsException:

java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 12
        at jdk.compiler/com.sun.tools.javac.util.Position$LineTabMapImpl.getColumnNumber(Position.java:266)
        at jdk.compiler/com.sun.tools.javac.util.Position$LineMapImpl.getColumnNumber(Position.java:236)
        at jdk.compiler/com.sun.tools.javac.util.Position$LineTabMapImpl.getColumnNumber(Position.java:253)
        at org.javacs.FindHelper.location(FindHelper.java:146)
        at org.javacs.FindHelper.location(FindHelper.java:133)
        at org.javacs.navigation.ReferenceProvider.findReferences(ReferenceProvider.java:78)
        at org.javacs.navigation.ReferenceProvider.find(ReferenceProvider.java:32)
        at org.javacs.JavaLanguageServer.findReferences(JavaLanguageServer.java:320)
        at org.javacs.FindReferencesTest.items(FindReferencesTest.java:21)
        at org.javacs.FindReferencesTest.varTypeReferences(FindReferencesTest.java:62)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:377)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:284)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:248)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:167)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:456)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:169)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:595)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:581)
nya3jp added a commit to nya3jp/java-language-server that referenced this issue Dec 15, 2024
It is possible that the matching type does not appear directly in the
AST, e.g. when a type is referenced with "var". This patch fixes the
issue by skipping such matches.

Fixes georgewfraser#297.
@nya3jp nya3jp linked a pull request Dec 15, 2024 that will close this issue
nya3jp added a commit to nya3jp/java-language-server that referenced this issue Dec 18, 2024
It is possible that the matching type does not appear directly in the
AST, e.g. when a type is referenced with "var". This patch fixes the
issue by skipping such matches.

Fixes georgewfraser#297.
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

Successfully merging a pull request may close this issue.

1 participant