@@ -384,27 +384,47 @@ private void _verifyIsNumberToken() throws IOException
384
384
@ Override
385
385
public NumberType getNumberType () throws IOException
386
386
{
387
- IonType type = _reader .getType ();
388
- if (type != null ) {
389
- // Hmmh. Looks like Ion gives little bit looser definition here;
390
- // harder to pin down exact type. But let's try some checks still.
391
- switch (type ) {
392
- case DECIMAL :
393
- //Ion decimals can be arbitrary precision, need to read as big decimal
394
- return NumberType .BIG_DECIMAL ;
395
- case INT :
396
- IntegerSize size = _reader .getIntegerSize ();
397
- switch (size ) {
387
+ if (_currToken == JsonToken .VALUE_NUMBER_INT
388
+ || _currToken == JsonToken .VALUE_NUMBER_FLOAT
389
+ // 30-Dec-2023, tatu: This is odd, but some current tests seem to
390
+ // expect this case to work when creating `IonParser` from `IonReader`,
391
+ // which does not seem to work without work-around like this:
392
+ || ((_currToken == null ) && !isClosed ())) {
393
+ IonType type = _reader .getType ();
394
+ if (type != null ) {
395
+ // Hmmh. Looks like Ion gives little bit looser definition here;
396
+ // harder to pin down exact type. But let's try some checks still.
397
+ switch (type ) {
398
+ case DECIMAL :
399
+ //Ion decimals can be arbitrary precision, need to read as big decimal
400
+ return NumberType .BIG_DECIMAL ;
398
401
case INT :
399
- return NumberType .INT ;
400
- case LONG :
401
- return NumberType .LONG ;
402
+ final IntegerSize size ;
403
+ // [dataformats-binary#434]: another problem with corrupt data handling.
404
+ // Temporary measure until this bug fixing is merged and published
405
+ // https://github.com/amazon-ion/ion-java/issues/685
406
+ try {
407
+ size = _reader .getIntegerSize ();
408
+ } catch (IonException e ) {
409
+ return _reportCorruptNumber (e );
410
+ } catch (NullPointerException e ) {
411
+ return _reportCorruptContent (e );
412
+ }
413
+ if (size == null ) {
414
+ _reportError ("Current token (%s) not integer" , _currToken );
415
+ }
416
+ switch (size ) {
417
+ case INT :
418
+ return NumberType .INT ;
419
+ case LONG :
420
+ return NumberType .LONG ;
421
+ default :
422
+ return NumberType .BIG_INTEGER ;
423
+ }
424
+ case FLOAT :
425
+ return NumberType .DOUBLE ;
402
426
default :
403
- return NumberType .BIG_INTEGER ;
404
427
}
405
- case FLOAT :
406
- return NumberType .DOUBLE ;
407
- default :
408
428
}
409
429
}
410
430
return null ;
0 commit comments