114 * <p>A {@code SecurityException} is raised if this object is a {@link
115 * java.lang.reflect.Constructor} object for the class
116 * {@code java.lang.Class}, and {@code flag} is true.
117 *
118 * @param flag the new value for the {@code accessible} flag
119 * @throws SecurityException if the request is denied.
120 * @see SecurityManager#checkPermission
121 * @see java.lang.RuntimePermission
122 */
123 public void setAccessible(boolean flag) throws SecurityException {
124 SecurityManager sm = System.getSecurityManager();
125 if (sm != null) sm.checkPermission(ACCESS_PERMISSION);
126 setAccessible0(this, flag);
127 }
128
129 /* Check that you aren't exposing java.lang.Class.<init>. */
130 private static void setAccessible0(AccessibleObject obj, boolean flag)
131 throws SecurityException
132 {
133 if (obj instanceof Constructor && flag == true) {
134 Constructor c = (Constructor)obj;
135 if (c.getDeclaringClass() == Class.class) {
136 throw new SecurityException("Can not make a java.lang.Class" +
137 " constructor accessible");
138 }
139 }
140 obj.override = flag;
141 }
142
143 /**
144 * Get the value of the {@code accessible} flag for this object.
145 *
146 * @return the value of the object's {@code accessible} flag
147 */
148 public boolean isAccessible() {
149 return override;
150 }
151
152 /**
153 * Constructor: only used by the Java Virtual Machine.
154 */
|
114 * <p>A {@code SecurityException} is raised if this object is a {@link
115 * java.lang.reflect.Constructor} object for the class
116 * {@code java.lang.Class}, and {@code flag} is true.
117 *
118 * @param flag the new value for the {@code accessible} flag
119 * @throws SecurityException if the request is denied.
120 * @see SecurityManager#checkPermission
121 * @see java.lang.RuntimePermission
122 */
123 public void setAccessible(boolean flag) throws SecurityException {
124 SecurityManager sm = System.getSecurityManager();
125 if (sm != null) sm.checkPermission(ACCESS_PERMISSION);
126 setAccessible0(this, flag);
127 }
128
129 /* Check that you aren't exposing java.lang.Class.<init>. */
130 private static void setAccessible0(AccessibleObject obj, boolean flag)
131 throws SecurityException
132 {
133 if (obj instanceof Constructor && flag == true) {
134 Constructor<?> c = (Constructor<?>)obj;
135 if (c.getDeclaringClass() == Class.class) {
136 throw new SecurityException("Can not make a java.lang.Class" +
137 " constructor accessible");
138 }
139 }
140 obj.override = flag;
141 }
142
143 /**
144 * Get the value of the {@code accessible} flag for this object.
145 *
146 * @return the value of the object's {@code accessible} flag
147 */
148 public boolean isAccessible() {
149 return override;
150 }
151
152 /**
153 * Constructor: only used by the Java Virtual Machine.
154 */
|