Skip to content

Commit

Permalink
Fix #3275
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 26, 2022
1 parent b447e39 commit 2f60d39
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
6 changes: 6 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1436,3 +1436,9 @@ Taylor S Marks (TaylorSMarks@github)
Spence Nace (snace98@github)
* Contributed fix for #2816: Optimize UntypedObjectDeserializer wrt recursion
(2.13.3)
Jason Harper (jsharper@github)
* Reported #3275: JDK 16 Illegal reflective access for `Throwable.setCause()` with
`PropertyNamingStrategy.UPPER_CAMEL_CASE`
(2.13.4)
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.13.4 (not yet released)

#3275: JDK 16 Illegal reflective access for `Throwable.setCause()` with
`PropertyNamingStrategy.UPPER_CAMEL_CASE`
(reported by Jason H)

2.13.3 (14-May-2022)

#3412: Version 2.13.2 uses `Method.getParameterCount()` which is not supported on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ public JsonDeserializer<Object> buildThrowableDeserializer(DeserializationContex

// But then let's decorate things a bit
// Need to add "initCause" as setter for exceptions (sub-classes of Throwable).
// 26-May-2022, tatu: [databind#3275] Looks like JDK 12 added "setCause()"
// which can wreak havoc, at least with NamingStrategy
Iterator<SettableBeanProperty> it = builder.getProperties();
while (it.hasNext()) {
SettableBeanProperty prop = it.next();
if ("setCause".equals(prop.getMember().getName())) {
// For now this is allowed as we are returned "live" Iterator...
it.remove();
break;
}
}
AnnotatedMethod am = beanDesc.findMethod("initCause", INIT_CAUSE_PARAMS);
if (am != null) { // should never be null
SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(ctxt.getConfig(), am,
Expand Down Expand Up @@ -453,10 +464,9 @@ public JsonDeserializer<Object> buildThrowableDeserializer(DeserializationContex
}
}
JsonDeserializer<?> deserializer = builder.build();

/* At this point it ought to be a BeanDeserializer; if not, must assume
* it's some other thing that can handle deserialization ok...
*/

// At this point it ought to be a BeanDeserializer; if not, must assume
// it's some other thing that can handle deserialization ok...
if (deserializer instanceof BeanDeserializer) {
deserializer = new ThrowableDeserializer((BeanDeserializer) deserializer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void testLineNumberAsString() throws IOException
assertNotNull(exc);
}

// [databind#1842]:
// [databind#1842]
public void testNullAsMessage() throws IOException
{
Exception exc = MAPPER.readValue(a2q(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.core.JsonParser;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.json.JsonMapper;

/**
* Unit tests for verifying that simple exceptions can be serialized.
Expand Down Expand Up @@ -134,4 +135,15 @@ public void testDatabindExceptionSerialization() throws IOException {
fail("Exception should contain '"+MATCH+"', does not: '"+msg+"'");
}
}

// [databind#3275]
public void testSerializeWithNamingStrategy() throws IOException {
final ObjectMapper mapper = JsonMapper.builder()
.propertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE)
.build();
String json = mapper.writeValueAsString(new Exception("message!"));
Map<?,?> map = mapper.readValue(json, Map.class);
assertEquals(new HashSet<>(Arrays.asList("Cause", "StackTrace", "Message", "Suppressed", "LocalizedMessage")),
map.keySet());
}
}

0 comments on commit 2f60d39

Please sign in to comment.