From b3587924ee5d8695942f364d0d404d48d0ea6126 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 12 Aug 2020 20:41:00 -0700 Subject: [PATCH] Add failing test for #2816 --- .../DeepNestingWithUntyped2816Test.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/failing/DeepNestingWithUntyped2816Test.java diff --git a/src/test/java/com/fasterxml/jackson/failing/DeepNestingWithUntyped2816Test.java b/src/test/java/com/fasterxml/jackson/failing/DeepNestingWithUntyped2816Test.java new file mode 100644 index 0000000000..86cf66f25f --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/failing/DeepNestingWithUntyped2816Test.java @@ -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(); + } +}