Skip to content

Commit

Permalink
[GR-51331] Backport to 23.1 : Fix failure when no resource bundle nul…
Browse files Browse the repository at this point in the history
…lary constructor is present

PullRequest: graal/16602
  • Loading branch information
TheTaha-Alamine committed Feb 21, 2024
2 parents c5ba9e9 + adcecfa commit 68da470
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package com.oracle.svm.core.jdk.localization;

import java.lang.reflect.Constructor;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -209,8 +210,25 @@ public static Locale parseLocaleFromTag(String tag) {
}

public void prepareClassResourceBundle(@SuppressWarnings("unused") String basename, Class<?> bundleClass) {
RuntimeReflection.register(bundleClass);
RuntimeReflection.registerForReflectiveInstantiation(bundleClass);
registerNullaryConstructor(bundleClass);
onClassBundlePrepared(bundleClass);
}

/**
* Bundle lookup code tries to reflectively access the default constructor of candidate bundle
* classes, and then tries to invoke them if they exist. We therefore need to register the
* default constructor as invoked if it exists, and as queried if it doesn't, which we know will
* result in a negative query.
*/
private static void registerNullaryConstructor(Class<?> bundleClass) {
RuntimeReflection.register(bundleClass);
Constructor<?> nullaryConstructor;
try {
nullaryConstructor = bundleClass.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
RuntimeReflection.registerConstructorLookup(bundleClass);
return;
}
RuntimeReflection.register(nullaryConstructor);
}
}

0 comments on commit 68da470

Please sign in to comment.