8344252: SM cleanup in java.util classes

Reviewed-by: naoto, smarks
This commit is contained in:
Roger Riggs 2024-11-15 20:29:14 +00:00
parent 59ffac84d3
commit c5b6ed8ca0
13 changed files with 160 additions and 330 deletions

View file

@ -32,8 +32,6 @@ import java.io.FileReader;
import java.io.InputStream;
import java.io.IOException;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.concurrent.ConcurrentHashMap;
@ -213,63 +211,57 @@ public final class Currency implements Serializable {
initStatic();
}
@SuppressWarnings("removal")
private static void initStatic() {
AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Void run() {
try {
try (InputStream in = getClass().getResourceAsStream("/java/util/currency.data")) {
if (in == null) {
throw new InternalError("Currency data not found");
}
DataInputStream dis = new DataInputStream(new BufferedInputStream(in));
if (dis.readInt() != MAGIC_NUMBER) {
throw new InternalError("Currency data is possibly corrupted");
}
formatVersion = dis.readInt();
if (formatVersion != VALID_FORMAT_VERSION) {
throw new InternalError("Currency data format is incorrect");
}
dataVersion = dis.readInt();
mainTable = readIntArray(dis, A_TO_Z * A_TO_Z);
int scCount = dis.readInt();
specialCasesList = readSpecialCases(dis, scCount);
int ocCount = dis.readInt();
otherCurrenciesList = readOtherCurrencies(dis, ocCount);
}
} catch (IOException e) {
throw new InternalError(e);
}
// look for the properties file for overrides
String propsFile = System.getProperty("java.util.currency.data");
if (propsFile == null) {
propsFile = StaticProperty.javaHome() + File.separator + "lib" +
File.separator + "currency.properties";
try {
try (InputStream in = Currency.class.getResourceAsStream("/java/util/currency.data")) {
if (in == null) {
throw new InternalError("Currency data not found");
}
try {
File propFile = new File(propsFile);
if (propFile.exists()) {
Properties props = new Properties();
try (FileReader fr = new FileReader(propFile)) {
props.load(fr);
}
Pattern propertiesPattern =
Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" +
"(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" +
"\\d{2}:\\d{2})?");
List<CurrencyProperty> currencyEntries
= getValidCurrencyData(props, propertiesPattern);
currencyEntries.forEach(Currency::replaceCurrencyData);
}
} catch (IOException e) {
CurrencyProperty.info("currency.properties is ignored"
+ " because of an IOException", e);
DataInputStream dis = new DataInputStream(new BufferedInputStream(in));
if (dis.readInt() != MAGIC_NUMBER) {
throw new InternalError("Currency data is possibly corrupted");
}
return null;
formatVersion = dis.readInt();
if (formatVersion != VALID_FORMAT_VERSION) {
throw new InternalError("Currency data format is incorrect");
}
dataVersion = dis.readInt();
mainTable = readIntArray(dis, A_TO_Z * A_TO_Z);
int scCount = dis.readInt();
specialCasesList = readSpecialCases(dis, scCount);
int ocCount = dis.readInt();
otherCurrenciesList = readOtherCurrencies(dis, ocCount);
}
});
} catch (IOException e) {
throw new InternalError(e);
}
// look for the properties file for overrides
String propsFile = System.getProperty("java.util.currency.data");
if (propsFile == null) {
propsFile = StaticProperty.javaHome() + File.separator + "lib" +
File.separator + "currency.properties";
}
try {
File propFile = new File(propsFile);
if (propFile.exists()) {
Properties props = new Properties();
try (FileReader fr = new FileReader(propFile)) {
props.load(fr);
}
Pattern propertiesPattern =
Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" +
"(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" +
"\\d{2}:\\d{2})?");
List<CurrencyProperty> currencyEntries
= getValidCurrencyData(props, propertiesPattern);
currencyEntries.forEach(Currency::replaceCurrencyData);
}
} catch (IOException e) {
CurrencyProperty.info("currency.properties is ignored"
+ " because of an IOException", e);
}
}
/**