< prev index next >

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

Print this page

157     public void testPublicFieldInNonExportedPackage() throws Exception {
158         Class<?> clazz = Class.forName("sun.security.x509.X500Name");
159         Field f = clazz.getField("SERIALNUMBER_OID");
160 
161         assertThrows(IllegalAccessException.class, () -> f.get(null));
162 
163         assertFalse(f.trySetAccessible());
164         assertFalse(f.canAccess(null));
165     }
166 
167 
168     /**
169      * Test that the Class constructor cannot be make accessible.
170      */
171     @Test
172     public void testJavaLangClass() throws Exception {
173 
174         // non-public constructor
175         Constructor<?> ctor
176             = Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, char.class,
177                                                  ProtectionDomain.class, boolean.class, char.class);
178         AccessibleObject[] ctors = { ctor };
179 
180         assertFalse(ctor.trySetAccessible());
181         assertFalse(ctor.canAccess(null));
182     }
183 
184 }

157     public void testPublicFieldInNonExportedPackage() throws Exception {
158         Class<?> clazz = Class.forName("sun.security.x509.X500Name");
159         Field f = clazz.getField("SERIALNUMBER_OID");
160 
161         assertThrows(IllegalAccessException.class, () -> f.get(null));
162 
163         assertFalse(f.trySetAccessible());
164         assertFalse(f.canAccess(null));
165     }
166 
167 
168     /**
169      * Test that the Class constructor cannot be make accessible.
170      */
171     @Test
172     public void testJavaLangClass() throws Exception {
173 
174         // non-public constructor
175         Constructor<?> ctor
176             = Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, char.class,
177                                                  ProtectionDomain.class, boolean.class, boolean.class, char.class);
178         AccessibleObject[] ctors = { ctor };
179 
180         assertFalse(ctor.trySetAccessible());
181         assertFalse(ctor.canAccess(null));
182     }
183 
184 }
< prev index next >