From 08a4ed4ac2a9e62b18065fedc66938cdbc4538d6 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 11 Oct 2023 20:43:14 -0700 Subject: [PATCH] Fix #1125 --- release-notes/VERSION | 2 +- .../jackson/core/TokenStreamFactory.java | 21 -------- .../jackson/core/json/JsonFactoryTest.java | 51 ------------------- 3 files changed, 1 insertion(+), 73 deletions(-) diff --git a/release-notes/VERSION b/release-notes/VERSION index bfa15536bd..c78d44dcf3 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -39,7 +39,7 @@ JSON library. #785: Make `JsonGenerator.writeXxx()` methods chainable #793: Rename "com.fasterxml.jackson" -> "tools.jackson" #1090: Remove `BufferRecyclers.SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS` - functionality from 3.0 +#1125: Remove `TokenStreamFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING` - Rename `JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT` as `AUTO_CLOSE_CONTENT` - Add `TreeCodec.nullNode()`, `TreeNode.isNull()` methods - Change the way `JsonLocation.NA` is included in exception messages diff --git a/src/main/java/tools/jackson/core/TokenStreamFactory.java b/src/main/java/tools/jackson/core/TokenStreamFactory.java index 179cc5152a..586d314741 100644 --- a/src/main/java/tools/jackson/core/TokenStreamFactory.java +++ b/src/main/java/tools/jackson/core/TokenStreamFactory.java @@ -113,21 +113,6 @@ public enum Feature */ FAIL_ON_SYMBOL_HASH_OVERFLOW(true), - /** - * Feature that determines whether we will use {@link BufferRecycler} with - * {@link ThreadLocal} and {@link SoftReference}, for efficient reuse of - * underlying input/output buffers. - * This usually makes sense on normal J2SE/J2EE server-side processing; - * but may not make sense on platforms where {@link SoftReference} handling - * is broken (like Android), or if there are retention issues due to - * {@link ThreadLocal} (see - * Issue #189 - * for a possible case) - *

- * This setting is enabled by default. - */ - USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING(true), - /** * Feature to control charset detection for byte-based inputs ({@code byte[]}, {@link InputStream}...). When * this feature is enabled (the default), the factory will allow UTF-16 and UTF-32 inputs and try to detect @@ -1233,12 +1218,6 @@ public BufferRecycler _getBufferRecycler() * {@link BufferRecycler} instance to use. */ public RecyclerPool _getRecyclerPool() { - // 23-Apr-2015, tatu: Let's allow disabling of buffer recycling - // scheme, for cases where it is considered harmful (possibly - // on Android, for example) - if (!Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING.enabledIn(_factoryFeatures)) { - return JsonRecyclerPools.nonRecyclingPool(); - } return _recyclerPool; } diff --git a/src/test/java/tools/jackson/core/json/JsonFactoryTest.java b/src/test/java/tools/jackson/core/json/JsonFactoryTest.java index fe6ff80426..8513ba8792 100644 --- a/src/test/java/tools/jackson/core/json/JsonFactoryTest.java +++ b/src/test/java/tools/jackson/core/json/JsonFactoryTest.java @@ -61,12 +61,6 @@ public void testFactoryFeatures() throws Exception .build(); assertFalse(f.isEnabled(JsonFactory.Feature.INTERN_PROPERTY_NAMES)); - // by default, should be enabled - assertTrue(f.isEnabled(JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING)); - f = f.rebuild().disable(JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING) - .build(); - assertFalse(f.isEnabled(JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING)); - assertFalse(f.canHandleBinaryNatively()); } @@ -82,51 +76,6 @@ public void testFactoryMisc() throws Exception assertEquals(JsonWriteFeature.class, JSON_F.getFormatWriteFeatureType()); } - // for [core#189]: verify that it's ok to disable recycling - // Basically simply exercises basic functionality, to ensure - // there are no obvious problems; needed since testing never - // disables this handling otherwise - public void testDisablingBufferRecycling() throws Exception - { - JsonFactory f = JsonFactory.builder() - .disable(JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING) - .build(); - - // First, generation - for (int i = 0; i < 3; ++i) { - StringWriter w = new StringWriter(); - JsonGenerator gen = f.createGenerator(ObjectWriteContext.empty(), w); - gen.writeStartObject(); - gen.writeEndObject(); - gen.close(); - assertEquals("{}", w.toString()); - } - - for (int i = 0; i < 3; ++i) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - JsonGenerator gen = f.createGenerator(ObjectWriteContext.empty(), bytes); - gen.writeStartArray(); - gen.writeEndArray(); - gen.close(); - assertEquals("[]", bytes.toString("UTF-8")); - } - - // Then parsing: - for (int i = 0; i < 3; ++i) { - JsonParser p = f.createParser(ObjectReadContext.empty(), "{}"); - assertToken(JsonToken.START_OBJECT, p.nextToken()); - assertToken(JsonToken.END_OBJECT, p.nextToken()); - assertNull(p.nextToken()); - p.close(); - - p = f.createParser(ObjectReadContext.empty(), "{}".getBytes("UTF-8")); - assertToken(JsonToken.START_OBJECT, p.nextToken()); - assertToken(JsonToken.END_OBJECT, p.nextToken()); - assertNull(p.nextToken()); - p.close(); - } - } - public void testJsonWithFiles() throws Exception { File file = File.createTempFile("jackson-test", null);