Recaf icon indicating copy to clipboard operation
Recaf copied to clipboard

InheritanceVertex#isLibraryMethod stack overflows

Open DoubleHypercube opened this issue 5 months ago • 4 comments

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:

  1. Open this sample in Recaf
  2. Run illegal name removal
  3. 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

DoubleHypercube avatar Jun 13 '26 13:06 DoubleHypercube

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.

Image

I can see the recursive approach being an issue in some cases but this doesn't appear to reproduce on my machine.

Col-E avatar Jun 14 '26 06:06 Col-E

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?

DoubleHypercube avatar Jun 18 '26 03:06 DoubleHypercube

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.

Col-E avatar Jun 18 '26 04:06 Col-E

f5b00a980199a204c688c5365c601ecfcfda67f4 - Reworked some inheritance graph logic to avoid recursion but still never could repro

Col-E avatar Jul 08 '26 04:07 Col-E