From d24fbc9f55976f0767a04d247e19de4f1a1479ca Mon Sep 17 00:00:00 2001 From: games647 Date: Tue, 13 Mar 2018 16:20:02 +0100 Subject: [PATCH] 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. --- Essentials/src/com/earth2me/essentials/Settings.java | 4 ---- .../src/com/earth2me/essentials/utils/NumberUtil.java | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 5f283f6b0..fbca35f22 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -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()); diff --git a/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java b/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java index c4459f34c..3d2a5cef5 100644 --- a/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java @@ -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);