Skip to content

Commit b2ccdee

Browse files
committed
Fix #877
1 parent d71de54 commit b2ccdee

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Project: jackson-databind
66

77
2.7.8 (not yet released)
88

9+
#877: @JsonIgnoreProperties`: ignoring the "cause" property of `Throwable` on GAE
910
#1359: Improve `JsonNode` deserializer to create `FloatNode` if parser supports
1011
#1362: ObjectReader.readValues()` ignores offset and length when reading an array
1112
(reported by wastevenson@github)

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,15 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
709709
AnnotatedMember mutator = propDef.getNonConstructorMutator();
710710

711711
if (ctxt.canOverrideAccessModifiers()) {
712-
mutator.fixAccess(ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
712+
// [databind#877]: explicitly prevent forced access to `cause` of `Throwable`;
713+
// never needed and attempts may cause problems on some platforms.
714+
// !!! NOTE: should be handled better for 2.8 and later
715+
if ((mutator instanceof AnnotatedField)
716+
&& "cause".equals(mutator.getName())) {
717+
;
718+
} else {
719+
mutator.fixAccess(ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
720+
}
713721
}
714722
// note: this works since we know there's exactly one argument for methods
715723
BeanProperty.Std property = new BeanProperty.Std(propDef.getFullName(),

src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,26 +773,22 @@ public static void checkAndFixAccess(Member member, boolean force)
773773
* always to make it accessible (latter because it will force
774774
* skipping checks we have no use for...), so let's always call it.
775775
*/
776-
//if (!ao.isAccessible()) {
777776
try {
778777
if (force ||
779778
(!Modifier.isPublic(member.getModifiers())
780779
|| !Modifier.isPublic(member.getDeclaringClass().getModifiers()))) {
781780
ao.setAccessible(true);
782781
}
783782
} catch (SecurityException se) {
784-
/* 17-Apr-2009, tatu: Related to [JACKSON-101]: this can fail on
785-
* platforms like EJB and Google App Engine); so let's
786-
* only fail if we really needed it...
787-
*/
783+
// 17-Apr-2009, tatu: Related to [JACKSON-101]: this can fail on platforms like
784+
// Google App Engine); so let's only fail if we really needed it...
788785
if (!ao.isAccessible()) {
789786
Class<?> declClass = member.getDeclaringClass();
790787
throw new IllegalArgumentException("Can not access "+member+" (from class "+declClass.getName()+"; failed to set access: "+se.getMessage());
791788
}
792789
}
793-
//}
794790
}
795-
791+
796792
/*
797793
/**********************************************************
798794
/* Enum type detection
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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
15+
public void checkPermission(Permission perm) throws SecurityException {
16+
if ("suppressAccessChecks".equals(perm.getName())) {
17+
throw new SecurityException("Can not 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)
24+
public void testCauseOfThrowableIgnoral() throws Exception
25+
{
26+
final SecurityManager origSecMan = System.getSecurityManager();
27+
try {
28+
System.setSecurityManager(new CauseBlockingSecurityManager());
29+
_testCauseOfThrowableIgnoral();
30+
} finally {
31+
System.setSecurityManager(origSecMan);
32+
}
33+
}
34+
35+
private void _testCauseOfThrowableIgnoral() throws Exception
36+
{
37+
ObjectMapper mapper = new ObjectMapper();
38+
mapper.disable(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS);
39+
IOException e = mapper.readValue("{}", IOException.class);
40+
assertNotNull(e);
41+
}
42+
}

0 commit comments

Comments
 (0)