|
44 | 44 | import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
45 | 45 | import org.springframework.beans.factory.support.RegisteredBean;
|
46 | 46 | import org.springframework.beans.factory.support.RootBeanDefinition;
|
| 47 | +import org.springframework.core.OverridingClassLoader; |
47 | 48 | import org.springframework.lang.Nullable;
|
48 | 49 |
|
49 | 50 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
|
@@ -134,6 +135,14 @@ void shouldProcessRecursiveGenericsWithoutInfiniteRecursion(Class<?> beanClass)
|
134 | 135 | .withMemberCategory(MemberCategory.DECLARED_FIELDS)).accepts(this.generationContext.getRuntimeHints());
|
135 | 136 | }
|
136 | 137 |
|
| 138 | + @Test // gh-33940 |
| 139 | + void shouldSkipConstraintWithMissingDependency() throws Exception { |
| 140 | + FilteringClassLoader classLoader = new FilteringClassLoader(getClass().getClassLoader()); |
| 141 | + Class<?> beanClass = classLoader.loadClass(ConstraintWithMissingDependency.class.getName()); |
| 142 | + process(beanClass); |
| 143 | + assertThat(this.generationContext.getRuntimeHints().reflection().typeHints()).isEmpty(); |
| 144 | + } |
| 145 | + |
137 | 146 | private void process(Class<?> beanClass) {
|
138 | 147 | BeanRegistrationAotContribution contribution = createContribution(beanClass);
|
139 | 148 | if (contribution != null) {
|
@@ -269,4 +278,31 @@ static class BeanWithRecursiveOptional {
|
269 | 278 | Optional<BeanWithRecursiveOptional> optional;
|
270 | 279 | }
|
271 | 280 |
|
| 281 | + static class ConstraintWithMissingDependency { |
| 282 | + |
| 283 | + private final Filtered filtered = new Filtered(); |
| 284 | + } |
| 285 | + |
| 286 | + static class Filtered {} |
| 287 | + |
| 288 | + static class FilteringClassLoader extends OverridingClassLoader { |
| 289 | + |
| 290 | + FilteringClassLoader(ClassLoader parent) { |
| 291 | + super(parent); |
| 292 | + } |
| 293 | + |
| 294 | + @Override |
| 295 | + protected boolean isEligibleForOverriding(String className) { |
| 296 | + return className.startsWith(BeanValidationBeanRegistrationAotProcessorTests.class.getName()); |
| 297 | + } |
| 298 | + |
| 299 | + @Override |
| 300 | + protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException { |
| 301 | + if (name.contains("Filtered")) { |
| 302 | + throw new NoClassDefFoundError(name); |
| 303 | + } |
| 304 | + return super.loadClassForOverriding(name); |
| 305 | + } |
| 306 | + } |
| 307 | + |
272 | 308 | }
|
0 commit comments