-
Notifications
You must be signed in to change notification settings - Fork 375
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
Java 21 cause StackOverFlowException in TypeUtils#resolveGenerics due to List implementing SequencedCollection with new function getFirst() being treated as a getter #9855
Comments
This can be trivially reproduced running this line on Java 21:
Unsurprisingly it also happens with any class implementing |
With this snipped it is even reproducible on JDKs before 21 (tested on 18, but should be the same on pretty much every JDK). import com.google.web.bindery.autobean.vm.impl.ProxyAutoBean;
public class GwtStackOverFlowException {
interface MyType<T> {
T getType();
}
public static void main(String[] args) {
new ProxyAutoBean<>(null, MyType.class, null);
}
} |
I have opened PR #9858 which fixed the issue for me. |
Thanks ! |
While the issue (#9855) is related to JDK21 and its new `getFirst` and `getLast` methods in the `List`/`SequencedCollection` interfaces, the current behaviour can in theory cause problems on JDK versions before 21 too. With this fix the `TypeUtils#resolveGenerics` method falls back to `TypeUtils#ensureBaseType` (already used method-level type variables) when a type variable is used in the same class where it has been defined. This class for example, currently causes a `StackOverflowError`. With this PR the error is avoided, and the `T` is resolved as `java.lang.Object`: ```java class BrokenClass<T> { public T getT() { return null; } } ``` Fixes #9855
GWT version: 2.8.2
Browser (with version): Firefox (does not matter)
Operating System: Linux (does not matter)
Description
When testing my existing program using older GWT 2.8.2 under Java 21, I had the surprise to see it crash on a
StackOverFlowException
when connecting to it with a web browser. See stack trace at the end of this message.TypeUtils#resolveGenerics
is called recursively indefinitely, causing the StackOverflow.Since it never happened on previous Java versions, I compared in a debugger between Java 17 and Java 21.
The problematic
TypeUtils#resolveGenerics(Class<?> containingType, Type type)
call is originating fromProxyAutoBean#calculateData
with this line:Type genericReturnType = TypeUtils.resolveGenerics(beanType, method.getGenericReturnType());
The invocation that cause the stack overflow is with
beanType
beingClass<java.util.List>
, method's name is "getFirst" (the newly added function from theSequencedCollection
interface inherited byList
) andmethod.getGenericReturnType()
being of typeTypeVariableImpl
which is causing this block inTypeUtils#resolveGenerics
to be called recursively indefinitely:Note that prior to Java 21, my program never triggered the execution of this block code above.
It is specifically triggered by the new
getFirst/getLast
methods ofList
in Java 21.So there is a bug with this code (not working properly or not guarded for infinite recursion) or the calling function
ProxyAutoBean#calculateData
should excludegetFirst()
andgetLast()
introduced in the SequencedCollection interface inherited byList
and other collections.The code in com/google/web/bindery/autobean/vm/impl has not been modified in 9 years, so I bet this issue still exist in current GWT version.
Steps to reproduce
Run a GWT program under Java 21 that results in
ProxyAutoBean#calculateData
being invoked withClass<java.util.list>
as parameter.////////////////////
The text was updated successfully, but these errors were encountered: