6464 * @author Sebastien Deleuze
6565 * @since 6.0
6666 */
67- @ SuppressWarnings ("unchecked" )
6867class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
6968
7069 private static final boolean jpaPresent = ClassUtils .isPresent ("jakarta.persistence.Entity" ,
7170 PersistenceManagedTypesBeanRegistrationAotProcessor .class .getClassLoader ());
7271
73- @ Nullable
7472 @ Override
73+ @ Nullable
7574 public BeanRegistrationAotContribution processAheadOfTime (RegisteredBean registeredBean ) {
7675 if (jpaPresent ) {
7776 if (PersistenceManagedTypes .class .isAssignableFrom (registeredBean .getBeanClass ())) {
@@ -82,12 +81,12 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe
8281 return null ;
8382 }
8483
84+
8585 private static final class JpaManagedTypesBeanRegistrationCodeFragments extends BeanRegistrationCodeFragmentsDecorator {
8686
8787 private static final List <Class <? extends Annotation >> CALLBACK_TYPES = List .of (PreUpdate .class ,
8888 PostUpdate .class , PrePersist .class , PostPersist .class , PreRemove .class , PostRemove .class , PostLoad .class );
8989
90-
9190 private static final ParameterizedTypeName LIST_OF_STRINGS_TYPE = ParameterizedTypeName .get (List .class , String .class );
9291
9392 private final RegisteredBean registeredBean ;
@@ -102,8 +101,8 @@ private JpaManagedTypesBeanRegistrationCodeFragments(BeanRegistrationCodeFragmen
102101
103102 @ Override
104103 public CodeBlock generateInstanceSupplierCode (GenerationContext generationContext ,
105- BeanRegistrationCode beanRegistrationCode ,
106- boolean allowDirectSupplierShortcut ) {
104+ BeanRegistrationCode beanRegistrationCode , boolean allowDirectSupplierShortcut ) {
105+
107106 PersistenceManagedTypes persistenceManagedTypes = this .registeredBean .getBeanFactory ()
108107 .getBean (this .registeredBean .getBeanName (), PersistenceManagedTypes .class );
109108 contributeHints (generationContext .getRuntimeHints (),
@@ -140,7 +139,7 @@ private void contributeHints(RuntimeHints hints, @Nullable ClassLoader classLoad
140139 contributeHibernateHints (hints , classLoader , managedClass );
141140 }
142141 catch (ClassNotFoundException ex ) {
143- throw new IllegalArgumentException ("Failed to instantiate the managed class: " + managedClassName , ex );
142+ throw new IllegalArgumentException ("Failed to instantiate JPA managed class: " + managedClassName , ex );
144143 }
145144 }
146145 }
@@ -149,7 +148,8 @@ private void contributeEntityListenersHints(RuntimeHints hints, Class<?> managed
149148 EntityListeners entityListeners = AnnotationUtils .findAnnotation (managedClass , EntityListeners .class );
150149 if (entityListeners != null ) {
151150 for (Class <?> entityListener : entityListeners .value ()) {
152- hints .reflection ().registerType (entityListener , MemberCategory .INVOKE_DECLARED_CONSTRUCTORS , MemberCategory .INVOKE_PUBLIC_METHODS );
151+ hints .reflection ().registerType (entityListener ,
152+ MemberCategory .INVOKE_DECLARED_CONSTRUCTORS , MemberCategory .INVOKE_PUBLIC_METHODS );
153153 }
154154 }
155155 }
@@ -169,12 +169,14 @@ private void contributeConverterHints(RuntimeHints hints, Class<?> managedClass)
169169 }
170170 Convert convertClassAnnotation = AnnotationUtils .findAnnotation (managedClass , Convert .class );
171171 if (convertClassAnnotation != null ) {
172- reflectionHints .registerType (convertClassAnnotation .converter (), MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
172+ reflectionHints .registerType (convertClassAnnotation .converter (),
173+ MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
173174 }
174175 ReflectionUtils .doWithFields (managedClass , field -> {
175176 Convert convertFieldAnnotation = AnnotationUtils .findAnnotation (field , Convert .class );
176177 if (convertFieldAnnotation != null && convertFieldAnnotation .converter () != void .class ) {
177- reflectionHints .registerType (convertFieldAnnotation .converter (), MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
178+ reflectionHints .registerType (convertFieldAnnotation .converter (),
179+ MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
178180 }
179181 });
180182 }
@@ -186,11 +188,11 @@ private void contributeCallbackHints(RuntimeHints hints, Class<?> managedClass)
186188 method -> CALLBACK_TYPES .stream ().anyMatch (method ::isAnnotationPresent ));
187189 }
188190
189- @ SuppressWarnings ("unchecked" )
190191 private void contributeHibernateHints (RuntimeHints hints , @ Nullable ClassLoader classLoader , Class <?> managedClass ) {
191192 ReflectionHints reflection = hints .reflection ();
192193
193- Class <? extends Annotation > embeddableInstantiatorClass = loadClass ("org.hibernate.annotations.EmbeddableInstantiator" , classLoader );
194+ Class <? extends Annotation > embeddableInstantiatorClass =
195+ loadClass ("org.hibernate.annotations.EmbeddableInstantiator" , classLoader );
194196 if (embeddableInstantiatorClass != null ) {
195197 registerForReflection (reflection ,
196198 AnnotationUtils .findAnnotation (managedClass , embeddableInstantiatorClass ), "value" );
@@ -204,23 +206,26 @@ private void contributeHibernateHints(RuntimeHints hints, @Nullable ClassLoader
204206 AnnotationUtils .findAnnotation (method , embeddableInstantiatorClass ), "value" ));
205207 }
206208
207- Class <? extends Annotation > valueGenerationTypeClass = loadClass ("org.hibernate.annotations.ValueGenerationType" , classLoader );
209+ Class <? extends Annotation > valueGenerationTypeClass =
210+ loadClass ("org.hibernate.annotations.ValueGenerationType" , classLoader );
208211 if (valueGenerationTypeClass != null ) {
209212 ReflectionUtils .doWithFields (managedClass , field -> registerForReflection (reflection ,
210213 AnnotationUtils .findAnnotation (field , valueGenerationTypeClass ), "generatedBy" ));
211214 ReflectionUtils .doWithMethods (managedClass , method -> registerForReflection (reflection ,
212215 AnnotationUtils .findAnnotation (method , valueGenerationTypeClass ), "generatedBy" ));
213216 }
214217
215- Class <? extends Annotation > idGeneratorTypeClass = loadClass ("org.hibernate.annotations.IdGeneratorType" , classLoader );
218+ Class <? extends Annotation > idGeneratorTypeClass =
219+ loadClass ("org.hibernate.annotations.IdGeneratorType" , classLoader );
216220 if (idGeneratorTypeClass != null ) {
217221 ReflectionUtils .doWithFields (managedClass , field -> registerForReflection (reflection ,
218222 AnnotationUtils .findAnnotation (field , idGeneratorTypeClass ), "value" ));
219223 ReflectionUtils .doWithMethods (managedClass , method -> registerForReflection (reflection ,
220224 AnnotationUtils .findAnnotation (method , idGeneratorTypeClass ), "value" ));
221225 }
222226
223- Class <? extends Annotation > attributeBinderTypeClass = loadClass ("org.hibernate.annotations.AttributeBinderType" , classLoader );
227+ Class <? extends Annotation > attributeBinderTypeClass =
228+ loadClass ("org.hibernate.annotations.AttributeBinderType" , classLoader );
224229 if (attributeBinderTypeClass != null ) {
225230 ReflectionUtils .doWithFields (managedClass , field -> registerForReflection (reflection ,
226231 AnnotationUtils .findAnnotation (field , attributeBinderTypeClass ), "binder" ));
@@ -229,6 +234,7 @@ private void contributeHibernateHints(RuntimeHints hints, @Nullable ClassLoader
229234 }
230235 }
231236
237+ @ SuppressWarnings ("unchecked" )
232238 @ Nullable
233239 private static Class <? extends Annotation > loadClass (String className , @ Nullable ClassLoader classLoader ) {
234240 try {
@@ -239,13 +245,14 @@ private static Class<? extends Annotation> loadClass(String className, @Nullable
239245 }
240246 }
241247
242- @ SuppressWarnings ("NullAway" )
248+ @ SuppressWarnings ("NullAway" ) // Not-null assertion performed in ReflectionHints.registerType
243249 private void registerForReflection (ReflectionHints reflection , @ Nullable Annotation annotation , String attribute ) {
244250 if (annotation == null ) {
245251 return ;
246252 }
247- Class <?> embeddableInstantiatorClass = (Class <?>) AnnotationUtils .getAnnotationAttributes (annotation ).get (attribute );
248- reflection .registerType (embeddableInstantiatorClass , MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
253+ Class <?> type = (Class <?>) AnnotationUtils .getAnnotationAttributes (annotation ).get (attribute );
254+ reflection .registerType (type , MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
249255 }
250256 }
257+
251258}
0 commit comments