Throw an explicit error instead of a NullPointerException

This commit is contained in:
Jeremy Lakeman 2014-03-12 13:48:37 +10:30
parent ee68856878
commit f0ce85bd8d

View File

@ -46,6 +46,8 @@ public abstract class AbstractId {
private final byte[] binary;
public AbstractId(String hex) throws InvalidHexException {
if (hex==null)
throw new InvalidHexException(this, "null is not a invalid hex value");
if (hex.length() != getBinarySize()*2)
throw new InvalidHexException(this, "invalid length " + hex.length() + " (should be " + (getBinarySize() * 2) + ") of '" + hex + "'");
binary = new byte[getBinarySize()];