|
1 | 1 | /* |
2 | | - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
40 | 40 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
41 | 41 | import org.springframework.beans.factory.support.RegisteredBean; |
42 | 42 | import org.springframework.beans.factory.support.RootBeanDefinition; |
| 43 | +import org.springframework.core.OverridingClassLoader; |
43 | 44 | import org.springframework.lang.Nullable; |
44 | 45 |
|
45 | 46 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; |
@@ -121,6 +122,14 @@ void shouldProcessTransitiveGenericTypeLevelConstraint() { |
121 | 122 | .withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(this.generationContext.getRuntimeHints()); |
122 | 123 | } |
123 | 124 |
|
| 125 | +@Test // gh-33940 |
| 126 | +void shouldSkipConstraintWithMissingDependency() throws Exception { |
| 127 | +FilteringClassLoader classLoader = new FilteringClassLoader(getClass().getClassLoader()); |
| 128 | +Class<?> beanClass = classLoader.loadClass(ConstraintWithMissingDependency.class.getName()); |
| 129 | +process(beanClass); |
| 130 | +assertThat(this.generationContext.getRuntimeHints().reflection().typeHints()).isEmpty(); |
| 131 | +} |
| 132 | + |
124 | 133 | private void process(Class<?> beanClass) { |
125 | 134 | BeanRegistrationAotContribution contribution = createContribution(beanClass); |
126 | 135 | if (contribution != null) { |
@@ -244,4 +253,31 @@ public void setExclude(List<Exclude> exclude) { |
244 | 253 | } |
245 | 254 | } |
246 | 255 |
|
| 256 | +static class ConstraintWithMissingDependency { |
| 257 | + |
| 258 | +private final Filtered filtered = new Filtered(); |
| 259 | +} |
| 260 | + |
| 261 | +static class Filtered {} |
| 262 | + |
| 263 | +static class FilteringClassLoader extends OverridingClassLoader { |
| 264 | + |
| 265 | +FilteringClassLoader(ClassLoader parent) { |
| 266 | +super(parent); |
| 267 | +} |
| 268 | + |
| 269 | +@Override |
| 270 | +protected boolean isEligibleForOverriding(String className) { |
| 271 | +return className.startsWith(BeanValidationBeanRegistrationAotProcessorTests.class.getName()); |
| 272 | +} |
| 273 | + |
| 274 | +@Override |
| 275 | +protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException { |
| 276 | +if (name.contains("Filtered")) { |
| 277 | +throw new NoClassDefFoundError(name); |
| 278 | +} |
| 279 | +return super.loadClassForOverriding(name); |
| 280 | +} |
| 281 | +} |
| 282 | + |
247 | 283 | } |
0 commit comments