How does one handle a java method which returns a non-public sub-type via reflection?

Alan Bateman Alan.Bateman at oracle.com
Mon Jan 15 19:24:24 UTC 2018


On 15/01/2018 18:27, jeffrey kutcher wrote:
> I've worked with Java since 1995. This example represents an issue that was never an issue up until Java9. Even then, I had no idea it was my code that was the issue since my code never directly referenced illegal classes. I code to write once, run anywhere and never use native method calls to maintain independence.
It's always been possible for getClass() to return a non-public class 
and for the Method invoke in the code example to fail with 
IllegalAccessException. You may have just got lucky in the past.  At 
some point then I would expect the JavaFX modules to not be open by 
default so maybe now is the time to fix the issues. You can run with 
`--illegal-access=warn` to help track down other code that may be 
accidentally trying to access members of JDK internal classes.  You can 
run with `--illegal-access=deny` to see how that code behaves when the 
classes in the JDK modules are not open for illegal access.

-Alan


More information about the jigsaw-dev mailing list