Skip to content

Commit ae03bb8

Browse files
committed
Merge pull request msgpack#207 from kutchar/fix-next-token-eof-exception
Fixing the contract of nextToken to be compliant with com.fasterxml.jackson.core.JsonParser.nextToken(), fixes msgpack#206
2 parents a788b01 + 44be495 commit ae03bb8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public JsonToken nextToken() throws IOException, JsonParseException {
118118
}
119119
}
120120

121+
if (!messageUnpacker.hasNext()) {
122+
return null;
123+
}
124+
121125
MessageFormat nextFormat = messageUnpacker.getNextFormat();
122126
ValueType valueType = nextFormat.getValueType();
123127

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackParserTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertArrayEquals;
2121
import static org.junit.Assert.assertTrue;
22+
import static org.junit.Assert.assertNull;
2223

2324
public class MessagePackParserTest extends MessagePackDataformatTestBase {
2425
@Test
@@ -309,13 +310,8 @@ public void testMessagePackParserDirectly() throws IOException {
309310
assertEquals(-1, parser.getCurrentLocation().getLineNr());
310311
assertEquals(16, parser.getCurrentLocation().getColumnNr());
311312

312-
try {
313-
parser.nextToken();
314-
assertTrue(false);
315-
}
316-
catch (EOFException e) {
317-
// Expected
318-
}
313+
assertNull(parser.nextToken());
314+
319315
parser.close();
320316
parser.close(); // Intentional
321317
}

0 commit comments

Comments
 (0)