A broken setAccessible use case: enhanced diagnostics

Jochen Theodorou blackdrag at gmx.org
Thu Jan 26 19:56:29 UTC 2017



On 26.01.2017 13:34, Russell Gold wrote:
> The Glassfish Primitive Function Library (PFL) contains an
> interesting use case for setAccessible: an enhanced object-to-string
> capability. Now, in an ideal world, this shouldn’t be needed, as each
> object provides an adequate toString() method; however, it is not
> uncommon while trying to diagnose a problem, to need to see the
> actual state of objects, as represented by their fields, as the
> toString() function often doesn’t show everything. This is especially
> important to diagnose problems in production, where one could ask a
> customer to enable a debug flag. Until now, this was restricted only
> by the security manager. What can we do to keep such a capability in
> JDK9?

you have to declare all the module and the packages you want to access 
as open. On the command line this is done by using --add-opens. For 
example --add-opens java.base to open all classes in the java.base 
module. At runtime you have to use the Module and Layer APIs to realize 
this...

bye Jochen


More information about the jigsaw-dev mailing list