@@ -1721,6 +1721,7 @@ private long CalcEncodedSize(int depth) {
17211721 if (depth > 1000 ) {
17221722 throw new CBORException ("Too deeply nested" );
17231723 }
1724+ //System.out.println("type="+this.getType()+" depth="+depth);
17241725 long size = 0L ;
17251726 CBORObject cbor = this ;
17261727 while (cbor .isTagged ()) {
@@ -1768,11 +1769,19 @@ private long CalcEncodedSize(int depth) {
17681769 Collection <Map .Entry <CBORObject , CBORObject >> entries =
17691770 this .getEntries ();
17701771 size = (size + IntegerByteLength (entries .size ()));
1771- for (Map .Entry <CBORObject , CBORObject > entry : entries ) {
1772- CBORObject key = entry .getKey ();
1773- CBORObject value = entry .getValue ();
1774- size = (size + key .CalcEncodedSize (depth + 1 ));
1775- size = (size + value .CalcEncodedSize (depth + 1 ));
1772+ try {
1773+ for (Map .Entry <CBORObject , CBORObject > entry : entries ) {
1774+ CBORObject key = entry .getKey ();
1775+ CBORObject value = entry .getValue ();
1776+ size = (size + key .CalcEncodedSize (depth + 1 ));
1777+ size = (size + value .CalcEncodedSize (depth + 1 ));
1778+ }
1779+ } catch (IllegalStateException ex ) {
1780+ // Additional error that may occur in iteration
1781+ throw new CBORException (ex .getMessage (), ex );
1782+ } catch (IllegalArgumentException ex ) {
1783+ // Additional error that may occur in iteration
1784+ throw new CBORException (ex .getMessage (), ex );
17761785 }
17771786 return size ;
17781787 }
0 commit comments