Skip to content

Commit 5d1078a

Browse files
authored
ProxyAutoBean should be able to handle List<Integer> in Java 21 (#9905)
Fix request factory tests fails with errors under java 21 due to added apis to the List class `getLast`, `getFirst`, `isEmpty` which are causing ProxyAutoBean treats the list as a traversable object. Fix #9902
1 parent f05b257 commit 5d1078a

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

user/src/com/google/web/bindery/autobean/vm/impl/ProxyAutoBean.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,38 @@ private static Map<String, Data> calculateData(Class<?> beanType) {
112112
if (toReturn == null) {
113113
Map<String, Data> getters = new HashMap<String, Data>();
114114
List<Method> setters = new ArrayList<Method>();
115-
for (Method method : beanType.getMethods()) {
116-
if (BeanMethod.GET.matches(method)) {
117-
// match methods on their name for now, to find the most specific
118-
// override
119-
String name = method.getName();
120-
121-
Type genericReturnType = TypeUtils.resolveGenerics(beanType, method.getGenericReturnType());
122-
Class<?> returnType = TypeUtils.ensureBaseType(genericReturnType);
123-
124-
Data data = getters.get(name);
125-
if (data == null || data.type.isAssignableFrom(returnType)) {
126-
// no getter seen yet for the property, or a less specific one
127-
PropertyType propertyType;
128-
if (TypeUtils.isValueType(returnType)) {
129-
propertyType = PropertyType.VALUE;
130-
} else if (Collection.class.isAssignableFrom(returnType)) {
131-
propertyType = PropertyType.COLLECTION;
132-
} else if (Map.class.isAssignableFrom(returnType)) {
133-
propertyType = PropertyType.MAP;
134-
} else {
135-
propertyType = PropertyType.REFERENCE;
115+
if (!(Collection.class.isAssignableFrom(beanType)
116+
|| Map.class.isAssignableFrom(beanType))) {
117+
for (Method method : beanType.getMethods()) {
118+
if (BeanMethod.GET.matches(method)) {
119+
// match methods on their name for now, to find the most specific
120+
// override
121+
String name = method.getName();
122+
123+
Type genericReturnType = TypeUtils.resolveGenerics(beanType,
124+
method.getGenericReturnType());
125+
Class<?> returnType = TypeUtils.ensureBaseType(genericReturnType);
126+
127+
Data data = getters.get(name);
128+
if (data == null || data.type.isAssignableFrom(returnType)) {
129+
// no getter seen yet for the property, or a less specific one
130+
PropertyType propertyType;
131+
if (TypeUtils.isValueType(returnType)) {
132+
propertyType = PropertyType.VALUE;
133+
} else if (Collection.class.isAssignableFrom(returnType)) {
134+
propertyType = PropertyType.COLLECTION;
135+
} else if (Map.class.isAssignableFrom(returnType)) {
136+
propertyType = PropertyType.MAP;
137+
} else {
138+
propertyType = PropertyType.REFERENCE;
139+
}
140+
data = new Data(method, genericReturnType, returnType, propertyType);
141+
142+
getters.put(name, data);
136143
}
137-
data = new Data(method, genericReturnType, returnType, propertyType);
138-
139-
getters.put(name, data);
144+
} else if (BeanMethod.SET.matches(method) || BeanMethod.SET_BUILDER.matches(method)) {
145+
setters.add(method);
140146
}
141-
} else if (BeanMethod.SET.matches(method) || BeanMethod.SET_BUILDER.matches(method)) {
142-
setters.add(method);
143147
}
144148
}
145149

0 commit comments

Comments
 (0)