Skip to content

Commit c164759

Browse files
committed
Fix NullPointerException in Jackson2SmileDecoder
Fix uncommon case in Jackson2SmileDecoder, where a null token, incicating a document separator in streaming mode, is followed by NOT_AVAILABLE. Closes gh-24009 (cherry picked from commit 5f3c7ca)
1 parent 2179b67 commit c164759

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,18 @@ private Flux<TokenBuffer> endOfInput() {
120120
private List<TokenBuffer> parseTokenBufferFlux() throws IOException {
121121
List<TokenBuffer> result = new ArrayList<>();
122122

123-
while (true) {
123+
// SPR-16151: Smile data format uses null to separate documents
124+
boolean previousNull = false;
125+
while (!this.parser.isClosed()) {
124126
JsonToken token = this.parser.nextToken();
125-
// SPR-16151: Smile data format uses null to separate documents
126127
if (token == JsonToken.NOT_AVAILABLE ||
127-
(token == null && (token = this.parser.nextToken()) == null)) {
128+
token == null && previousNull) {
128129
break;
129130
}
131+
else if (token == null ) { // !previousNull
132+
previousNull = true;
133+
continue;
134+
}
130135
updateDepth(token);
131136
if (!this.tokenizeArrayElements) {
132137
processTokenNormal(token, result);
@@ -167,6 +172,9 @@ private void processTokenNormal(JsonToken token, List<TokenBuffer> result) throw
167172

168173
private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
169174
if (!isTopLevelArrayToken(token)) {
175+
if (!this.parser.hasCurrentToken()) {
176+
System.out.println("NO CURRENT TOKEN: " + token);
177+
}
170178
this.tokenBuffer.copyCurrentEvent(this.parser);
171179
}
172180

0 commit comments

Comments
 (0)