Skip to content

Commit

Permalink
Add failing test for #2816
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 13, 2020
1 parent 0e1cd09 commit b358792
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.fasterxml.jackson.failing;

import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.*;

// [databind#2816]
public class DeepNestingWithUntyped2816Test extends BaseMapTest
{
// 2000 passes, 3000 fails
private final static int TOO_DEEP_NESTING = 4000;

private final ObjectMapper MAPPER = newJsonMapper();

public void testWithArray() throws Exception
{
final String doc = _nestedDoc(TOO_DEEP_NESTING, "[ ", "] ");
Object ob = MAPPER.readValue(doc, Object.class);
assertTrue(ob instanceof List<?>);
}

public void testWithObject() throws Exception
{
final String doc = "{"+_nestedDoc(TOO_DEEP_NESTING, "\"x\":{", "} ") + "}";
Object ob = MAPPER.readValue(doc, Object.class);
assertTrue(ob instanceof Map<?,?>);
}

private String _nestedDoc(int nesting, String open, String close) {
StringBuilder sb = new StringBuilder(nesting * (open.length() + close.length()));
for (int i = 0; i < nesting; ++i) {
sb.append(open);
if ((i & 31) == 0) {
sb.append("\n");
}
}
for (int i = 0; i < nesting; ++i) {
sb.append(close);
if ((i & 31) == 0) {
sb.append("\n");
}
}
return sb.toString();
}
}

0 comments on commit b358792

Please sign in to comment.