3
getClass().getResource("/com/sun/javafx/scene/control/skin/modena/modena.css")

returns null even with the JVM argument

--add-opens=javafx.controls/com.sun.javafx.scene.control.skin.modena=ALL-UNNAMED
fabian
  • 80,457
  • 12
  • 86
  • 114
wzberger
  • 923
  • 6
  • 15
  • 2
    Which Class does getClass return in the code fragment? If it's not a class in javafx.control then the above will always return null. – Alan Bateman Jul 31 '17 at 11:52
  • It's my own class - works fine with control classes. However, when adding an additional stylesheet with references to resources located in /com/sun/javafx/scene/control/skin/modena these resources can not be found. StyleManager.getInstance().addUserAgentStylesheet(myClass.getResource("/com/css/mystyle.css").toExternalForm()); – wzberger Jul 31 '17 at 13:17
  • 1
    It seems very brittle to rely on resources that are internal to the javafx.controls module. In any case, Class.getResource is working as specified. When you invoke it on a class in a named module then the method attempts to locate the resource in that module. That is why it works when you invoke it on a class in javafx.controls module. However, if you invoke it on myClass then it's not going to locate it in javafx.controls becuase the com.sun.javafx.scene.control.skin.modena package is not open to all modules. – Alan Bateman Jul 31 '17 at 14:09
  • So '--add-opens' does not work for resources? – wzberger Jul 31 '17 at 14:41
  • `--add-opens` can be used to open the package with the resources to "all unnamed modules" as you have done. The result is that you can invoke getResource on a class in javafx.controls and locate one of its internal resources. You cannot use `--add-opens` to open a package to all modules so this is why ClassLoader.getResource cannot locate the resource - the reason that ClassLoader.getResource is in the picture is because Class.getResource delegates to ClassLoader.getResource when you invoke it to locate a resource that is not in the module. – Alan Bateman Jul 31 '17 at 14:46
  • So the only way to get this working is to open the package in the related module descriptor? Is it already too late for such an entry in Java 9? – wzberger Jul 31 '17 at 16:33
  • You could bring up your use-case on the openjfx-dev mailing lists. You might get help there that avoids you needing to directly use modena.css. – Alan Bateman Jul 31 '17 at 22:56

0 Answers0