Remove final modifier to fix illegal reflective access warning

Java 9 runtimes report warnings for reflective access on JRE
classes (in this case Field.modifiers). Future versions of Java
may deny the access completely.

Since we access our own code here, we could just remove the final modifier.
With it's current visibility (of private) it's unlikely that it will be
modified from somewhere else except our Settings class.
This commit is contained in:
games647 2018-03-13 16:20:02 +01:00
parent 7e40d13947
commit d24fbc9f55
No known key found for this signature in database
GPG key ID: BFC68C8708713A88
2 changed files with 3 additions and 7 deletions

View file

@ -1338,11 +1338,7 @@ public class Settings implements net.ess3.api.ISettings {
try {
Field field = NumberUtil.class.getDeclaredField("PRETTY_FORMAT");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, currencyFormat);
modifiersField.setAccessible(false);
field.setAccessible(false);
} catch (NoSuchFieldException | IllegalAccessException e) {
ess.getLogger().severe("Failed to apply custom currency format: " + e.getMessage());

View file

@ -13,12 +13,12 @@ import static com.earth2me.essentials.I18n.tl;
public class NumberUtil {
static DecimalFormat twoDPlaces = new DecimalFormat("#,###.##");
static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
private static DecimalFormat twoDPlaces = new DecimalFormat("#,###.##");
private static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
// This field is likely to be modified in com.earth2me.essentials.Settings when loading currency format.
// This ensures that we can supply a constant formatting.
static final NumberFormat PRETTY_FORMAT = NumberFormat.getInstance(Locale.US);
private static NumberFormat PRETTY_FORMAT = NumberFormat.getInstance(Locale.US);
static {
twoDPlaces.setRoundingMode(RoundingMode.HALF_UP);