Skip to content

Commit ef23d8c

Browse files
authored
Update NativeImageUtil method name and expose new getter (#4063)
1 parent 0910dc4 commit ef23d8c

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/main/java/com/fasterxml/jackson/databind/util/NativeImageUtil.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,39 @@
99
* @since 2.14
1010
*/
1111
public class NativeImageUtil {
12-
private static final boolean RUNNING_IN_SVM;
13-
14-
static {
15-
RUNNING_IN_SVM = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
16-
}
12+
13+
private static final boolean RUNNING_IN_SVM = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
1714

1815
private NativeImageUtil() {
1916
}
2017

2118
/**
22-
* Check whether we're running in substratevm native image runtime mode.
23-
* This check cannot be a constant, because
19+
* Check whether we're running in SubstrateVM native image and also in "runtime" mode.
20+
* The "runtime" check cannot be a constant, because
2421
* the static initializer may run early during build time
2522
*<p>
26-
* NOTE: {@code public} since 2.16 (before that, {@code private}).
23+
* As optimization, {@link #RUNNING_IN_SVM} is used to short-circuit on normal JVMs.
2724
*/
28-
public static boolean isRunningInNativeImage() {
25+
private static boolean isInNativeImageAndIsAtRuntime() {
2926
return RUNNING_IN_SVM && "runtime".equals(System.getProperty("org.graalvm.nativeimage.imagecode"));
3027
}
3128

29+
/**
30+
* Checks whether we're running in SubstrateVM native image <b>only by the presence</b> of
31+
* {@code "org.graalvm.nativeimage.imagecode"} system property, regardless of its value (buildtime or runtime).
32+
* We are irrespective of the build or runtime phase, because native-image can initialize static initializers at build time.
33+
*<p>
34+
* @since 2.16
35+
*/
36+
public static boolean isInNativeImage() {
37+
return RUNNING_IN_SVM;
38+
}
39+
3240
/**
3341
* Check whether the given error is a substratevm UnsupportedFeatureError
3442
*/
3543
public static boolean isUnsupportedFeatureError(Throwable e) {
36-
if (!isRunningInNativeImage()) {
44+
if (!isInNativeImageAndIsAtRuntime()) {
3745
return false;
3846
}
3947
if (e instanceof InvocationTargetException) {
@@ -47,7 +55,7 @@ public static boolean isUnsupportedFeatureError(Throwable e) {
4755
* members visible in reflection).
4856
*/
4957
public static boolean needsReflectionConfiguration(Class<?> cl) {
50-
if (!isRunningInNativeImage()) {
58+
if (!isInNativeImageAndIsAtRuntime()) {
5159
return false;
5260
}
5361
// records list their fields but not other members

0 commit comments

Comments
 (0)