On 19/05/2017 14:48, Stephen Felts wrote:

By the way, there is no available API so that one can write

If an object is not accessible and setAccessible on the object will succeed

   call setAccessible

That means that the code needs to call setAccessible and handle the exception, 
which triggers a warning.

AccessibleObject canAccess is new in 9 to test if a reflected object is accessible. Another new API is trySetAccessible to avoid using exceptions for control flow.

To your example then if setAccessible succeeds in suppressing access to a JDK internal member then you'll get a warning if it's the first illegal access. If setAccessible fails then you'll InaccessibleObjectException will be thrown as it does not, there will be no warning.

-Alan.

Reply via email to