byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

StackOverflowError during exception reporting

Open raner opened this issue 1 year ago • 1 comments

I just ran into a scenario where instead of seeing an exception that informs me of an issue with my bytecode generation, I see a StackOverflowError instead. The repeating part of the overflow is:

	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:1973)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfTypeVariable$Symbolic.accept(TypeDescription.java:5931)
	at net.bytebuddy.description.method.MethodDescription$Latent.getReturnType(MethodDescription.java:1489)
	at net.bytebuddy.description.method.MethodDescription$AbstractBase.toSafeString(MethodDescription.java:1052)
	at net.bytebuddy.description.TypeVariableSource$AbstractBase.findExpectedVariable(TypeVariableSource.java:174)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:2062)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:1973)

Clearly, there is something wrong on my part with regards to a missing symbolic type variable (still investigating what exactly), but I would have expected to see the IllegalArgumentException thrown by findExpectedVariable:

https://github.com/raphw/byte-buddy/blob/0a91a85d741c1e0b5d8eeef98f7842e5cbc1496e/byte-buddy-dep/src/main/java/net/bytebuddy/description/TypeVariableSource.java#L171C1-L178C1

Instead, the call to toSafeString() leads to an endless recursion. This has been observed with Byte Buddy 1.14.12.

raner avatar Apr 21 '24 00:04 raner

This is indeed overseen. The return type is also possibly an unresolved recursive. Will be fixed in the next release.

raphw avatar Apr 22 '24 21:04 raphw