From 116655bc4661059b2d16fe703427f62ab285699b Mon Sep 17 00:00:00 2001 From: Vojin Jovanovic Date: Tue, 8 Jul 2025 18:32:52 +0200 Subject: [PATCH] Include resource bundles with -H:Preserve= --- .../BundleContentSubstitutedLocalizationSupport.java | 2 +- .../src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java | 6 +++++- .../oracle/svm/hosted/image/PreserveOptionsSupport.java | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/BundleContentSubstitutedLocalizationSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/BundleContentSubstitutedLocalizationSupport.java index a09f0d1199d8..1b17af59bffc 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/BundleContentSubstitutedLocalizationSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/BundleContentSubstitutedLocalizationSupport.java @@ -133,7 +133,7 @@ private static boolean isBundleSupported(ResourceBundle bundle) { } @Platforms(Platform.HOSTED_ONLY.class) - private static boolean isBundleSupported(Class bundleClass) { + public static boolean isBundleSupported(Class bundleClass) { return ListResourceBundle.class.isAssignableFrom(bundleClass) || OpenListResourceBundle.class.isAssignableFrom(bundleClass); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java index c8dff0897002..96589b8d5f37 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassLoaderSupportImpl.java @@ -266,7 +266,11 @@ public List getResourceBundle(String bundleSpec, Locale locale) } else { Modules.addOpensToAllUnnamed(module, packageName); } - resourceBundles.add(ResourceBundle.getBundle(bundleName, locale, module)); + try { + resourceBundles.add(ResourceBundle.getBundle(bundleName, locale, module)); + } catch (InternalError e) { + // ignore, nothing we can do + } } return resourceBundles; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/PreserveOptionsSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/PreserveOptionsSupport.java index e84dab52ebf1..6795e1f14a64 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/PreserveOptionsSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/PreserveOptionsSupport.java @@ -42,10 +42,12 @@ import org.graalvm.nativeimage.impl.RuntimeJNIAccessSupport; import org.graalvm.nativeimage.impl.RuntimeProxyCreationSupport; import org.graalvm.nativeimage.impl.RuntimeReflectionSupport; +import org.graalvm.nativeimage.impl.RuntimeResourceSupport; import org.graalvm.nativeimage.impl.RuntimeSerializationSupport; import com.oracle.graal.pointsto.ClassInclusionPolicy; import com.oracle.svm.core.SubstrateOptions; +import com.oracle.svm.core.jdk.localization.BundleContentSubstitutedLocalizationSupport; import com.oracle.svm.core.option.AccumulatingLocatableMultiOptionValue; import com.oracle.svm.core.option.LocatableMultiOptionValue; import com.oracle.svm.core.option.SubstrateOptionsParser; @@ -149,6 +151,7 @@ public static void registerPreservedClasses(NativeImageClassLoaderSupport classL .toList(); final RuntimeReflectionSupport reflection = ImageSingletons.lookup(RuntimeReflectionSupport.class); + final RuntimeResourceSupport resources = RuntimeResourceSupport.singleton(); final RuntimeProxyCreationSupport proxy = ImageSingletons.lookup(RuntimeProxyCreationSupport.class); final RuntimeSerializationSupport serialization = RuntimeSerializationSupport.singleton(); final ConfigurationCondition always = ConfigurationCondition.alwaysTrue(); @@ -205,6 +208,11 @@ public static void registerPreservedClasses(NativeImageClassLoaderSupport classL // if we register as unsafe allocated earlier there are build-time // initialization errors reflection.register(always, !(c.isArray() || c.isInterface() || c.isPrimitive() || Modifier.isAbstract(c.getModifiers())), c); + + /* Register resource bundles */ + if (BundleContentSubstitutedLocalizationSupport.isBundleSupported(c)) { + resources.addResourceBundles(always, c.getTypeName()); + } }); /*