Code example for Permission

Methods: getName

0
        class TestSecurityManager extends SecurityManager {
            boolean called = false;
            @Override 
            public void checkPermission(Permission permission) {
                if (permission instanceof ReflectPermission
                        && "suppressAccessChecks".equals(permission.getName())) {
                    called = true;              
                } 
            } 
             
        } 
        TestSecurityManager s = new TestSecurityManager();
        System.setSecurityManager(s);
         
        Field field = TestClass.class.getDeclaredField("field");
        field.setAccessible(true);
         
        assertTrue(
                "java.lang.reflect.AccessibleObject.setAccessible(boolean)  " + 
                "must call checkPermission on security permissions", 
Experience pair programming with AI  Get Codota for Java