You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NullPointerException if passing an anonymous class to ReflectionsHint#registerType #29774
If you (accidentally in this case) pass an anonymous class to registerType it fails with
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "org.springframework.aot.hint.AbstractTypeReference.getCanonicalName()" is null
at org.springframework.aot.hint.AbstractTypeReference.equals(AbstractTypeReference.java:93)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1214)
at org.springframework.aot.hint.ReflectionHints.registerType(ReflectionHints.java:85)
at org.springframework.aot.hint.ReflectionHints.registerType(ReflectionHints.java:98)
at org.springframework.aot.hint.ReflectionHints.registerType(ReflectionHints.java:120)
This happened to us when trying to use
for (var c : reflections.getSubTypesOf(Converter.class)) {
reflection.registerType(c, memberCategories);
}
Well for some reason it seems like adding com.vaadin.flow.data.converter.Converter$1 works fine but when it gets to com.vaadin.flow.data.converter.Converter$2 then it fails
changed the title [-]NullPointerException if passing an anonymous class to ReflectionsHints.registerType[/-][+]`NullPointerException` if passing an anonymous class to `ReflectionsHint#registerType`[/+]on Feb 24, 2023
For this one, I think I would assert that the class passed to ReflectionTypeReference#of is not null and has a non null canonical name, in order to have a more meaningful exception earlier. That would also be consistent with the kind of checks done in SimpleTypeReference. cc @bclozel
@Artur- That will not change the fact you need to avoid passing such class to ReflectionHints in your code, I don't think silently ignoring such class-based type reference would be a reasonable behavior.
@Artur- I implemented a solution that should fix the NullPointerException you see, keep a lenient behavior at ReflectionHints#registerType level, and assert that the class and related canonical name are not null at ReflectionTypeReference#of level.
We have a planned release tomorrow, so when the build is finished, would be great if you could test Spring Framework 6.0.6-SNAPSHOT to confirm it works as expected for you.
Activity
Artur- commentedon Jan 5, 2023
Well for some reason it seems like adding
com.vaadin.flow.data.converter.Converter$1works fine but when it gets tocom.vaadin.flow.data.converter.Converter$2then it failsfix: Do not register anonymous classes with Spring aot
fix: Do not register anonymous classes with Spring aot
fix: Do not register anonymous classes with Spring aot (#15633)
[-]NullPointerException if passing an anonymous class to ReflectionsHints.registerType[/-][+]`NullPointerException` if passing an anonymous class to `ReflectionsHint#registerType`[/+]sdeleuze commentedon Feb 24, 2023
For this one, I think I would assert that the class passed to
ReflectionTypeReference#ofis not null and has a non null canonical name, in order to have a more meaningful exception earlier. That would also be consistent with the kind of checks done inSimpleTypeReference. cc @bclozel@Artur- That will not change the fact you need to avoid passing such class to
ReflectionHintsin your code, I don't think silently ignoring such class-based type reference would be a reasonable behavior.sdeleuze commentedon Mar 1, 2023
@Artur- I implemented a solution that should fix the
NullPointerExceptionyou see, keep a lenient behavior atReflectionHints#registerTypelevel, and assert that the class and related canonical name are notnullatReflectionTypeReference#oflevel.We have a planned release tomorrow, so when the build is finished, would be great if you could test Spring Framework
6.0.6-SNAPSHOTto confirm it works as expected for you.Artur- commentedon Mar 2, 2023
I tried 6.0.6-SNAPSHOT but run into something that is already in 6.0.5
Need to figure that one out first..
Artur- commentedon Mar 2, 2023
Ok, Spring Boot vs Spring Framework conflict. With Spring Boot 3.0.3 + Spring Framework 6.0.6-SNAPSHOT everything works as expected, thanks!