changeset 13551:f161a951b47c

setAccessible(false) should not fail
author alanb
date Thu, 30 Jul 2015 20:29:50 +0100
parents bba4dbbe8901
children 3f2cca7ef3fb
files src/java.base/share/classes/java/lang/reflect/AccessibleObject.java test/jdk/jigsaw/reflect/ModuleSetAccessibleTest.java
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java	Thu Jul 30 20:21:44 2015 +0100
+++ b/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java	Thu Jul 30 20:29:50 2015 +0100
@@ -108,7 +108,7 @@
         throws SecurityException {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) sm.checkPermission(ACCESS_PERMISSION);
-        if (true) {
+        if (flag) {
             Class<?> caller = Reflection.getCallerClass();
             for (AccessibleObject ao : array) {
                 checkCanSetAccessible(caller, ao);
@@ -148,7 +148,7 @@
     public void setAccessible(boolean flag) throws SecurityException {
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) sm.checkPermission(ACCESS_PERMISSION);
-        if (true) checkCanSetAccessible(Reflection.getCallerClass(), this);
+        if (flag) checkCanSetAccessible(Reflection.getCallerClass(), this);
         this.override = flag;
     }
 
--- a/test/jdk/jigsaw/reflect/ModuleSetAccessibleTest.java	Thu Jul 30 20:21:44 2015 +0100
+++ b/test/jdk/jigsaw/reflect/ModuleSetAccessibleTest.java	Thu Jul 30 20:29:50 2015 +0100
@@ -106,6 +106,8 @@
             ctor.setAccessible(true);
             assertTrue(false);
         } catch (SecurityException expected) { }
+
+        ctor.setAccessible(false); // should succeed
     }
 
     /**
@@ -124,6 +126,8 @@
             f.setAccessible(true);
             assertTrue(false);
         } catch (SecurityException expected) { }
+
+        f.setAccessible(false); // should succeed
     }
 
 }