Skip to content

Commit 5f3c7ca

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
1 parent a79eade commit 5f3c7ca

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
@@ -122,13 +122,18 @@ private Flux<TokenBuffer> endOfInput() {
122122
private List<TokenBuffer> parseTokenBufferFlux() throws IOException {
123123
List<TokenBuffer> result = new ArrayList<>();
124124

125-
while (true) {
125+
// SPR-16151: Smile data format uses null to separate documents
126+
boolean previousNull = false;
127+
while (!this.parser.isClosed()) {
126128
JsonToken token = this.parser.nextToken();
127-
// SPR-16151: Smile data format uses null to separate documents
128129
if (token == JsonToken.NOT_AVAILABLE ||
129-
(token == null && (token = this.parser.nextToken()) == null)) {
130+
token == null && previousNull) {
130131
break;
131132
}
133+
else if (token == null ) { // !previousNull
134+
previousNull = true;
135+
continue;
136+
}
132137
updateDepth(token);
133138
if (!this.tokenizeArrayElements) {
134139
processTokenNormal(token, result);
@@ -169,6 +174,9 @@ private void processTokenNormal(JsonToken token, List<TokenBuffer> result) throw
169174

170175
private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
171176
if (!isTopLevelArrayToken(token)) {
177+
if (!this.parser.hasCurrentToken()) {
178+
System.out.println("NO CURRENT TOKEN: " + token);
179+
}
172180
this.tokenBuffer.copyCurrentEvent(this.parser);
173181
}
174182

0 commit comments

Comments
 (0)