Skip to content

Commit 5ac330b

Browse files
author
Roger Riggs
committed
8344039: Remove security manager dependency in java.time
Reviewed-by: naoto, mullan, lancea
1 parent 1eb38c8 commit 5ac330b

File tree

2 files changed

+47
-78
lines changed

2 files changed

+47
-78
lines changed

src/java.base/share/classes/java/time/chrono/HijrahChronology.java

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -59,18 +59,14 @@
5959

6060
import static java.time.temporal.ChronoField.EPOCH_DAY;
6161

62-
import java.io.FilePermission;
6362
import java.io.IOException;
6463
import java.io.InputStream;
6564
import java.io.InvalidObjectException;
6665
import java.io.ObjectInputStream;
6766
import java.io.Serializable;
68-
import java.io.UncheckedIOException;
6967
import java.nio.file.Files;
7068
import java.nio.file.Path;
7169
import java.nio.file.StandardOpenOption;
72-
import java.security.AccessController;
73-
import java.security.PrivilegedAction;
7470
import java.time.Clock;
7571
import java.time.DateTimeException;
7672
import java.time.Instant;
@@ -88,6 +84,7 @@
8884
import java.util.Properties;
8985
import java.util.stream.Stream;
9086

87+
import jdk.internal.util.StaticProperty;
9188
import sun.util.logging.PlatformLogger;
9289

