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

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

    Details

    • Subcomponent:
    • Introduced In Build:
      b165
    • Introduced In Version:
      9
    • Resolved In Build:
      b167
    • Verification:
      Verified

      Backports

        Description

        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);
                     }

          Activity

          Hide
          alanb Alan Bateman added a comment -
          This is approved for JDK 9 as it is a regression and the fix is low risk.
          Show
          alanb Alan Bateman added a comment - This is approved for JDK 9 as it is a regression and the fix is low risk.
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/0a701ba4c306
          User: naoto
          Date: 2017-04-20 21:11:38 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/0a701ba4c306 User: naoto Date: 2017-04-20 21:11:38 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/0a701ba4c306
          User: lana
          Date: 2017-04-26 19:55:46 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/0a701ba4c306 User: lana Date: 2017-04-26 19:55:46 +0000

            People

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

              Dates

              • Due:
                Created:
                Updated:
                Resolved: