Skip to content

Commit b309711

Browse files
authored
Fix #2593: improve StackTraceElement deserialization (#4842)
1 parent e33f7c4 commit b309711

File tree

6 files changed

+50
-17
lines changed

6 files changed

+50
-17
lines changed

pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@
300300
-->
301301
<ignore>java.beans.ConstructorProperties</ignore>
302302
<ignore>java.beans.Transient</ignore>
303+
<!-- 08-Dec-2024, tatu: [databind#2593] need to ignore "StackTraceElement"
304+
constructor(s)
305+
-->
306+
<ignore>java.lang.StackTraceElement</ignore>
303307
</ignores>
304308
</configuration>
305309
</plugin>

release-notes/CREDITS

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
Here are people who have contributed to the development of Jackson JSON processor
22
databind core component, version 3.x
3-
Version numbers in brackets indicate release in which the problem was fixed
3+
(version numbers in brackets indicate release in which the problem was fixed)
44

55
(note: for older credits, see `CREDITS-2.x` instead)
66

7-
Tatu Saloranta, [email protected]: author
7+
Author: Tatu Saloranta, [email protected]: author
88

9-
Alexander Koshman (akoshman@github)
9+
Co-Authors (with only partial listings below):
10+
11+
* Joo Hyuk Kim (@JooHyukKim)
12+
* PJ Fanning (@pjfanning)
13+
* Sim Yih Tsern (@yihtsern)
14+
15+
----------------------------------------------------------------------------
16+
17+
Alexander Koshman (@akoshman)
1018
* Requested #1600: Serializing locale with underscore, not standard hyphen
1119
[3.0.0]
1220

13-
XakepSDK@github
21+
@XakepSDK
1422
* Requested #2013: Allow use of `java.nio.file.Path` for `readValue()`, `writeValue()`
1523
[3.0.0]
1624
* Requested #2411: `valueToTree()` during serialization (via `SerializerProvider()`)
1725
[3.0.0]
1826

19-
Sven Döring (sdoeringNew@github)
27+
Sven Döring (@sdoeringNew)
2028
* Contributed #2013: Allow use of `java.nio.file.Path` for `readValue()`, `writeValue()`
2129
[3.0.0]
30+
31+
Michael Dillon (@michaelcdillon)
32+
#2593: StackTraceElement w/ >= Java 9 doesn't deserialize properly
33+
(requested by Michael D)
34+

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Versions: 3.x (for earlier see VERSION-2.x)
5050
(requested by XakepSDK@github)
5151
#2539: Add `Deserializers.hasDeserializerFor()` (and something for `DeserializerFactory`)
5252
to allow detection of explicitly supported types
53+
#2593: StackTraceElement w/ >= Java 9 doesn't deserialize properly
54+
(requested by Michael D)
5355
#2713: Change wording of `UnrecognizedPropertyException` to refer to "property" not "field"
5456
#2828: Add `DatabindException` as intermediate subtype of `JsonMappingException`
5557
#3028: Change `UUIDSerializer` to use `StreamWriteCapability` check instead of

src/main/java/tools/jackson/databind/deser/jdk/StackTraceElementDeserializer.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,18 @@ protected StackTraceElement constructValue(DeserializationContext ctxt,
7171
{
7272
// 21-May-2016, tatu: With Java 9, could use different constructor, probably
7373
// via different module, and throw exception here if extra args passed
74-
return new StackTraceElement(className, methodName, fileName, lineNumber);
74+
// 08-Dec-2024, tatu: With Jackson 3.0 can use full Java 9 introduced
75+
// constructor, finally
76+
return new StackTraceElement(classLoaderName, moduleName, moduleVersion,
77+
className, methodName, fileName, lineNumber);
7578
}
7679

7780
/**
7881
* Intermediate class used both for convenience of binding and
7982
* to support {@code PropertyNamingStrategy}.
83+
*<p>
84+
* NOTE: MUST remain {@code public} for JDK 17 at least to avoid
85+
* needing opening up access separately.
8086
*/
8187
public final static class Adapter {
8288
// NOTE: some String fields must not be nulls

src/test/java/tools/jackson/databind/exc/ExceptionDeserializationTest.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ public void testSingleValueArrayDeserialization() throws Exception
140140
@Test
141141
public void testExceptionCauseDeserialization() throws Exception
142142
{
143-
ObjectMapper mapper = new ObjectMapper();
144-
145143
final IOException exp = new IOException("the outer exception", new Throwable("the cause"));
146144

147-
final String value = mapper.writeValueAsString(exp);
148-
final IOException act = mapper.readValue(value, IOException.class);
145+
final String value = MAPPER.writeValueAsString(exp);
146+
final IOException act = MAPPER.readValue(value, IOException.class);
149147

150148
assertNotNull(act.getCause());
151149
assertEquals(exp.getCause().getMessage(), act.getCause().getMessage());
@@ -155,13 +153,11 @@ public void testExceptionCauseDeserialization() throws Exception
155153
@Test
156154
public void testSuppressedGenericThrowableDeserialization() throws Exception
157155
{
158-
ObjectMapper mapper = new ObjectMapper();
159-
160156
final IOException exp = new IOException("the outer exception");
161157
exp.addSuppressed(new Throwable("the suppressed exception"));
162158

163-
final String value = mapper.writeValueAsString(exp);
164-
final IOException act = mapper.readValue(value, IOException.class);
159+
final String value = MAPPER.writeValueAsString(exp);
160+
final IOException act = MAPPER.readValue(value, IOException.class);
165161

166162
assertNotNull(act.getSuppressed());
167163
assertEquals(1, act.getSuppressed().length);

src/test/java/tools/jackson/databind/exc/StackTraceElementTest.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import com.fasterxml.jackson.annotation.*;
66

77
import tools.jackson.databind.*;
8+
import tools.jackson.databind.testutil.DatabindTestUtil;
89

10+
import static org.junit.jupiter.api.Assertions.assertEquals;
911
import static org.junit.jupiter.api.Assertions.assertNotNull;
1012

11-
import static tools.jackson.databind.testutil.DatabindTestUtil.jsonMapperBuilder;
12-
1313
// for [databind#1794]
14-
public class StackTraceElementTest
14+
public class StackTraceElementTest extends DatabindTestUtil
1515
{
1616
public static class ErrorObject {
1717

@@ -46,4 +46,16 @@ public void testCustomStackTraceDeser() throws Exception
4646
ErrorObject result = mapper.readValue(json, ErrorObject.class);
4747
assertNotNull(result);
4848
}
49+
50+
// for [databind#2593]: missing fields (due to JDK 8 compatibility)
51+
@Test
52+
public void testAllFieldsDeserialized() throws Exception
53+
{
54+
final ObjectMapper mapper = sharedMapper();
55+
StackTraceElement input = new StackTraceElement("classLoaderX", "moduleY", "1.0",
56+
"MyClass", "MyMethod", "MyClass.java", 10);
57+
String json = mapper.writeValueAsString(input);
58+
StackTraceElement output = mapper.readValue(json, StackTraceElement.class);
59+
assertEquals(input, output);
60+
}
4961
}

0 commit comments

Comments
 (0)