RFR(S+M) / 8022701 Accessibility checking: InvocationTargetException is thrown instead of IllegalAccessError

John Rose john.r.rose at oracle.com
Fri Sep 27 04:33:26 UTC 2013

On Sep 19, 2013, at 9:57 AM, David Chase <david.r.chase at oracle.com> wrote:

> Recommended changes made:
> http://cr.openjdk.java.net/~drchase/8022701/webrev.04/

Good; reviewed.

Consider adding this tweak, which would close the loop on alternation between the fooError and fooException versions:

+    static private void initCauseFrom(Error err, Exception ex) {
+        Throwable th = ex.getCause();
++      if (err.getClass().isInstance(th))  throw (Error) th;
+        err.initCause(th == null ? ex : th);
+    }

E.g., if the reason for linkage failure was originally NoSuchMethodError, but was mapped to NoSuchMethodException (which can happen in MemberName.makeAccessException) then the original NoSuchMethodError is extracted and thrown, rather than a new NoSuchMethodError which wraps the original NoSuchMethodError.

> Test with jtreg (for pass and for induced failure) on MacOS,
> not sure what additional other testing is desired since it is entirely in the libraries.

Your test case is enough.

> I included code to handle the case of a broken field-referencing methodhandle,
> but did not test it because there's no syntax for these in Java, nor is their creation
> well-documented.

That's fine.  Ship it, preferably with the tweak above.

— John

More information about the core-libs-dev mailing list