@@ -536,8 +536,8 @@ public JsonToken nextToken() throws IOException
536
536
// should we change description based on reserved vs illegal? (special cases
537
537
// of null bytes etc)
538
538
private JsonToken _reportUnknownValueTypeToken (int ch ) throws IOException {
539
- _reportError ("Invalid type marker byte 0x" + Integer . toHexString ( ch & 0xFF )+ " for expected value token");
540
- return null ;
539
+ throw _constructReadException ("Invalid type marker byte 0x%s for expected value token" ,
540
+ Integer . toHexString ( ch & 0xFF )) ;
541
541
}
542
542
543
543
// Helper method called in situations where Smile Header was encountered
@@ -877,8 +877,8 @@ public String nextFieldName() throws IOException
877
877
// Should we try to give more information on kind of problem (reserved vs
878
878
// illegal by definition; suggesting likely problem)
879
879
private String _reportUnknownNameToken (int ch ) throws IOException {
880
- _reportError ("Invalid type marker byte 0x" + Integer . toHexString ( ch & 0xFF )+ " for expected field name (or END_OBJECT marker)");
881
- return null ;
880
+ throw _constructReadException ("Invalid type marker byte 0x%s for expected field name (or END_OBJECT marker)" ,
881
+ Integer . toHexString ( ch & 0xFF )) ;
882
882
}
883
883
884
884
@ Override
@@ -1211,7 +1211,9 @@ public byte[] getBinaryValue(Base64Variant b64variant) throws IOException
1211
1211
} else if (_currToken == JsonToken .VALUE_STRING ) {
1212
1212
return _getBinaryFromString (b64variant );
1213
1213
} else {
1214
- _reportError ("Current token (" +currentToken ()+") not VALUE_EMBEDDED_OBJECT, can not access as binary" );
1214
+ throw _constructReadException (
1215
+ "Current token (%s) not VALUE_EMBEDDED_OBJECT or VALUE_STRING, can not access as binary" ,
1216
+ currentToken ());
1215
1217
}
1216
1218
return _binaryValue ;
1217
1219
}
@@ -1240,7 +1242,9 @@ public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IO
1240
1242
out .write (b , 0 , len );
1241
1243
return len ;
1242
1244
}
1243
- _reportError ("Current token (" +currentToken ()+") not VALUE_EMBEDDED_OBJECT, can not access as binary" );
1245
+ throw _constructReadException (
1246
+ "Current token (%s) not VALUE_EMBEDDED_OBJECT or VALUE_STRING, can not access as binary" ,
1247
+ currentToken ());
1244
1248
}
1245
1249
// Ok, first, unlikely (but legal?) case where someone already requested binary data:
1246
1250
if (!_tokenIncomplete ) {
@@ -1448,8 +1452,8 @@ protected final JsonToken _handleFieldName() throws IOException
1448
1452
break ;
1449
1453
}
1450
1454
// Other byte values are illegal
1451
- _reportError ("Invalid type marker byte 0x" + Integer . toHexString ( _typeAsInt )+ " for expected field name (or END_OBJECT marker)");
1452
- return null ;
1455
+ throw _constructReadException ("Invalid type marker byte 0x%s for expected field name (or END_OBJECT marker)" ,
1456
+ Integer . toHexString ( _typeAsInt )) ;
1453
1457
}
1454
1458
1455
1459
private String _findOrDecodeShortAsciiName (final int len ) throws IOException
@@ -1609,7 +1613,8 @@ private final String _decodeShortUnicodeName(int len)
1609
1613
default : // invalid
1610
1614
// Update pointer here to point to (more) correct location
1611
1615
_inputPtr = inPtr ;
1612
- _reportError (String .format ("Invalid byte 0x%02X in short Unicode text block" , i ));
1616
+ throw _constructReadException (
1617
+ "Invalid byte 0x%02X in short Unicode text block" , i );
1613
1618
}
1614
1619
}
1615
1620
outBuf [outPtr ++] = (char ) i ;
@@ -2454,7 +2459,7 @@ protected final String _decodeShortUnicodeValue(final int byteLen) throws IOExce
2454
2459
i = 0xDC00 | (i & 0x3FF );
2455
2460
break ;
2456
2461
default : // invalid
2457
- _reportError ( String . format ( "Invalid byte 0x%02X in short Unicode text block" , i ) );
2462
+ throw _constructReadException ( "Invalid byte 0x%02X in short Unicode text block" , i );
2458
2463
}
2459
2464
outBuf [outPtr ++] = (char ) i ;
2460
2465
}
@@ -3060,7 +3065,7 @@ protected String _reportTruncatedUTF8InString(int strLenBytes, int truncatedChar
3060
3065
int firstUTFByteValue , int bytesExpected )
3061
3066
throws IOException
3062
3067
{
3063
- throw _constructError (String .format (
3068
+ throw _constructReadException (String .format (
3064
3069
"Truncated UTF-8 character in Short Unicode String value (%d bytes): "
3065
3070
+"byte 0x%02X at offset #%d indicated %d more bytes needed" ,
3066
3071
strLenBytes , firstUTFByteValue , truncatedCharOffset , bytesExpected ));
0 commit comments