Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a failing test for InternCache churn on map keys #3859

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.util.InternCache;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

// for [core#946]
public class MapDeserializationInternStringsTest extends BaseMapTest
{
public void testArbitraryKeysDontChurnCache() throws IOException {
ObjectMapper mapper = new ObjectMapper();
String json = a2q("{'1st':'onedata','2nd':'twodata'}");
Map<String, String> expected = new HashMap<>();
expected.put("1st", "onedata");
expected.put("2nd", "twodata");
// Clear the InternCache before deserialization to avoid impact from other tests. Note that the
// cache is static state, and this test will not be meaningful in an environment where tests are
// executed in parallel.
InternCache.instance.clear();
Map<String, String> deserialized = mapper.readValue(json, new TypeReference<Map<String, String>>() {});
// Verify our test has done what we expect before asserting state on the InternCache.
assertEquals(expected, deserialized);
assertEquals("Arbitrary map key values should not be added to the InternCache because " +
"map keys may have greater cardinality than the InternCache expects",
Collections.emptyMap(), InternCache.instance);
Comment on lines +29 to +31
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with:

AssertionFailedError: Arbitrary map key values should not be added to the InternCache because map keys may have greater cardinality than the InternCache expects 
Expected :{}
Actual   :{1st=1st, 2nd=2nd}

}
}