112 Class<?> clazz = Class.forName("sun.security.x509.X500Name");
113 Field f = clazz.getField("SERIALNUMBER_OID");
114
115 assertThrows(IllegalAccessException.class, () -> f.get(null));
116
117 assertThrows(InaccessibleObjectException.class, () -> f.setAccessible(true));
118
119 f.setAccessible(false); // should succeed
120 }
121
122
123 /**
124 * Test that the Class constructor cannot be make accessible.
125 */
126 @Test
127 public void testJavaLangClass() throws Exception {
128
129 // non-public constructor
130 Constructor<?> ctor
131 = Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, char.class,
132 ProtectionDomain.class, boolean.class, char.class);
133 AccessibleObject[] ctors = { ctor };
134
135 assertThrows(SecurityException.class, () -> ctor.setAccessible(true));
136 assertThrows(SecurityException.class, () -> AccessibleObject.setAccessible(ctors, true));
137
138 // should succeed
139 ctor.setAccessible(false);
140 AccessibleObject.setAccessible(ctors, false);
141
142 }
143
144 }
|
112 Class<?> clazz = Class.forName("sun.security.x509.X500Name");
113 Field f = clazz.getField("SERIALNUMBER_OID");
114
115 assertThrows(IllegalAccessException.class, () -> f.get(null));
116
117 assertThrows(InaccessibleObjectException.class, () -> f.setAccessible(true));
118
119 f.setAccessible(false); // should succeed
120 }
121
122
123 /**
124 * Test that the Class constructor cannot be make accessible.
125 */
126 @Test
127 public void testJavaLangClass() throws Exception {
128
129 // non-public constructor
130 Constructor<?> ctor
131 = Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, char.class,
132 ProtectionDomain.class, boolean.class, boolean.class, char.class);
133 AccessibleObject[] ctors = { ctor };
134
135 assertThrows(SecurityException.class, () -> ctor.setAccessible(true));
136 assertThrows(SecurityException.class, () -> AccessibleObject.setAccessible(ctors, true));
137
138 // should succeed
139 ctor.setAccessible(false);
140 AccessibleObject.setAccessible(ctors, false);
141
142 }
143
144 }
|