mardi 10 octobre 2017

Java 9 modules, does static imply shallow reflection?

I think I miss something in recent Java 9 modularisation changes. Can there be a situation where static (compile time as defined in the link below, not talking about a static modifier) access (public method in public type) would be allowed, but simple shallow reflection fails?

I mean can I always replace

// returns any Subtype of PublicType
PublicType p = (PublicType)(Factory.instance());
p.publicMethod();

(Where Factory.instance() is returning an encapsulated private implementation of that type)

with

Object p = Factory.instance();
Class<?> c = Class.forName(“package.PublicType“);
Method m = c.getMethod(“publicMethod“, (Class[])null);
m.invoke(p, (Class[])null);

Specifically in my case it is a WebStart App in the unnamed module requiring from the javax.jnlp.BasicService an API method (which is provided by a sun.jnlp.BasicServiceImpl).

But I am more wondering about the general notion that static accessibility would imply shallow reflection (or not). (Especially since I see no security gain here).





Aucun commentaire:

Enregistrer un commentaire