Skip to content

Commit 14be345

Browse files
authored
Backport #3275 in 2.12 (proposing micro-release 2.12.7.2) (#4509)
1 parent f5a84a5 commit 14be345

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

release-notes/CREDITS-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -1324,3 +1324,8 @@ Jelle Voost (jellevoost@github)
13241324
JoeWoo (xJoeWoo@github)
13251325
* Reported #3139: Deserialization of "empty" subtype with DEDUCTION failed
13261326
(2.12.4)
1327+
1328+
Jason Harper (jsharper@github)
1329+
* Reported #3275: JDK 16 Illegal reflective access for `Throwable.setCause()` with
1330+
`PropertyNamingStrategy.UPPER_CAMEL_CASE`
1331+
(2.12.7.2)

release-notes/VERSION-2.x

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.12.7.2 (not yet released)
8+
9+
#3275: JDK 16 Illegal reflective access for `Throwable.setCause()` with
10+
`PropertyNamingStrategy.UPPER_CAMEL_CASE`
11+
(reported by Jason H)
12+
713
2.12.7.1 (12-Oct-2022)
814

915
#3582: Add check in `BeanDeserializer._deserializeFromArray()` to prevent

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,17 @@ public JsonDeserializer<Object> buildThrowableDeserializer(DeserializationContex
425425

426426
// But then let's decorate things a bit
427427
// Need to add "initCause" as setter for exceptions (sub-classes of Throwable).
428+
// 26-May-2022, tatu: [databind#3275] Looks like JDK 12 added "setCause()"
429+
// which can wreak havoc, at least with NamingStrategy
430+
Iterator<SettableBeanProperty> it = builder.getProperties();
431+
while (it.hasNext()) {
432+
SettableBeanProperty prop = it.next();
433+
if ("setCause".equals(prop.getMember().getName())) {
434+
// For now this is allowed as we are returned "live" Iterator...
435+
it.remove();
436+
break;
437+
}
438+
}
428439
AnnotatedMethod am = beanDesc.findMethod("initCause", INIT_CAUSE_PARAMS);
429440
if (am != null) { // should never be null
430441
SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(ctxt.getConfig(), am,
@@ -454,10 +465,9 @@ public JsonDeserializer<Object> buildThrowableDeserializer(DeserializationContex
454465
}
455466
}
456467
JsonDeserializer<?> deserializer = builder.build();
457-
458-
/* At this point it ought to be a BeanDeserializer; if not, must assume
459-
* it's some other thing that can handle deserialization ok...
460-
*/
468+
469+
// At this point it ought to be a BeanDeserializer; if not, must assume
470+
// it's some other thing that can handle deserialization ok...
461471
if (deserializer instanceof BeanDeserializer) {
462472
deserializer = new ThrowableDeserializer((BeanDeserializer) deserializer);
463473
}

src/test/java/com/fasterxml/jackson/databind/exc/ExceptionDeserializationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void testLineNumberAsString() throws IOException
172172
assertNotNull(exc);
173173
}
174174

175-
// [databind#1842]:
175+
// [databind#1842]
176176
public void testNullAsMessage() throws IOException
177177
{
178178
Exception exc = MAPPER.readValue(aposToQuotes(

src/test/java/com/fasterxml/jackson/databind/exc/ExceptionSerializationTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
77
import com.fasterxml.jackson.core.JsonParser;
88
import com.fasterxml.jackson.databind.*;
9+
import com.fasterxml.jackson.databind.json.JsonMapper;
910

1011
/**
1112
* Unit tests for verifying that simple exceptions can be serialized.
@@ -132,4 +133,15 @@ public void testJsonMappingExceptionSerialization() throws IOException {
132133
fail("Exception should contain '"+MATCH+"', does not: '"+msg+"'");
133134
}
134135
}
136+
137+
// [databind#3275]
138+
public void testSerializeWithNamingStrategy() throws IOException {
139+
final ObjectMapper mapper = JsonMapper.builder()
140+
.propertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE)
141+
.build();
142+
String json = mapper.writeValueAsString(new Exception("message!"));
143+
Map<?,?> map = mapper.readValue(json, Map.class);
144+
assertEquals(new HashSet<>(Arrays.asList("Cause", "StackTrace", "Message", "Suppressed", "LocalizedMessage")),
145+
map.keySet());
146+
}
135147
}

0 commit comments

Comments
 (0)