Right. I'm asking for a new API so code can be written to avoid the warning.
-----Original Message----- From: Alan Bateman Sent: Friday, May 19, 2017 10:11 AM To: Stephen Felts; jigsaw-dev@openjdk.java.net Subject: Re: Proposal: Allow illegal reflective access by default in JDK 9 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.