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

--add-opens does not open up reflective access to resources

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      It appears as though loading resource bundles from non-exported packages is impossible, even with use of the --add-opens VM option.

      echo 'public class SecBundleTest { public static void main(String[] args) { System.out.println(java.util.ResourceBundle.getBundle("sun.security.util.Resources")); }}' >SecBundleTest.java
      javac SecBundleTest.java
      java --add-opens=java.base/sun.security.util=ALL-UNNAMED SecBundleTest
      Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name sun.security.util.Resources, locale en_US
      at java.base/java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:2055)
      at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1689)
      at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1593)
      at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1556)
      at java.base/java.util.ResourceBundle.getBundle(ResourceBundle.java:857)
      at SecBundleTest.main(SecBundleTest.java:11)
      Caused by: java.lang.IllegalAccessException: unnamed module can't load sun.security.util.Resources in module java.base
      at java.base/java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:3184)
      at java.base/java.util.ResourceBundle.loadBundle(ResourceBundle.java:1994)
      at java.base/java.util.ResourceBundle.findBundle(ResourceBundle.java:1776)
      at java.base/java.util.ResourceBundle.findBundle(ResourceBundle.java:1728)
      at java.base/java.util.ResourceBundle.findBundle(ResourceBundle.java:1728)
      at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1662)
      ... 4 more

      [~alanb] pointed out:

      "The Resource bundles in other modules and class path" in the ResourceBundle spec is the starting point. It comes down to ClassLoader.getResourcAsStream which can only locate resources in packages that are open to all modules. There is no way on the command line to open a package to all modules."

      Its rather unfortunate that there's no way to access these resources (even with extra command line options) as GraalVM Native Image needs to be able to load and cache such ResourceBundle objects when generating a native image.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dnsimon Douglas Simon
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: