-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d71de54
commit b2ccdee
Showing
4 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -709,7 +709,15 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext | |
AnnotatedMember mutator = propDef.getNonConstructorMutator(); | ||
|
||
if (ctxt.canOverrideAccessModifiers()) { | ||
mutator.fixAccess(ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS)); | ||
// [databind#877]: explicitly prevent forced access to `cause` of `Throwable`; | ||
// never needed and attempts may cause problems on some platforms. | ||
// !!! NOTE: should be handled better for 2.8 and later | ||
if ((mutator instanceof AnnotatedField) | ||
&& "cause".equals(mutator.getName())) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cowtowncoder
Author
Member
|
||
; | ||
} else { | ||
mutator.fixAccess(ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS)); | ||
} | ||
} | ||
// note: this works since we know there's exactly one argument for methods | ||
BeanProperty.Std property = new BeanProperty.Std(propDef.getFullName(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/com/fasterxml/jackson/databind/misc/AccessFixTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.fasterxml.jackson.databind.misc; | ||
|
||
import java.io.IOException; | ||
import java.security.Permission; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
// Test(s) to verify that forced access works as expected | ||
public class AccessFixTest extends BaseMapTest | ||
{ | ||
static class CauseBlockingSecurityManager | ||
extends SecurityManager | ||
{ | ||
@Override | ||
public void checkPermission(Permission perm) throws SecurityException { | ||
if ("suppressAccessChecks".equals(perm.getName())) { | ||
throw new SecurityException("Can not force permission: "+perm); | ||
} | ||
} | ||
} | ||
|
||
// [databind#877]: avoid forcing access to `cause` field of `Throwable` | ||
// as it is never actually used (always call `initCause()` instead) | ||
public void testCauseOfThrowableIgnoral() throws Exception | ||
{ | ||
final SecurityManager origSecMan = System.getSecurityManager(); | ||
try { | ||
System.setSecurityManager(new CauseBlockingSecurityManager()); | ||
_testCauseOfThrowableIgnoral(); | ||
} finally { | ||
System.setSecurityManager(origSecMan); | ||
} | ||
} | ||
|
||
private void _testCauseOfThrowableIgnoral() throws Exception | ||
{ | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.disable(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS); | ||
IOException e = mapper.readValue("{}", IOException.class); | ||
assertNotNull(e); | ||
} | ||
} |
I have no context on the code, but could this impact non-Throwables that happen to have a member named "cause"?