Skip to content

Commit

Permalink
Fix #2593: improve StackTraceElement deserialization (#4842)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Dec 9, 2024
1 parent e33f7c4 commit b309711
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@
-->
<ignore>java.beans.ConstructorProperties</ignore>
<ignore>java.beans.Transient</ignore>
<!-- 08-Dec-2024, tatu: [databind#2593] need to ignore "StackTraceElement"
constructor(s)
-->
<ignore>java.lang.StackTraceElement</ignore>
</ignores>
</configuration>
</plugin>
Expand Down
23 changes: 18 additions & 5 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
Here are people who have contributed to the development of Jackson JSON processor
databind core component, version 3.x
Version numbers in brackets indicate release in which the problem was fixed
(version numbers in brackets indicate release in which the problem was fixed)

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

Tatu Saloranta, [email protected]: author
Author: Tatu Saloranta, [email protected]: author

Alexander Koshman (akoshman@github)
Co-Authors (with only partial listings below):

* Joo Hyuk Kim (@JooHyukKim)
* PJ Fanning (@pjfanning)
* Sim Yih Tsern (@yihtsern)

----------------------------------------------------------------------------

Alexander Koshman (@akoshman)
* Requested #1600: Serializing locale with underscore, not standard hyphen
[3.0.0]

XakepSDK@github
@XakepSDK
* Requested #2013: Allow use of `java.nio.file.Path` for `readValue()`, `writeValue()`
[3.0.0]
* Requested #2411: `valueToTree()` during serialization (via `SerializerProvider()`)
[3.0.0]

Sven Döring (sdoeringNew@github)
Sven Döring (@sdoeringNew)
* Contributed #2013: Allow use of `java.nio.file.Path` for `readValue()`, `writeValue()`
[3.0.0]

Michael Dillon (@michaelcdillon)
#2593: StackTraceElement w/ >= Java 9 doesn't deserialize properly
(requested by Michael D)

2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Versions: 3.x (for earlier see VERSION-2.x)
(requested by XakepSDK@github)
#2539: Add `Deserializers.hasDeserializerFor()` (and something for `DeserializerFactory`)
to allow detection of explicitly supported types
#2593: StackTraceElement w/ >= Java 9 doesn't deserialize properly
(requested by Michael D)
#2713: Change wording of `UnrecognizedPropertyException` to refer to "property" not "field"
#2828: Add `DatabindException` as intermediate subtype of `JsonMappingException`
#3028: Change `UUIDSerializer` to use `StreamWriteCapability` check instead of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ protected StackTraceElement constructValue(DeserializationContext ctxt,
{
// 21-May-2016, tatu: With Java 9, could use different constructor, probably
// via different module, and throw exception here if extra args passed
return new StackTraceElement(className, methodName, fileName, lineNumber);
// 08-Dec-2024, tatu: With Jackson 3.0 can use full Java 9 introduced
// constructor, finally
return new StackTraceElement(classLoaderName, moduleName, moduleVersion,
className, methodName, fileName, lineNumber);
}

/**
* Intermediate class used both for convenience of binding and
* to support {@code PropertyNamingStrategy}.
*<p>
* NOTE: MUST remain {@code public} for JDK 17 at least to avoid
* needing opening up access separately.
*/
public final static class Adapter {
// NOTE: some String fields must not be nulls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ public void testSingleValueArrayDeserialization() throws Exception
@Test
public void testExceptionCauseDeserialization() throws Exception
{
ObjectMapper mapper = new ObjectMapper();

final IOException exp = new IOException("the outer exception", new Throwable("the cause"));

final String value = mapper.writeValueAsString(exp);
final IOException act = mapper.readValue(value, IOException.class);
final String value = MAPPER.writeValueAsString(exp);
final IOException act = MAPPER.readValue(value, IOException.class);

assertNotNull(act.getCause());
assertEquals(exp.getCause().getMessage(), act.getCause().getMessage());
Expand All @@ -155,13 +153,11 @@ public void testExceptionCauseDeserialization() throws Exception
@Test
public void testSuppressedGenericThrowableDeserialization() throws Exception
{
ObjectMapper mapper = new ObjectMapper();

final IOException exp = new IOException("the outer exception");
exp.addSuppressed(new Throwable("the suppressed exception"));

final String value = mapper.writeValueAsString(exp);
final IOException act = mapper.readValue(value, IOException.class);
final String value = MAPPER.writeValueAsString(exp);
final IOException act = MAPPER.readValue(value, IOException.class);

assertNotNull(act.getSuppressed());
assertEquals(1, act.getSuppressed().length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import com.fasterxml.jackson.annotation.*;

import tools.jackson.databind.*;
import tools.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import static tools.jackson.databind.testutil.DatabindTestUtil.jsonMapperBuilder;

// for [databind#1794]
public class StackTraceElementTest
public class StackTraceElementTest extends DatabindTestUtil
{
public static class ErrorObject {

Expand Down Expand Up @@ -46,4 +46,16 @@ public void testCustomStackTraceDeser() throws Exception
ErrorObject result = mapper.readValue(json, ErrorObject.class);
assertNotNull(result);
}

// for [databind#2593]: missing fields (due to JDK 8 compatibility)
@Test
public void testAllFieldsDeserialized() throws Exception
{
final ObjectMapper mapper = sharedMapper();
StackTraceElement input = new StackTraceElement("classLoaderX", "moduleY", "1.0",
"MyClass", "MyMethod", "MyClass.java", 10);
String json = mapper.writeValueAsString(input);
StackTraceElement output = mapper.readValue(json, StackTraceElement.class);
assertEquals(input, output);
}
}

0 comments on commit b309711

Please sign in to comment.