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
This commit is contained in:
parent
2112e86795
commit
64c6a97130
|
@ -34,6 +34,7 @@ class PreComputeFieldFeature implements Feature {
|
||||||
|
|
||||||
private static Pattern[] patterns = {
|
private static Pattern[] patterns = {
|
||||||
Pattern.compile(Pattern.quote("org.springframework.core.NativeDetector#imageCode")),
|
Pattern.compile(Pattern.quote("org.springframework.core.NativeDetector#imageCode")),
|
||||||
|
Pattern.compile(Pattern.quote("org.springframework.cglib.core.AbstractClassGenerator#imageCode")),
|
||||||
Pattern.compile(Pattern.quote("org.springframework.") + ".*#.*Present"),
|
Pattern.compile(Pattern.quote("org.springframework.") + ".*#.*Present"),
|
||||||
Pattern.compile(Pattern.quote("org.springframework.") + ".*#.*PRESENT"),
|
Pattern.compile(Pattern.quote("org.springframework.") + ".*#.*PRESENT"),
|
||||||
Pattern.compile(Pattern.quote("reactor.") + ".*#.*Available"),
|
Pattern.compile(Pattern.quote("reactor.") + ".*#.*Available"),
|
||||||
|
|
|
@ -43,6 +43,9 @@ abstract public class AbstractClassGenerator<T> implements ClassGenerator {
|
||||||
private static final boolean DEFAULT_USE_CACHE =
|
private static final boolean DEFAULT_USE_CACHE =
|
||||||
Boolean.parseBoolean(System.getProperty("cglib.useCache", "true"));
|
Boolean.parseBoolean(System.getProperty("cglib.useCache", "true"));
|
||||||
|
|
||||||
|
// See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java
|
||||||
|
private static final boolean imageCode = (System.getProperty("org.graalvm.nativeimage.imagecode") != null);
|
||||||
|
|
||||||
|
|
||||||
private GeneratorStrategy strategy = DefaultGeneratorStrategy.INSTANCE;
|
private GeneratorStrategy strategy = DefaultGeneratorStrategy.INSTANCE;
|
||||||
|
|
||||||
|
@ -359,6 +362,12 @@ abstract public class AbstractClassGenerator<T> implements ClassGenerator {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// SPRING PATCH BEGIN
|
||||||
|
if (imageCode) {
|
||||||
|
throw new UnsupportedOperationException("CGLIB runtime enhancement not supported on native image. " +
|
||||||
|
"Make sure to include a pre-generated class on the classpath instead: " + getClassName());
|
||||||
|
}
|
||||||
|
// SPRING PATCH END
|
||||||
byte[] b = strategy.generate(this);
|
byte[] b = strategy.generate(this);
|
||||||
String className = ClassNameReader.getClassName(new ClassReader(b));
|
String className = ClassNameReader.getClassName(new ClassReader(b));
|
||||||
ProtectionDomain protectionDomain = getProtectionDomain();
|
ProtectionDomain protectionDomain = getProtectionDomain();
|
||||||
|
|
Loading…
Reference in New Issue