123 * @see SecurityManager#checkPermission 124 * @see java.lang.RuntimePermission 125 */ 126 public void setAccessible(boolean flag) throws SecurityException { 127 SecurityManager sm = System.getSecurityManager(); 128 if (sm != null) sm.checkPermission(ACCESS_PERMISSION); 129 setAccessible0(this, flag); 130 } 131 132 /* Check that you aren't exposing java.lang.Class.<init> or sensitive 133 fields in java.lang.Class. */ 134 private static void setAccessible0(AccessibleObject obj, boolean flag) 135 throws SecurityException 136 { 137 if (obj instanceof Constructor && flag == true) { 138 Constructor<?> c = (Constructor<?>)obj; 139 if (c.getDeclaringClass() == Class.class) { 140 throw new SecurityException("Cannot make a java.lang.Class" + 141 " constructor accessible"); 142 } 143 } else if (obj instanceof Field && flag == true) { 144 Field f = (Field)obj; 145 if (f.getDeclaringClass() == Class.class && 146 f.getName().equals("classLoader")) { 147 throw new SecurityException("Cannot make java.lang.Class.classLoader" + 148 " accessible"); 149 } 150 } 151 obj.override = flag; 152 } 153 154 /** 155 * Get the value of the {@code accessible} flag for this object. 156 * 157 * @return the value of the object's {@code accessible} flag 158 */ 159 public boolean isAccessible() { 160 return override; 161 } 162 163 /** 164 * Constructor: only used by the Java Virtual Machine. 165 */ 166 protected AccessibleObject() {} 167 168 // Indicates whether language-level access checks are overridden 169 // by this object. Initializes to "false". This field is used by | 123 * @see SecurityManager#checkPermission 124 * @see java.lang.RuntimePermission 125 */ 126 public void setAccessible(boolean flag) throws SecurityException { 127 SecurityManager sm = System.getSecurityManager(); 128 if (sm != null) sm.checkPermission(ACCESS_PERMISSION); 129 setAccessible0(this, flag); 130 } 131 132 /* Check that you aren't exposing java.lang.Class.<init> or sensitive 133 fields in java.lang.Class. */ 134 private static void setAccessible0(AccessibleObject obj, boolean flag) 135 throws SecurityException 136 { 137 if (obj instanceof Constructor && flag == true) { 138 Constructor<?> c = (Constructor<?>)obj; 139 if (c.getDeclaringClass() == Class.class) { 140 throw new SecurityException("Cannot make a java.lang.Class" + 141 " constructor accessible"); 142 } 143 } 144 obj.override = flag; 145 } 146 147 /** 148 * Get the value of the {@code accessible} flag for this object. 149 * 150 * @return the value of the object's {@code accessible} flag 151 */ 152 public boolean isAccessible() { 153 return override; 154 } 155 156 /** 157 * Constructor: only used by the Java Virtual Machine. 158 */ 159 protected AccessibleObject() {} 160 161 // Indicates whether language-level access checks are overridden 162 // by this object. Initializes to "false". This field is used by |