Skip to content

Commit

Permalink
Fix #302
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 2, 2021
1 parent aa043df commit d4b80c5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,13 @@ public Object getEmbeddedObject() throws IOException {
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
switch (_reader.getType()) {
case TIMESTAMP:
return _reader.timestampValue();
try {
return _reader.timestampValue();
} catch (IllegalArgumentException e) {
throw _constructError(String.format(
"Invalid embedded TIMESTAMP value, problem: %s", e.getMessage()),
e);
}
case BLOB:
case CLOB:
return _reader.newBytes();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fasterxml.jackson.dataformat.ion.misc;

import java.net.URL;
import java.util.Arrays;

import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;

import static org.junit.Assert.*;

/**
* A set of unit tests for reported issues where implementation does
* not catch exceptions like {@link NullPointerException} where it should.
*/
public class UncaughtExceptionsTest
{
private final IonObjectMapper MAPPER = IonObjectMapper.builder().build();

// [dataformats-binary#302]
@Test
public void testUncaughtException302() throws Exception
{
URL poc = getClass().getResource("/data/issue-302.ion");
try {
MAPPER.readTree(poc);
fail("Should not pass with invalid content");
} catch (JsonProcessingException e) {
verifyException(e, "Invalid embedded TIMESTAMP");
}
}

void verifyException(Throwable e, String match)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
if (lmsg.indexOf(match.toLowerCase()) < 0) {
fail("Expected an exception with a substrings ("+match+"): got one with message \""+msg+"\"");
}
}
}
1 change: 1 addition & 0 deletions ion/src/test/resources/data/issue-302.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(=V(#252222(=V(#252222(2_222-11-93((-84(22000n23mlock($0c
6 changes: 6 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,9 @@ Nick (manaigrn-amzn@github)
* Contributed #270: (ion) Ion Polymorphic deserialization in 2.12 breaks wrt use of
Native Type Ids when upgrading from 2.8
(2.12.3)
ZanderHuang@github:
* Reported #302: `IllegalArgumentException` in `IonParser.getEmbeddedObject()`
(2.12.6)
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

(not yet released)

#302: `IllegalArgumentException` in `IonParser.getEmbeddedObject()`
(reported by ZanderHuang@github)

2.12.5 (27-Aug-2021)

No changes since 2.12.4
Expand Down

0 comments on commit d4b80c5

Please sign in to comment.