eclipse-jdt / eclipse-jdt/eclipse.jdt.core

JavaAllCompletionProposalComputer IfStatement cannot be cast to class LambdaExpression

Open
#1,163 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

I originally filed this ticket as eclipse-platform/eclipse.platform.ui#837.

I ran into a problem where Eclipse was incorrectly indicating that an exception should have a `catch` even though I was using sneaky throws. I filed that problem as #1162.

However when I was trying to find a workaround to that problem, I started to add some `catch`es just to try to get the error to go away so I could determine how best to deal with it. Starting with the code in #1162, I did something like this:

```java
try (final InputStream inputStream = new BufferedInputStream(newInputStream(file))) {
document = documentBuilder.parse(inputStream);
} catch(final IOException ioEx) {
} catch(final SAXException saxException) {
}
```

When I put my cursor after `ioEx` and hit `Ctrl+Space` to autocomplete to (I had hoped) `ioException`, Eclipse threw a fit. (See error below.) Unfortunately I have not yet been able to reproduce the problem. I'm filing this ticket in hopes that looking at the stack trace can give you a clue to where the problem is, or at least put in additional logging to detect the cause in the future. When you're investigating #1162 you might keep your eyes open for something that might cause the problem, as they might (or might not) be related.

```
eclipse.buildId=4.28.0.20230608-1200
java.version=17.0.7
java.vendor=Eclipse Adoptium
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

org.eclipse.jdt.ui
Warning
Mon Jun 19 10:10:40 PDT 2023
The 'org.eclipse.jdt.ui.JavaAllCompletionProposalComputer' proposal computer from the 'org.eclipse.jdt.ui' plug-in did not complete normally. The extension has thrown a runtime exception.

java.lang.ClassCastException: class org.eclipse.jdt.internal.compiler.ast.IfStatement cannot be cast to class org.eclipse.jdt.internal.compiler.ast.LambdaExpression (org.eclipse.jdt.internal.compiler.ast.IfStatement and org.eclipse.jdt.internal.compiler.ast.LambdaExpression are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @189e986f)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeLambdaExpression(Parser.java:9156)
at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.consumeLambdaExpression(CompletionParser.java:3747)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:7951)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13180)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:2131)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1971)
at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.parseBlockStatements(CompletionParser.java:5845)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:349)
at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:312)
at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:2335)
at org.eclipse.jdt.internal.core.Openable.codeComplete(Openable.java:136)
at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:367)
at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:357)
at org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer.internalComputeCompletionProposals(JavaCompletionProposalComputer.java:256)
at org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer.computeCompletionProposals(JavaCompletionProposalComputer.java:218)
at org.eclipse.jdt.internal.ui.text.java.JavaTypeCompletionProposalComputer.computeCompletionProposals(JavaTypeCompletionProposalComputer.java:65)
at org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:348)
at org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:340)
at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:333)
at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:289)
at org.eclipse.jface.text.contentassist.AsyncCompletionProposalPopup.lambda$10(AsyncCompletionProposalPopup.java:378)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.jface.text.contentassist.AsyncCompletionProposalPopup.lambda$9(AsyncCompletionProposalPopup.java:377)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.