Skip to content

Commit 64c6a97

Browse files
committed
Make GeneratorStrategy.generate unreachable on native
This change provides also more information to the user about the missing generated class when that happens. Closes gh-29521
1 parent 2112e86 commit 64c6a97

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

spring-core/src/main/java/org/springframework/aot/nativex/feature/PreComputeFieldFeature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class PreComputeFieldFeature implements Feature {
3434

3535
private static Pattern[] patterns = {
3636
Pattern.compile(Pattern.quote("org.springframework.core.NativeDetector#imageCode")),
37+
Pattern.compile(Pattern.quote("org.springframework.cglib.core.AbstractClassGenerator#imageCode")),
3738
Pattern.compile(Pattern.quote("org.springframework.") + ".*#.*Present"),
3839
Pattern.compile(Pattern.quote("org.springframework.") + ".*#.*PRESENT"),
3940
Pattern.compile(Pattern.quote("reactor.") + ".*#.*Available"),

spring-core/src/main/java/org/springframework/cglib/core/AbstractClassGenerator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ abstract public class AbstractClassGenerator<T> implements ClassGenerator {
4343
private static final boolean DEFAULT_USE_CACHE =
4444
Boolean.parseBoolean(System.getProperty("cglib.useCache", "true"));
4545

46+
// See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java
47+
private static final boolean imageCode = (System.getProperty("org.graalvm.nativeimage.imagecode") != null);
48+
4649

4750
private GeneratorStrategy strategy = DefaultGeneratorStrategy.INSTANCE;
4851

@@ -359,6 +362,12 @@ protected Class generate(ClassLoaderData data) {
359362
// ignore
360363
}
361364
}
365+
// SPRING PATCH BEGIN
366+
if (imageCode) {
367+
throw new UnsupportedOperationException("CGLIB runtime enhancement not supported on native image. " +
368+
"Make sure to include a pre-generated class on the classpath instead: " + getClassName());
369+
}
370+
// SPRING PATCH END
362371
byte[] b = strategy.generate(this);
363372
String className = ClassNameReader.getClassName(new ClassReader(b));
364373
ProtectionDomain protectionDomain = getProtectionDomain();

0 commit comments

Comments
 (0)