InheritanceVertex#isLibraryMethod stack overflows
Describe the bug
Running illegal name removal on certain samples throws StackOverflowError.
Specifically, the issue is in: if (parent.isLibraryMethod(name, desc))
in the following block:
public boolean isLibraryMethod(@Nonnull String name, @Nonnull String desc) {
// Check against this definition
if (!isPrimary && hasMethod(name, desc))
return true;
// Check parents.
// If we extend a class with a library definition then it should be considered a library method.
for (InheritanceVertex parent : getParents())
if (parent.isLibraryMethod(name, desc))
return true;
// No library definition found, so its safe to rename.
return false;
}
To Reproduce
Steps to reproduce the behavior:
- Open this sample in Recaf
- Run illegal name removal
- Refer to logs for stack overflow
Exception
If applicable, add the exception/stacktrace.
01:17:24.485 [MappingGenerator/JavaFX Application Thread] ERROR: Failed to generate mappings
java.util.concurrent.CompletionException: java.lang.StackOverflowError
at java.base/java.util.concurrent.CompletableFuture.wrapInCompletionException(CompletableFuture.java:323)
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:359)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:364)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1791)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1781)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1450)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2019)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
Caused by: java.lang.StackOverflowError
at software.coley.recaf.services.inheritance.InheritanceVertex.isLibraryMethod(InheritanceVertex.java:200)
at software.coley.recaf.services.inheritance.InheritanceVertex.isLibraryMethod(InheritanceVertex.java:206)
at software.coley.recaf.services.inheritance.InheritanceVertex.isLibraryMethod(InheritanceVertex.java:206)
at software.coley.recaf.services.inheritance.InheritanceVertex.isLibraryMethod(InheritanceVertex.java:206)
...
Screenshots
N/A
I added a depth parameter to see how far down we get in the sample when doing illegal name analysis, but it didn't even hit a depth level of 10 for me.
I can see the recursive approach being an issue in some cases but this doesn't appear to reproduce on my machine.
Definitely reproducible on my end, at least, on commit 5110e53cc0959c295479997e5ff349b9b9c9bc8e.
Odd that you can't repro it - any suggestions for debugging it on my end if you can't?
Just clone the repo, and follow https://recaf.coley.software/dev/arch/running.html for running it. Use the debug run mode in IntelliJ and set a breakpoint anywhere in that stacktrace and you should be able to inspect the state.
This shouldn't loop unless there's some cycle occuring in the graph.
f5b00a980199a204c688c5365c601ecfcfda67f4 - Reworked some inheritance graph logic to avoid recursion but still never could repro