eclipse-jdtls / eclipse.jdt.ls

Java language server
1.75k stars 390 forks source link

can't build project after latest jdt core updates (ArrayBinding cannot be cast to class ReferenceBinding) #3199

Open mfussenegger opened 2 months ago

mfussenegger commented 2 months ago

Using the current master (5c5f2e3e1c8d164172f2016eaa290137b17ee037), eclipse.jdt.ls is no longer able to load and build crate. Update: Workaround was merged: https://github.com/crate/crate/pull/16416, see https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/3199#issuecomment-2254181280 for a reproduction.

The logs show the following errors:

org.eclipse.core.internal.resources.ResourceException: Errors occurred during the build.
    at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:611)
    at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:483)
    at org.eclipse.jdt.ls.core.internal.handlers.BuildWorkspaceHandler.buildWorkspace(BuildWorkspaceHandler.java:67)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$28(JDTLanguageServer.java:989)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$61(JDTLanguageServer.java:1224)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
Contains: Errors running builder 'Java Builder' on project 'crate-server'.
java.lang.RuntimeException: Internal Error compiling /crate-server/src/test/java/io/crate/execution/engine/sort/OrderingByPositionTest.java
    at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:151)
    at java.base/java.lang.Thread.run(Thread.java:1570)
Caused by: java.lang.ClassCastException
java.lang.ClassCastException: class org.eclipse.jdt.internal.compiler.lookup.ArrayBinding cannot be cast to class org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ArrayBinding and org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @4eb6283e)
    at org.eclipse.jdt.internal.compiler.lookup.CaptureBinding.downwardsProjection(CaptureBinding.java:547)
    at org.eclipse.jdt.internal.compiler.lookup.CaptureBinding.downwardsProjection(CaptureBinding.java:1)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.upwardsProjection(ParameterizedTypeBinding.java:530)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.upwardsProjection(ParameterizedTypeBinding.java:1)
    at org.eclipse.jdt.internal.compiler.lookup.TypeBinding.upwardsProjection(TypeBinding.java:325)
    at org.eclipse.jdt.internal.compiler.lookup.BoundSet.deriveTypeArgumentConstraints(BoundSet.java:974)
    at org.eclipse.jdt.internal.compiler.lookup.BoundSet.incorporate(BoundSet.java:630)
    at org.eclipse.jdt.internal.compiler.lookup.BoundSet.incorporate(BoundSet.java:511)
    at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.resolve(InferenceContext18.java:1215)
    at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.solve(InferenceContext18.java:1052)
    at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.solve(InferenceContext18.java:1035)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod18(ParameterizedGenericMethodBinding.java:256)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod(ParameterizedGenericMethodBinding.java:92)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:842)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:799)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod0(Scope.java:1753)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1655)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:3145)
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1138)
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:914)
    at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:402)
    at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:258)
    at org.eclipse.jdt.internal.compiler.ast.Statement.resolveWithBindings(Statement.java:498)
    at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveStatements(ASTNode.java:725)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:713)
    at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:409)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:611)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1514)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1643)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:666)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1326)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:791)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateASTCached(ASTParser.java:1248)
    at org.eclipse.jdt.core.dom.ASTParser.lambda$0(ASTParser.java:1126)
    at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5762)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1126)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:874)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:294)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:286)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:199)
    at org.eclipse.jdt.ls.core.internal.handlers.DocumentHighlightHandler.documentHighlight(DocumentHighlightHandler.java:56)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$12(JDTLanguageServer.java:725)
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)

I suspect this is caused by one of the recent jdt core/target platform updates, but I cannot compile the older commits of eclipse.jdt.ls so I can't tell for sure. (dependencies disappeared(?)).

After deleting OrderingByPositionTest the project builds again.

I can try to extract a smaller reproduction if necessary, but I suspected that with the full project, the file that causes the error and the full stacktrace someone more familiar with the code might already have an idea what's causing the problem.

mfussenegger commented 2 months ago

Looks like https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3200 fixed it

mfussenegger commented 2 months ago

Actually, it looks like this is still broken (tested with https://github.com/eclipse-jdtls/eclipse.jdt.ls/commit/b363a8617022e3d7d60b64b6669c823fdda1e1f9). In my earlier test I forgot to switch back to the development version of eclipse.jdt.ls

mfussenegger commented 1 month ago

Narrowed it down to:

    @Test
    public void test_compile_error() throws Exception {
        Comparator<Object[]> ordering = CompoundOrdering.of(Arrays.asList(
            OrderingByPosition.arrayOrdering(1, false, false),
            OrderingByPosition.arrayOrdering(0, false, false)
        ));
    }

Which triggers the error. The code compiles with javac. It also compiles with the eclipse compiler if changing to:

    @Test
    public void test_ok() throws Exception {
        var orderings = Arrays.asList(
            OrderingByPosition.arrayOrdering(1, false, false),
            OrderingByPosition.arrayOrdering(0, false, false)
        );
        Comparator<Object[]> ordering = CompoundOrdering.of(orderings);
    }

https://github.com/mfussenegger/eclipse-compiler-bug contains the full trimmed reproduction. (Currently the problematic code is commented out: https://github.com/mfussenegger/eclipse-compiler-bug/blob/0b1c7bf3fef26d6879b54fdf3ea94432186e8148/src/test/java/foo/CompoundOrderingTest.java#L20)