diff --git a/release-notes/VERSION b/release-notes/VERSION index 18caf15a90..fb87ce6047 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -26,6 +26,7 @@ Project: jackson-databind #1211: Change `JsonValueSerializer` to get `AnnotatedMethod`, not "raw" method #1217: `@JsonIgnoreProperties` on Pojo fields not working for deserialization (reported by Lokesh K) +#1221: Use `Throwable.addSuppressed()` directly and/or via try-with-resources 2.7.4 (29-Apr-2016) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index bca0d70612..860bc57e7e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -3718,15 +3718,15 @@ private final void _writeCloseableValue(JsonGenerator g, Object value, Serializa * for deserializing a single root value. * Can be overridden if a custom context is needed. */ - protected DefaultDeserializationContext createDeserializationContext(JsonParser jp, + protected DefaultDeserializationContext createDeserializationContext(JsonParser p, DeserializationConfig cfg) { - return _deserializationContext.createInstance(cfg, jp, _injectableValues); + return _deserializationContext.createInstance(cfg, p, _injectableValues); } /** * Actual implementation of value reading+binding operation. */ - protected Object _readValue(DeserializationConfig cfg, JsonParser jp, JavaType valueType) + protected Object _readValue(DeserializationConfig cfg, JsonParser p, JavaType valueType) throws IOException { /* First: may need to read the next token, to initialize @@ -3734,59 +3734,55 @@ protected Object _readValue(DeserializationConfig cfg, JsonParser jp, JavaType v * previous token has been cleared) */ Object result; - JsonToken t = _initForReading(jp); + JsonToken t = _initForReading(p); if (t == JsonToken.VALUE_NULL) { - // [JACKSON-643]: Ask JsonDeserializer what 'null value' to use: - DeserializationContext ctxt = createDeserializationContext(jp, cfg); + // Ask JsonDeserializer what 'null value' to use: + DeserializationContext ctxt = createDeserializationContext(p, cfg); result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt); } else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) { result = null; } else { // pointing to event other than null - DeserializationContext ctxt = createDeserializationContext(jp, cfg); + DeserializationContext ctxt = createDeserializationContext(p, cfg); JsonDeserializer deser = _findRootDeserializer(ctxt, valueType); // ok, let's get the value if (cfg.useRootWrapping()) { - result = _unwrapAndDeserialize(jp, ctxt, cfg, valueType, deser); + result = _unwrapAndDeserialize(p, ctxt, cfg, valueType, deser); } else { - result = deser.deserialize(jp, ctxt); + result = deser.deserialize(p, ctxt); } } // Need to consume the token too - jp.clearCurrentToken(); + p.clearCurrentToken(); return result; } - protected Object _readMapAndClose(JsonParser jp, JavaType valueType) + protected Object _readMapAndClose(JsonParser p0, JavaType valueType) throws IOException { - try { + try (JsonParser p = p0) { Object result; - JsonToken t = _initForReading(jp); + JsonToken t = _initForReading(p); if (t == JsonToken.VALUE_NULL) { - // [JACKSON-643]: Ask JsonDeserializer what 'null value' to use: - DeserializationContext ctxt = createDeserializationContext(jp, + // Ask JsonDeserializer what 'null value' to use: + DeserializationContext ctxt = createDeserializationContext(p, getDeserializationConfig()); result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt); } else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) { result = null; } else { DeserializationConfig cfg = getDeserializationConfig(); - DeserializationContext ctxt = createDeserializationContext(jp, cfg); + DeserializationContext ctxt = createDeserializationContext(p, cfg); JsonDeserializer deser = _findRootDeserializer(ctxt, valueType); if (cfg.useRootWrapping()) { - result = _unwrapAndDeserialize(jp, ctxt, cfg, valueType, deser); + result = _unwrapAndDeserialize(p, ctxt, cfg, valueType, deser); } else { - result = deser.deserialize(jp, ctxt); + result = deser.deserialize(p, ctxt); } ctxt.checkUnresolvedObjectId(); } // Need to consume the token too - jp.clearCurrentToken(); + p.clearCurrentToken(); return result; - } finally { - try { - jp.close(); - } catch (IOException ioe) { } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java b/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java index 1d4c386d12..21c1fbc949 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java @@ -1554,9 +1554,9 @@ protected JsonParser _considerFilter(final JsonParser p, boolean multiValue) { ? p : new FilteringParserDelegate(p, _filter, false, multiValue); } - protected Object _bindAndClose(JsonParser p) throws IOException + protected Object _bindAndClose(JsonParser p0) throws IOException { - try { + try (JsonParser p = p0) { Object result; JsonToken t = _initForReading(p); if (t == JsonToken.VALUE_NULL) { @@ -1583,20 +1583,12 @@ protected Object _bindAndClose(JsonParser p) throws IOException } } return result; - } finally { - try { - p.close(); - } catch (IOException ioe) { } } } - protected JsonNode _bindAndCloseAsTree(JsonParser p) throws IOException { - try { + protected JsonNode _bindAndCloseAsTree(JsonParser p0) throws IOException { + try (JsonParser p = p0) { return _bindAsTree(p); - } finally { - try { - p.close(); - } catch (IOException ioe) { } } }