9390
/**
@@ -291,10 +288,7 @@ public final class HijrahChronology extends AbstractChronology implements Serial
291288
AbstractChronology.registerChrono(INSTANCE, "islamic");
292289

293290
// custom config chronologies
294-
@SuppressWarnings("removal")
295-
String javaHome = AccessController.doPrivileged((PrivilegedAction<String>)
296-
() -> System.getProperty("java.home"));
297-
CONF_PATH = Path.of(javaHome, "conf", "chronology");
291+
CONF_PATH = Path.of(StaticProperty.javaHome(), "conf", "chronology");
298292
registerCustomChrono();
299293
}
300294

@@ -824,19 +818,9 @@ private int epochMonthLength(int epochMonth) {
824818
*/
825819
private static Properties readConfigProperties(final String chronologyId, final String calendarType) throws Exception {
826820
String resourceName = RESOURCE_PREFIX + chronologyId + "_" + calendarType + RESOURCE_SUFFIX;
827-
PrivilegedAction<InputStream> getResourceAction = calendarType.equals("islamic-umalqura") ?
828-
() -> HijrahChronology.class.getResourceAsStream(resourceName) :
829-
() -> {
830-
try {
831-
return Files.newInputStream(CONF_PATH.resolve(resourceName),
832-
StandardOpenOption.READ);
833-
} catch (IOException e) {
834-
throw new UncheckedIOException(e);
835-
}
836-
};
837-
FilePermission perm1 = new FilePermission("<<ALL FILES>>", "read");
838-
RuntimePermission perm2 = new RuntimePermission("accessSystemModules");
839-
try (@SuppressWarnings("removal") InputStream is = AccessController.doPrivileged(getResourceAction, null, perm1, perm2)) {
821+
try (InputStream is = calendarType.equals("islamic-umalqura")
822+
? HijrahChronology.class.getResourceAsStream(resourceName)
823+
: Files.newInputStream(CONF_PATH.resolve(resourceName), StandardOpenOption.READ)) {
840824
if (is == null) {
841825
throw new RuntimeException("Hijrah calendar resource not found: " + resourceName);
842826
}
@@ -1031,38 +1015,32 @@ private int[] parseYMD(String string) {
10311015
* Look for Hijrah chronology variant properties files in
10321016
* <JAVA_HOME>/conf/chronology directory. Then register its chronology, if any.
10331017
*/
1034-
@SuppressWarnings("removal")
10351018
private static void registerCustomChrono() {
1036-
AccessController.doPrivileged(
1037-
(PrivilegedAction<Void>)() -> {
1038-
if (Files.isDirectory(CONF_PATH)) {
1039-
try (Stream<Path> stream = Files.list(CONF_PATH)) {
1040-
stream.map(p -> p.getFileName().toString())
1041-
.filter(fn -> fn.matches("hijrah-config-[^\\.]+\\.properties"))
1042-
.map(fn -> fn.replaceAll("(hijrah-config-|\\.properties)", ""))
1043-
.forEach(idtype -> {
1044-
int delimiterPos = idtype.indexOf('_');
1045-
// '_' should be somewhere in the middle of idtype
1046-
if (delimiterPos > 1 && delimiterPos < idtype.length() - 1) {
1047-
AbstractChronology.registerChrono(
1048-
new HijrahChronology(
1049-
idtype.substring(0, delimiterPos),
1050-
idtype.substring(delimiterPos + 1)));
1051-
} else {
1052-
PlatformLogger.getLogger("java.time.chrono")
1053-
.warning("Hijrah custom config init failed." +
1054-
"'<id>_<type>' name convention not followed: " + idtype);
1055-
}
1056-
});
1057-
} catch (IOException e) {
1058-
PlatformLogger.getLogger("java.time.chrono")
1059-
.warning("Hijrah custom config init failed.", e);
1060-
}
1061-
}
1062-
return null;
1063-
},
1064-
null,
1065-
new FilePermission("<<ALL FILES>>", "read"));
1019+
1020+
if (Files.isDirectory(CONF_PATH)) {
1021+
try (Stream<Path> stream = Files.list(CONF_PATH)) {
1022+
stream.map(p -> p.getFileName().toString())
1023+
.filter(fn -> fn.matches("hijrah-config-[^\\.]+\\.properties"))
1024+
.map(fn -> fn.replaceAll("(hijrah-config-|\\.properties)", ""))
1025+
.forEach(idtype -> {
1026+
int delimiterPos = idtype.indexOf('_');
1027+
// '_' should be somewhere in the middle of idtype
1028+
if (delimiterPos > 1 && delimiterPos < idtype.length() - 1) {
1029+
AbstractChronology.registerChrono(
1030+
new HijrahChronology(
1031+
idtype.substring(0, delimiterPos),
1032+
idtype.substring(delimiterPos + 1)));
1033+
} else {
1034+
PlatformLogger.getLogger("java.time.chrono")
1035+
.warning("Hijrah custom config init failed." +
1036+
"'<id>_<type>' name convention not followed: " + idtype);
1037+
}
1038+
});
1039+
} catch (IOException e) {
1040+
PlatformLogger.getLogger("java.time.chrono")
1041+
.warning("Hijrah custom config init failed.", e);
1042+
}
1043+
}
10661044
}
10671045

10681046
//-----------------------------------------------------------------------

src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -61,8 +61,6 @@
6161
*/
6262
package java.time.zone;
6363

64-
import java.security.AccessController;
65-
import java.security.PrivilegedAction;
6664
import java.time.ZoneId;
6765
import java.time.ZonedDateTime;
6866
import java.util.ArrayList;
@@ -146,28 +144,21 @@ public abstract class ZoneRulesProvider {
146144
static {
147145
// if the property java.time.zone.DefaultZoneRulesProvider is
148146
// set then its value is the class name of the default provider
149-
@SuppressWarnings("removal")
150-
final List<ZoneRulesProvider> loaded =
151-
AccessController.doPrivileged(new PrivilegedAction<List<ZoneRulesProvider>>() {
152-
public List<ZoneRulesProvider> run() {
153-
List<ZoneRulesProvider> result = new ArrayList<>();
154-
String prop = System.getProperty("java.time.zone.DefaultZoneRulesProvider");
155-
if (prop != null) {
156-
try {
157-
Class<?> c = Class.forName(prop, true, ClassLoader.getSystemClassLoader());
158-
@SuppressWarnings("deprecation")
159-
ZoneRulesProvider provider = ZoneRulesProvider.class.cast(c.newInstance());
160-
registerProvider(provider);
161-
result.add(provider);
162-
} catch (Exception x) {
163-
throw new Error(x);
164-
}
165-
} else {
166-
registerProvider(new TzdbZoneRulesProvider());
167-
}
168-
return result;
169-
}
170-
});
147+
final List<ZoneRulesProvider> loaded = new ArrayList<>();
148+
String prop = System.getProperty("java.time.zone.DefaultZoneRulesProvider");
149+
if (prop != null) {
150+
try {
151+
Class<?> c = Class.forName(prop, true, ClassLoader.getSystemClassLoader());
152+
@SuppressWarnings("deprecation")
153+
ZoneRulesProvider provider = ZoneRulesProvider.class.cast(c.newInstance());
154+
registerProvider(provider);
155+
loaded.add(provider);
156+
} catch (Exception x) {
157+
throw new Error(x);
158+
}
159+
} else {
160+
registerProvider(new TzdbZoneRulesProvider());
161+
}
171162

172163
ServiceLoader<ZoneRulesProvider> sl = ServiceLoader.load(ZoneRulesProvider.class, ClassLoader.getSystemClassLoader());
173164
Iterator<ZoneRulesProvider> it = sl.iterator();

0 commit comments

Comments
 (0)