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

References computation issue with Unnamed classes #3069

Closed
fbricon opened this issue Feb 21, 2024 · 5 comments · Fixed by #3077
Closed

References computation issue with Unnamed classes #3069

fbricon opened this issue Feb 21, 2024 · 5 comments · Fixed by #3077
Assignees

Comments

@fbricon
Copy link
Contributor

fbricon commented Feb 21, 2024

Using the latest vscode-java release (using jdt.ls 1.33.0), with this code snippet, the greeting reference codelens shows 0 reference, when on the 1st line, and 1 reference, when moved down to another line:

String greeting = "Hello, World!";

void main() {
    System.out.println(greeting);
}

Feb-21-2024 10-27-14

It's actually worse than that. The reference seems to be pointing at the String keyword:
Screenshot 2024-02-21 at 10 41 35
Screenshot 2024-02-21 at 10 42 15
Screenshot 2024-02-21 at 10 42 26

@fbricon fbricon added the bug label Feb 21, 2024
@fbricon
Copy link
Contributor Author

fbricon commented Feb 21, 2024

@datho7561 can you maybe take a look?

@datho7561
Copy link
Contributor

Sure. It might take me a while to get to, I have quite a bit on my plate.

@snjeza
Copy link
Contributor

snjeza commented Feb 23, 2024

The issue can't be reproduced in Eclipse

fbricon5

datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Feb 29, 2024
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Feb 29, 2024
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Mar 1, 2024
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Mar 1, 2024
datho7561 added a commit to datho7561/eclipse.jdt.ls that referenced this issue Mar 1, 2024
@rgrunber rgrunber added this to the Mid March 2024 milestone Mar 5, 2024
@rgrunber
Copy link
Contributor

rgrunber commented Mar 5, 2024

Managed to find another (not related to this change, but similar style) issue while playing with this :

!ENTRY org.eclipse.jdt.ls.core 4 2 2024-03-05 13:53:25.854
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ls.core".
!STACK 0
java.lang.ClassCastException: class org.eclipse.jdt.core.dom.UnnamedClass cannot be cast to class org.eclipse.jdt.core.dom.TypeDeclaration (org.eclipse.jdt.core.dom.UnnamedClass and org.eclipse.jdt.core.dom.TypeDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @4eef705f)
	at org.eclipse.jdt.ls.core.internal.handlers.PasteEventHandler.handleFilePasteEvent(PasteEventHandler.java:371)
	at org.eclipse.jdt.ls.core.internal.JDTDelegateCommandHandler.executeCommand(JDTDelegateCommandHandler.java:217)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:616)
	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)

When you paste a snippet of code (default is ctrl+shift+v) with the file explorer in focus (and some folder opened), and if the snippet would parse into an UnnamedClass node (like the example Fred gives at #3069 (comment) ). CC'ing @hopehadfield .

@rgrunber
Copy link
Contributor

rgrunber commented Mar 5, 2024

Oh, and another separate issue (through the code action request) :

{
  message: "[Trace - 14:03:58] Received response 'textDocument/codeAction - (9)' in 275ms. Request failed: Internal error. (-32603).",
  level: 'info',
  timestamp: '2024-03-05 14:03:58.222'
}
{
  message: 'Error data: "java.util.concurrent.CompletionException: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.UnnamedClass cannot be cast to class org.eclipse.jdt.core.dom.AbstractTypeDeclaration (org.eclipse.jdt.core.dom.UnnamedClass and org.eclipse.jdt.core.dom.AbstractTypeDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @3b0962d9)\\n\\tat java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)\\n\\tat java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)\\n\\tat java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)\\n\\tat java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)\\n\\tat java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)\\n\\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)\\n\\tat java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)\\n\\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)\\n\\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)\\nCaused by: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.UnnamedClass cannot be cast to class org.eclipse.jdt.core.dom.AbstractTypeDeclaration (org.eclipse.jdt.core.dom.UnnamedClass and org.eclipse.jdt.core.dom.AbstractTypeDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @3b0962d9)\\n\\tat org.eclipse.jdt.internal.core.SortElementsOperation$1.visit(SortElementsOperation.java:196)\\n\\tat org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:250)\\n\\tat org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3309)\\n\\tat org.eclipse.jdt.internal.core.SortElementsOperation.sortCompilationUnit(SortElementsOperation.java:190)\\n\\tat org.eclipse.jdt.internal.core.SortElementsOperation.calculateEdit(SortElementsOperation.java:136)\\n\\tat org.eclipse.jdt.core.util.CompilationUnitSorter.sort(CompilationUnitSorter.java:451)\\n\\tat org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSortMembersProposal(SourceAssistProcessor.java:648)\\n\\tat org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSortMembersAction(SourceAssistProcessor.java:683)\\n\\tat org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSourceActionCommands(SourceAssistProcessor.java:254)\\n\\tat org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:223)\\n\\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:765)\\n\\tat org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)\\n\\t... 7 more\\n"\n' +
    '\n',
  level: 'info',
  timestamp: '2024-03-05 14:03:58.223'
}
{
  message: '[Error - 14:03:58] Request textDocument/codeAction failed.',
  level: 'info',
  timestamp: '2024-03-05 14:03:58.224'
}
{
  message: '  Message: Internal error.\n' +
    '  Code: -32603 \n' +
    'java.util.concurrent.CompletionException: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.UnnamedClass cannot be cast to class org.eclipse.jdt.core.dom.AbstractTypeDeclaration (org.eclipse.jdt.core.dom.UnnamedClass and org.eclipse.jdt.core.dom.AbstractTypeDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @3b0962d9)\n' +
    '\tat java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)\n' +
    '\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)\n' +
    'Caused by: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.UnnamedClass cannot be cast to class org.eclipse.jdt.core.dom.AbstractTypeDeclaration (org.eclipse.jdt.core.dom.UnnamedClass and org.eclipse.jdt.core.dom.AbstractTypeDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @3b0962d9)\n' +
    '\tat org.eclipse.jdt.internal.core.SortElementsOperation$1.visit(SortElementsOperation.java:196)\n' +
    '\tat org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:250)\n' +
    '\tat org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3309)\n' +
    '\tat org.eclipse.jdt.internal.core.SortElementsOperation.sortCompilationUnit(SortElementsOperation.java:190)\n' +
    '\tat org.eclipse.jdt.internal.core.SortElementsOperation.calculateEdit(SortElementsOperation.java:136)\n' +
    '\tat org.eclipse.jdt.core.util.CompilationUnitSorter.sort(CompilationUnitSorter.java:451)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSortMembersProposal(SourceAssistProcessor.java:648)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSortMembersAction(SourceAssistProcessor.java:683)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSourceActionCommands(SourceAssistProcessor.java:254)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:223)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:765)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)\n' +
    '\t... 7 more\n',
  level: 'info',
  timestamp: '2024-03-05 14:03:58.224'
}

Just click around the simple example and you'll see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants