Code example for FilePermission

0
     */ 
    @SuppressWarnings("nls") 
    public void test_checkReadLjava_lang_StringLjava_lang_Object() { 
        // enable all but one check 
        mutableSM.addPermission(new AllPermission());
        mutableSM.denyPermission(new FilePermission("<<ALL FILES>>", "read"));
        ProtectionDomain pDomain = this.getClass().getProtectionDomain();
        ProtectionDomain[] pd = { pDomain };
        AccessControlContext acc = new AccessControlContext(pd);
        try { 
            mutableSM.checkRead("aa", acc);
            fail("This should throw a SecurityException.");
        } catch (SecurityException e) {
            // expected 
        } 
    } 
 
    /** 
     * @tests {@link java.lang.SecurityManager#checkSetFactory()} 
     */ 
Experience pair programming with AI  Get Codota for Java