< prev index next >

test/jdk/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java

Print this page

132             assertTrue(false);
133         } catch (IllegalAccessException expected) { }
134 
135         try {
136             f.setAccessible(true);
137             assertTrue(false);
138         } catch (InaccessibleObjectException expected) { }
139 
140         f.setAccessible(false); // should succeed
141     }
142 
143 
144     /**
145      * Test that the Class constructor cannot be make accessible.
146      */
147     public void testJavaLangClass() throws Exception {
148 
149         // non-public constructor
150         Constructor<?> ctor
151             = Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, char.class,
152                                                  ProtectionDomain.class, boolean.class, char.class);
153         AccessibleObject[] ctors = { ctor };
154 
155         try {
156             ctor.setAccessible(true);
157             assertTrue(false);
158         } catch (SecurityException expected) { }
159 
160         try {
161             AccessibleObject.setAccessible(ctors, true);
162             assertTrue(false);
163         } catch (SecurityException expected) { }
164 
165         // should succeed
166         ctor.setAccessible(false);
167         AccessibleObject.setAccessible(ctors, false);
168 
169     }
170 
171 }

132             assertTrue(false);
133         } catch (IllegalAccessException expected) { }
134 
135         try {
136             f.setAccessible(true);
137             assertTrue(false);
138         } catch (InaccessibleObjectException expected) { }
139 
140         f.setAccessible(false); // should succeed
141     }
142 
143 
144     /**
145      * Test that the Class constructor cannot be make accessible.
146      */
147     public void testJavaLangClass() throws Exception {
148 
149         // non-public constructor
150         Constructor<?> ctor
151             = Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, char.class,
152                                                  ProtectionDomain.class, boolean.class, boolean.class, char.class);
153         AccessibleObject[] ctors = { ctor };
154 
155         try {
156             ctor.setAccessible(true);
157             assertTrue(false);
158         } catch (SecurityException expected) { }
159 
160         try {
161             AccessibleObject.setAccessible(ctors, true);
162             assertTrue(false);
163         } catch (SecurityException expected) { }
164 
165         // should succeed
166         ctor.setAccessible(false);
167         AccessibleObject.setAccessible(ctors, false);
168 
169     }
170 
171 }
< prev index next >