|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
59 | 59 |
|
60 | 60 | import static java.time.temporal.ChronoField.EPOCH_DAY; |
61 | 61 |
|
62 | | -import java.io.FilePermission; |
63 | 62 | import java.io.IOException; |
64 | 63 | import java.io.InputStream; |
65 | 64 | import java.io.InvalidObjectException; |
66 | 65 | import java.io.ObjectInputStream; |
67 | 66 | import java.io.Serializable; |
68 | | -import java.io.UncheckedIOException; |
69 | 67 | import java.nio.file.Files; |
70 | 68 | import java.nio.file.Path; |
71 | 69 | import java.nio.file.StandardOpenOption; |
72 | | -import java.security.AccessController; |
73 | | -import java.security.PrivilegedAction; |
74 | 70 | import java.time.Clock; |
75 | 71 | import java.time.DateTimeException; |
76 | 72 | import java.time.Instant; |
|
88 | 84 | import java.util.Properties; |
89 | 85 | import java.util.stream.Stream; |
90 | 86 |
|
| 87 | +import jdk.internal.util.StaticProperty; |
91 | 88 | import sun.util.logging.PlatformLogger; |
92 | 89 |
|
93 | 90 | /** |
@@ -291,10 +288,7 @@ public final class HijrahChronology extends AbstractChronology implements Serial |
291 | 288 | AbstractChronology.registerChrono(INSTANCE, "islamic"); |
292 | 289 |
|
293 | 290 | // 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"); |
298 | 292 | registerCustomChrono(); |
299 | 293 | } |
300 | 294 |
|
@@ -824,19 +818,9 @@ private int epochMonthLength(int epochMonth) { |
824 | 818 | */ |
825 | 819 | private static Properties readConfigProperties(final String chronologyId, final String calendarType) throws Exception { |
826 | 820 | 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)) { |
840 | 824 | if (is == null) { |
841 | 825 | throw new RuntimeException("Hijrah calendar resource not found: " + resourceName); |
842 | 826 | } |
@@ -1031,38 +1015,32 @@ private int[] parseYMD(String string) { |
1031 | 1015 | * Look for Hijrah chronology variant properties files in |
1032 | 1016 | * <JAVA_HOME>/conf/chronology directory. Then register its chronology, if any. |
1033 | 1017 | */ |
1034 | | - @SuppressWarnings("removal") |
1035 | 1018 | 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 | + } |
1066 | 1044 | } |
1067 | 1045 |
|
1068 | 1046 | //----------------------------------------------------------------------- |
|
0 commit comments