From d4b80c532f1c89f70c7f42d555c796b91203a030 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 1 Nov 2021 20:37:23 -0700 Subject: [PATCH] Fix #302 --- .../jackson/dataformat/ion/IonParser.java | 8 +++- .../ion/misc/UncaughtExceptionsTest.java | 42 +++++++++++++++++++ ion/src/test/resources/data/issue-302.ion | 1 + release-notes/CREDITS-2.x | 6 +++ release-notes/VERSION-2.x | 5 +++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 ion/src/test/java/com/fasterxml/jackson/dataformat/ion/misc/UncaughtExceptionsTest.java create mode 100644 ion/src/test/resources/data/issue-302.ion diff --git a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java index ac731ccad..972dd4c21 100644 --- a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java +++ b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java @@ -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(); diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/misc/UncaughtExceptionsTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/misc/UncaughtExceptionsTest.java new file mode 100644 index 000000000..b1ff1bb1c --- /dev/null +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/misc/UncaughtExceptionsTest.java @@ -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+"\""); + } + } +} diff --git a/ion/src/test/resources/data/issue-302.ion b/ion/src/test/resources/data/issue-302.ion new file mode 100644 index 000000000..590a93966 --- /dev/null +++ b/ion/src/test/resources/data/issue-302.ion @@ -0,0 +1 @@ +(=V(#252222(=V(#252222(2_222-11-93((-84(22000n23mlock($0c \ No newline at end of file diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index aba3d1d71..f548f8c04 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -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) + diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index da15a802f..cea208076 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -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