Skip to content

Commit 0b03305

Browse files
committed
0xC1 NEVER_USED always throws MessageNeverUsedFormatException regardless of context rather than MessageTypeException or MessageFormatException depending on context
1 parent f45be09 commit 0b03305

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public void skipValue()
449449
remainingValues += readNextLength32() * 2; // TODO check int overflow
450450
break;
451451
case NEVER_USED:
452-
throw new MessageFormatException(String.format("unknown code: %02x is found", b));
452+
throw new MessageNeverUsedFormatException("Encountered 0xC1 \"NEVER_USED\" byte");
453453
}
454454

455455
remainingValues--;
@@ -464,19 +464,17 @@ public void skipValue()
464464
* @return
465465
* @throws MessageFormatException
466466
*/
467-
private static MessageTypeException unexpected(String expected, byte b)
468-
throws MessageTypeException
467+
private static MessagePackException unexpected(String expected, byte b)
469468
{
470469
MessageFormat format = MessageFormat.valueOf(b);
471-
String typeName;
472470
if (format == MessageFormat.NEVER_USED) {
473-
typeName = "NeverUsed";
471+
return new MessageNeverUsedFormatException(String.format("Expected %s, but encountered 0xC1 \"NEVER_USED\" byte", expected));
474472
}
475473
else {
476474
String name = format.getValueType().name();
477-
typeName = name.substring(0, 1) + name.substring(1).toLowerCase();
475+
String typeName = name.substring(0, 1) + name.substring(1).toLowerCase();
476+
return new MessageTypeException(String.format("Expected %s, but got %s (%02x)", expected, typeName, b));
478477
}
479-
return new MessageTypeException(String.format("Expected %s, but got %s (%02x)", expected, typeName, b));
480478
}
481479

482480
public ImmutableValue unpackValue()
@@ -530,7 +528,7 @@ public ImmutableValue unpackValue()
530528
return ValueFactory.newExtension(extHeader.getType(), readPayload(extHeader.getLength()));
531529
}
532530
default:
533-
throw new MessageFormatException("Unknown value type");
531+
throw new MessageNeverUsedFormatException("Unknown value type");
534532
}
535533
}
536534

0 commit comments

Comments
 (0)