Skip to content

Commit

Permalink
Fix #1125
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 12, 2023
1 parent 3303d15 commit 08a4ed4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 73 deletions.
2 changes: 1 addition & 1 deletion release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 0 additions & 21 deletions src/main/java/tools/jackson/core/TokenStreamFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <a href="https://github.com/FasterXML/jackson-core/issues/189">Issue #189</a>
* for a possible case)
*<p>
* 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
Expand Down Expand Up @@ -1233,12 +1218,6 @@ public BufferRecycler _getBufferRecycler()
* {@link BufferRecycler} instance to use.
*/
public RecyclerPool<BufferRecycler> _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;
}

Expand Down
51 changes: 0 additions & 51 deletions src/test/java/tools/jackson/core/json/JsonFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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);
Expand Down

0 comments on commit 08a4ed4

Please sign in to comment.