mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-20 01:25:31 +01:00
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:
parent
7e40d13947
commit
d24fbc9f55
@ -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());
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user