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

ResourceBundle.Control.newBundle should throw IllegalAccessException when constructor of the resource bundle is not public.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 12
    • 11.0.2, 12
    • core-libs

    Description

      Based on the specification of ResourceBundle.Control.newBundle in jdk 11, the method will throw IllegalAccessException if the class or its nullary constructor is not accessible. But the IllegalAccessException is not thrown.
      I checked the source code, since jdk 9, ResourceBundle.Control.newBundle is changed, if constructor of the resource bundle is not public, it does not throw IllegalAccessException, only when unnamed module loads a resource bundle in a named module which are not open, the exception will be thrown.
      JDK 12:
      3178 // To access a resource bundle in a named module,
      3179 // either class-based or properties-based, the resource
      3180 // bundle must be opened unconditionally,
      3181 // same rule as accessing a resource file.
      3182 if (m.isNamed() && !m.isOpen(bundleClass.getPackageName())) {
      3183 throw new IllegalAccessException("unnamed module can't load " +
      3184 bundleClass.getName() + " in " + m.toString());
      3185 }
      3186 try {
      3187 // bundle in a unnamed module
      3188 Constructor<ResourceBundle> ctor = bundleClass.getConstructor();
      3189 if (!Modifier.isPublic(ctor.getModifiers())) {
      3190 return null;
      3191 }
      3192
      3193 // java.base may not be able to read the bundleClass's module.
      3194 PrivilegedAction<Void> pa1 = () -> { ctor.setAccessible(true); return null; };
      3195 AccessController.doPrivileged(pa1);
      3196 bundle = ctor.newInstance((Object[]) null);

      Run attached sample code:
      8u191 build 12: passed
      12 build 20: failed
      11.02 build 04: failed
      Error log:
      Exception in thread "main" java.lang.RuntimeException: getBundle("PrivateConstructorRB") throws null, expected class java.lang.IllegalAccessException
              at MissingResourceCauseTest.callGetBundle(MissingResourceCauseTest.java:18)
              at MissingResourceCauseTest.main(MissingResourceCauseTest.java:5)

      Attachments

        Activity

          People

            naoto Naoto Sato
            dzhou Dora Zhou (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: