RequestFactory tests fails under java 21 due to changes in the List API
vegegoku opened this issue · comments
GWT version: 2.11
Browser (with version):
Operating System:Ubuntu
Description
While building GWT using java 21 RequestFactorySuite
tests failed with 58 errors
Testcase: testFetchEntityWithRelation took 0.007 sec
Caused an ERROR
Exception caught: Cannot invoke "com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverse(com.google.web.bindery.autobean.shared.AutoBeanVisitor, com.google.web.bindery.autobean.shared.impl.AbstractAutoBean$OneShotContext)" because "bean" is null
com.google.web.bindery.event.shared.UmbrellaException: Exception caught: Cannot invoke "com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverse(com.google.web.bindery.autobean.shared.AutoBeanVisitor, com.google.web.bindery.autobean.shared.impl.AbstractAutoBean$OneShotContext)" because "bean" is null
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:413)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5.onTransportSuccess(AbstractRequestContext.java:1160)
at com.google.web.bindery.requestfactory.server.testing.InProcessRequestTransport.send(InProcessRequestTransport.java:64)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.doFire(AbstractRequestContext.java:1154)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.fire(AbstractRequestContext.java:595)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.fire(AbstractRequest.java:56)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.fire(AbstractRequest.java:61)
at com.google.web.bindery.requestfactory.gwt.client.RequestFactoryTest.testFetchEntityWithRelation(RequestFactoryTest.java:856)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:419)
at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:247)
Caused by: java.lang.NullPointerException: Cannot invoke "com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverse(com.google.web.bindery.autobean.shared.AutoBeanVisitor, com.google.web.bindery.autobean.shared.impl.AbstractAutoBean$OneShotContext)" because "bean" is null
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:382)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:166)
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:358)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:166)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:101)
at com.google.web.bindery.requestfactory.shared.impl.ProxySerializerImpl.serialize(ProxySerializerImpl.java:118)
at com.google.web.bindery.requestfactory.gwt.client.RequestFactoryTestBase.checkSerialization(RequestFactoryTestBase.java:181)
at com.google.web.bindery.requestfactory.gwt.client.RequestFactoryTest$23.onSuccess(RequestFactoryTest.java:860)
at com.google.web.bindery.requestfactory.gwt.client.RequestFactoryTest$23.onSuccess(RequestFactoryTest.java:857)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.onSuccess(AbstractRequest.java:131)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:380)
tracing the issue alongside @niloc132 we found the reason of the failure is that in java 21 a new methods are added to the list class getFirst
, getLast
, isEmpty
, and in the ProxyAutoBean when tries to build the propertData for a list field is collect those methods as getters, this result in the field to be recognized as a nested entity that need to be traversed for its internal properties and is being processed as a reference instead of a value causing the above exception.
full logs are attached
logs.txt
Steps to reproduce
cd into gwt user folder and run the command
ant test.nongwt -Dgwt.nongwt.testcase.includes='**/RequestFactoryJreSuite.class'
Known workarounds
adding a simple check to skip Collection classes from the propertyData will make this pass.
private static Map<String, Data> calculateData(Class<?> beanType) {
Map<String, Data> toReturn;
synchronized (cache) {
toReturn = cache.get(beanType);
if (toReturn == null) {
Map<String, Data> getters = new HashMap<String, Data>();
List<Method> setters = new ArrayList<Method>();
if (!Collection.class.isAssignableFrom(beanType)) { // <------ here
for (Method method : beanType.getMethods()) {
if (BeanMethod.GET.matches(method)) {
// match methods on their name for now, to find the most specific
// override
String name = method.getName();
Type genericReturnType = TypeUtils.resolveGenerics(beanType, method.getGenericReturnType());
Class<?> returnType = TypeUtils.ensureBaseType(genericReturnType);
Data data = getters.get(name);
...