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 within decompiled classes may fail to resolve #3083

Open
rgrunber opened this issue Mar 4, 2024 · 0 comments
Open

References within decompiled classes may fail to resolve #3083

rgrunber opened this issue Mar 4, 2024 · 0 comments

Comments

@rgrunber
Copy link
Contributor

rgrunber commented Mar 4, 2024

Looking at the work in eclipse-jdt/eclipse.jdt.core#2074 got me thinking that we might see some improvement in corner cases for references given that we use that helper method when looking up references in classfiles that must be decompiled (eg. using a JDK with no sources).

image

{
  message: "[Trace - 17:44:22] Sending request 'textDocument/references - (870)'.",
  level: 'info',
  timestamp: '2024-03-04 17:44:22.659'
}
{
  message: 'Params: {\n' +
    '    "textDocument": {\n' +
    '        "uri": "jdt://contents/java.base/java.net/URI.class?%3Dfoo_caeb84bf%2F%5C%2Fusr%5C%2Flib%5C%2Fjvm%5C%2Fjava-11-openjdk-11.0.22.0.7-1.fc39.x86_64%5C%2Flib%5C%2Fjrt-fs.jar%60java.base%3D%2Fjavadoc_location%3D%2Fhttps%3A%5C%2F%5C%2Fdocs.oracle.com%5C%2Fen%5C%2Fjava%5C%2Fjavase%5C%2F11%5C%2Fdocs%5C%2Fapi%5C%2F%3D%2F%3Cjava.net%28URI.class"\n' +
    '    },\n' +
    '    "position": {\n' +
    '        "line": 1208,\n' +
    '        "character": 25\n' +
    '    },\n' +
    '    "context": {\n' +
    '        "includeDeclaration": true\n' +
    '    }\n' +
    '}\n' +
    '\n',
  level: 'info',
  timestamp: '2024-03-04 17:44:22.659'
}

...
...
...

{
  message: "[Trace - 17:44:45] Received response 'textDocument/references - (870)' in 22976ms. Request failed: Internal error. (-32603).",
  level: 'info',
  timestamp: '2024-03-04 17:44:45.635'
}
{
  message: 'Error data: "java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke \\"org.eclipse.jdt.core.dom.CompilationUnit.accept(org.eclipse.jdt.core.dom.ASTVisitor)\\" because \\"this.fRoot\\" is null\\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.NullPointerException: Cannot invoke \\"org.eclipse.jdt.core.dom.CompilationUnit.accept(org.eclipse.jdt.core.dom.ASTVisitor)\\" because \\"this.fRoot\\" is null\\n\\tat org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder.performSearch(OccurrencesFinder.java:105)\\n\\tat org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder.getOccurrences(OccurrencesFinder.java:111)\\n\\tat org.eclipse.jdt.ls.core.internal.JDTUtils.searchDecompiledSources(JDTUtils.java:1774)\\n\\tat org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler$1.acceptSearchMatch(ReferencesHandler.java:201)\\n\\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.report(MatchLocator.java:2205)\\n\\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportBinaryMemberDeclaration(MatchLocator.java:2506)\\n\\tat org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:276)\\n\\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:2002)\\n\\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1369)\\n\\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1406)\\n\\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1549)\\n\\tat org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:134)\\n\\tat org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:253)\\n\\tat org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:599)\\n\\tat org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:669)\\n\\tat org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler.search(ReferencesHandler.java:182)\\n\\tat org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler.findReferences(ReferencesHandler.java:85)\\n\\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$10(JDTLanguageServer.java:722)\\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-04 17:44:45.637'
}
{
  message: '[Error - 17:44:45] Request textDocument/references failed.',
  level: 'info',
  timestamp: '2024-03-04 17:44:45.640'
}
{
  message: '  Message: Internal error.\n' +
    '  Code: -32603 \n' +
    'java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.CompilationUnit.accept(org.eclipse.jdt.core.dom.ASTVisitor)" because "this.fRoot" is null\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.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.CompilationUnit.accept(org.eclipse.jdt.core.dom.ASTVisitor)" because "this.fRoot" is null\n' +
    '\tat org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder.performSearch(OccurrencesFinder.java:105)\n' +
    '\tat org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder.getOccurrences(OccurrencesFinder.java:111)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.JDTUtils.searchDecompiledSources(JDTUtils.java:1774)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler$1.acceptSearchMatch(ReferencesHandler.java:201)\n' +
    '\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.report(MatchLocator.java:2205)\n' +
    '\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportBinaryMemberDeclaration(MatchLocator.java:2506)\n' +
    '\tat org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:276)\n' +
    '\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:2002)\n' +
    '\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1369)\n' +
    '\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1406)\n' +
    '\tat org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1549)\n' +
    '\tat org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:134)\n' +
    '\tat org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:253)\n' +
    '\tat org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:599)\n' +
    '\tat org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:669)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler.search(ReferencesHandler.java:182)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.handlers.ReferencesHandler.findReferences(ReferencesHandler.java:85)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$10(JDTLanguageServer.java:722)\n' +
    '\tat org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)\n' +
    '\t... 7 more\n',
  level: 'info',
  timestamp: '2024-03-04 17:44:45.641'
}

On top of that, the part of the code that visits method invocations seems strange :

public boolean visit(MethodInvocation node) {
if (element.getElementName().equals(node.getName().getIdentifier())) {
if (element instanceof IMethod method) {
String[] parameters = method.getParameterTypes();
List<?> astParameters = node.typeArguments();
if (parameters.length == astParameters.size()) {
int size = astParameters.size();
String[] astParameterTypes = new String[size];
Iterator<?> iterator = astParameters.iterator();
for (int i = 0; i < size; i++) {
Type parameter = (Type) iterator.next();
astParameterTypes[i] = getSignature(parameter);
}
if (equals(parameters, astParameterTypes)) {
nodes[0] = node;
return false;
}
}
}
}

We're taking the method parameter types from an IMethod, but we're comparing them to the type arguments from the method invocation node, which is something completely different (it's for parameterized types). This seems like a typo. I think what was meant was to take the parameters() of the method invocation node and resolve the type binding of each individual parameter, and then compare it to the parameter types. Either way, this part of the code could use a closer look.

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

No branches or pull requests

1 participant