diff options
author | Sebastien Hertz <shertz@google.com> | 2015-04-28 15:00:41 +0200 |
---|---|---|
committer | Sebastien Hertz <shertz@google.com> | 2015-04-28 15:25:47 +0200 |
commit | 2d2f2a9c665b02ca5139f71e37ca5e08389e4191 (patch) | |
tree | 50551b6039ff7924d75077ace60bd4304a8ed3bf /test/100-reflect2 | |
parent | 3adfc4bbe6c42d574bd2069d8e38a13d5ad98ccf (diff) | |
download | art-2d2f2a9c665b02ca5139f71e37ca5e08389e4191.tar.gz art-2d2f2a9c665b02ca5139f71e37ca5e08389e4191.tar.bz2 art-2d2f2a9c665b02ca5139f71e37ca5e08389e4191.zip |
Fix constructor access check through reflection
We must not throw IllegalAccessException if the constructor has been
made accessible by a previous call to Constructor.setAccessible, even
if the caller cannot access the constructor.
Bug: 20639158
Change-Id: I9a34f05cdbb8825ad88b42223743690228e3f03e
Diffstat (limited to 'test/100-reflect2')
-rw-r--r-- | test/100-reflect2/src/Main.java | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/test/100-reflect2/src/Main.java b/test/100-reflect2/src/Main.java index 86a5ef89d1..72e14b15f3 100644 --- a/test/100-reflect2/src/Main.java +++ b/test/100-reflect2/src/Main.java @@ -266,7 +266,7 @@ class Main { show(ctor.newInstance(new char[] { 'x', 'y', 'z', '!' }, 1, 2)); } - private static void testPackagePrivate() { + private static void testPackagePrivateConstructor() { try { Class<?> c = Class.forName("sub.PPClass"); Constructor cons = c.getConstructor(); @@ -280,10 +280,23 @@ class Main { } } + private static void testPackagePrivateAccessibleConstructor() { + try { + Class<?> c = Class.forName("sub.PPClass"); + Constructor cons = c.getConstructor(); + cons.setAccessible(true); // ensure we prevent IllegalAccessException + cons.newInstance(); + } catch (Exception e) { + // Error. + e.printStackTrace(); + } + } + public static void main(String[] args) throws Exception { testFieldReflection(); testMethodReflection(); testConstructorReflection(); - testPackagePrivate(); + testPackagePrivateConstructor(); + testPackagePrivateAccessibleConstructor(); } } |