Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8178823

Unable to initialize HijrahCalendar: Hijrah-umalqura when running with a security manager

XMLWordPrintable

    • b165
    • 9
    • b167
    • Verified

        The permission required to access resources in the run-time image changed from FilePermission("<<ALL FILES>>", "read") to RuntimePermission("accessSystemModules") in jdk-9+165. This required adjusting one or two places that call Class or ClassLoader.getResourceXXX with limited doPrivileged (code all getResourceXXX with the regular doPrivileged is not impacted).

        HijrahChronology.readConfigProperties was missed, I assume because we don't have tests that exercise that code with a security manager. This will need to be fixed as otherwise invoking a method on the HijrahChronology.INSTANCE will fail with:

        Apr 14, 2017 7:46:03 P.M. java.time.chrono.HijrahChronology loadCalendarData
        SEVERE: Unable to initialize Hijrah calendar proxy: Hijrah-umalqura
        java.lang.RuntimeException: Hijrah calendar resource not found: /java/time/chrono/hijrah-config-islamic-umalqura.properties
        at java.base/java.time.chrono.HijrahChronology.readConfigProperties(HijrahChronology.java:819)
        at java.base/java.time.chrono.HijrahChronology.loadCalendarData(HijrahChronology.java:840)
        at java.base/java.time.chrono.HijrahChronology.checkCalendarInit(HijrahChronology.java:313)
        at java.base/java.time.chrono.HijrahChronology.isLeapYear(HijrahChronology.java:473)
        at Test2.main(Test2.java:8)

        Exception in thread "main" java.time.DateTimeException: Unable to initialize HijrahCalendar: Hijrah-umalqura
        at java.base/java.time.chrono.HijrahChronology.loadCalendarData(HijrahChronology.java:909)
        at java.base/java.time.chrono.HijrahChronology.checkCalendarInit(HijrahChronology.java:313)
        at java.base/java.time.chrono.HijrahChronology.isLeapYear(HijrahChronology.java:473)
        at Test2.main(Test2.java:8)
        Caused by: java.lang.RuntimeException: Hijrah calendar resource not found: /java/time/chrono/hijrah-config-islamic-umalqura.properties
        at java.base/java.time.chrono.HijrahChronology.readConfigProperties(HijrahChronology.java:819)
        at java.base/java.time.chrono.HijrahChronology.loadCalendarData(HijrahChronology.java:840)
        ... 3 more


        The following is enough to fix the issue:

        diff -r 5f24e5bf62bd src/java.base/share/classes/java/time/chrono/HijrahChronology.java
        --- a/src/java.base/share/classes/java/time/chrono/HijrahChronology.java Fri Apr 14 15:30:39 2017 +0800
        +++ b/src/java.base/share/classes/java/time/chrono/HijrahChronology.java Fri Apr 14 19:53:58 2017 +0100
        @@ -813,8 +813,9 @@
             private Properties readConfigProperties(final String calendarType) throws Exception {
                 String resourceName = RESOURCE_PREFIX + calendarType + RESOURCE_SUFFIX;
                 PrivilegedAction<InputStream> getResourceAction = () -> HijrahChronology.class.getResourceAsStream(resourceName);
        - FilePermission perm = new FilePermission("<<ALL FILES>>", "read");
        - try (InputStream is = AccessController.doPrivileged(getResourceAction, null, perm)) {
        + FilePermission perm1 = new FilePermission("<<ALL FILES>>", "read");
        + RuntimePermission perm2 = new RuntimePermission("accessSystemModules");
        + try (InputStream is = AccessController.doPrivileged(getResourceAction, null, perm1, perm2)) {
                     if (is == null) {
                         throw new RuntimeException("Hijrah calendar resource not found: /java/time/chrono/" + resourceName);
                     }

              naoto Naoto Sato
              alanb Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: