1 package com.fasterxml.jackson.databind.misc; 2 3 import java.io.IOException; 4 import java.security.Permission; 5 6 import com.fasterxml.jackson.databind.*; 7 8 // Test(s) to verify that forced access works as expected 9 public class AccessFixTest extends BaseMapTest 10 { 11 static class CauseBlockingSecurityManager 12 extends SecurityManager 13 { 14 @Override checkPermission(Permission perm)15 public void checkPermission(Permission perm) throws SecurityException { 16 if ("suppressAccessChecks".equals(perm.getName())) { 17 throw new SecurityException("Cannot force permission: "+perm); 18 } 19 } 20 } 21 22 // [databind#877]: avoid forcing access to `cause` field of `Throwable` 23 // as it is never actually used (always call `initCause()` instead) testCauseOfThrowableIgnoral()24 public void testCauseOfThrowableIgnoral() throws Exception 25 { 26 final SecurityManager origSecMan = System.getSecurityManager(); 27 ObjectMapper mapper = jsonMapperBuilder() 28 .disable(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS) 29 .build(); 30 try { 31 System.setSecurityManager(new CauseBlockingSecurityManager()); 32 _testCauseOfThrowableIgnoral(mapper); 33 } finally { 34 System.setSecurityManager(origSecMan); 35 } 36 } 37 _testCauseOfThrowableIgnoral(ObjectMapper mapper)38 private void _testCauseOfThrowableIgnoral(ObjectMapper mapper) throws Exception 39 { 40 IOException e = mapper.readValue("{}", IOException.class); 41 assertNotNull(e); 42 } 43 } 44