Skip to content

Commit

Permalink
Minor post #943 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 6, 2023
1 parent 54f78a9 commit 6b57b33
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public abstract class JsonStreamContext
/**
* The nesting depth is a count of objects and arrays that have not
* been closed, `{` and `[` respectively.
*
* @since 2.15
*/
protected int _nestingDepth;

Expand Down Expand Up @@ -127,6 +129,8 @@ protected JsonStreamContext(int type, int index) {
/**
* The nesting depth is a count of objects and arrays that have not
* been closed, `{` and `[` respectively.
*
* @since 2.15
*/
public final int getNestingDepth() {
return _nestingDepth;
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/com/fasterxml/jackson/core/base/ParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,24 @@ protected float _getNumberFloat() throws JsonParseException {
return _numberFloat;
}

/*
/**********************************************************
/* Internal/package methods: Context handling (2.15)
/**********************************************************
*/

// @since 2.15
protected void createChildArrayContext(final int lineNr, final int colNr) throws IOException {
_parsingContext = _parsingContext.createChildArrayContext(lineNr, colNr);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
}

// @since 2.15
protected void createChildObjectContext(final int lineNr, final int colNr) throws IOException {
_parsingContext = _parsingContext.createChildObjectContext(lineNr, colNr);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
}

/*
/**********************************************************
/* Internal/package methods: Error reporting
Expand Down Expand Up @@ -1536,14 +1554,4 @@ protected void loadMoreGuaranteed() throws IOException {

// Can't declare as deprecated, for now, but shouldn't be needed
protected void _finishString() throws IOException { }

protected final void createChildArrayContext(final int lineNr, final int colNr) throws IOException {
_parsingContext = _parsingContext.createChildArrayContext(lineNr, colNr);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
}

protected final void createChildObjectContext(final int lineNr, final int colNr) throws IOException {
_parsingContext = _parsingContext.createChildObjectContext(lineNr, colNr);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public void testDeepNesting() throws Exception
{
final String DOC = createDeepNestedDoc(1050);
try (JsonParser jp = createParserUsingStream(new JsonFactory(), DOC, "UTF-8")) {
JsonToken jt;
while ((jt = jp.nextToken()) != null) {

}
while (jp.nextToken() != null) { }
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
assertEquals("Depth (1001) exceeds the maximum allowed nesting depth (1000)", e.getMessage());
Expand Down

0 comments on commit 6b57b33

Please sign in to comment.