diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java index 6cad2bbab6..5b35f10fd4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java @@ -1135,8 +1135,7 @@ public String writeValueAsString(Object value) throws JsonProcessingException { // alas, we have to pull the recycler directly here... - SegmentedStringWriter sw = new SegmentedStringWriter(_generatorFactory._getBufferRecycler()); - try { + try (SegmentedStringWriter sw = new SegmentedStringWriter(_generatorFactory._getBufferRecycler())) { _writeValueAndClose(createGenerator(sw), value); return sw.getAndClear(); } catch (JsonProcessingException e) {