Skip to content

Commit d4b80c5

Browse files
committed
Fix #302
1 parent aa043df commit d4b80c5

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,13 @@ public Object getEmbeddedObject() throws IOException {
436436
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
437437
switch (_reader.getType()) {
438438
case TIMESTAMP:
439-
return _reader.timestampValue();
439+
try {
440+
return _reader.timestampValue();
441+
} catch (IllegalArgumentException e) {
442+
throw _constructError(String.format(
443+
"Invalid embedded TIMESTAMP value, problem: %s", e.getMessage()),
444+
e);
445+
}
440446
case BLOB:
441447
case CLOB:
442448
return _reader.newBytes();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.fasterxml.jackson.dataformat.ion.misc;
2+
3+
import java.net.URL;
4+
import java.util.Arrays;
5+
6+
import org.junit.Test;
7+
8+
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* A set of unit tests for reported issues where implementation does
15+
* not catch exceptions like {@link NullPointerException} where it should.
16+
*/
17+
public class UncaughtExceptionsTest
18+
{
19+
private final IonObjectMapper MAPPER = IonObjectMapper.builder().build();
20+
21+
// [dataformats-binary#302]
22+
@Test
23+
public void testUncaughtException302() throws Exception
24+
{
25+
URL poc = getClass().getResource("/data/issue-302.ion");
26+
try {
27+
MAPPER.readTree(poc);
28+
fail("Should not pass with invalid content");
29+
} catch (JsonProcessingException e) {
30+
verifyException(e, "Invalid embedded TIMESTAMP");
31+
}
32+
}
33+
34+
void verifyException(Throwable e, String match)
35+
{
36+
String msg = e.getMessage();
37+
String lmsg = (msg == null) ? "" : msg.toLowerCase();
38+
if (lmsg.indexOf(match.toLowerCase()) < 0) {
39+
fail("Expected an exception with a substrings ("+match+"): got one with message \""+msg+"\"");
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(=V(#252222(=V(#252222(2_222-11-93((-84(22000n23mlock($0c

release-notes/CREDITS-2.x

+6
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,9 @@ Nick (manaigrn-amzn@github)
197197
* Contributed #270: (ion) Ion Polymorphic deserialization in 2.12 breaks wrt use of
198198
Native Type Ids when upgrading from 2.8
199199
(2.12.3)
200+
201+
ZanderHuang@github:
202+
203+
* Reported #302: `IllegalArgumentException` in `IonParser.getEmbeddedObject()`
204+
(2.12.6)
205+

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Modules:
1010
=== Releases ===
1111
------------------------------------------------------------------------
1212

13+
(not yet released)
14+
15+
#302: `IllegalArgumentException` in `IonParser.getEmbeddedObject()`
16+
(reported by ZanderHuang@github)
17+
1318
2.12.5 (27-Aug-2021)
1419

1520
No changes since 2.12.4

0 commit comments

Comments
 (0)