Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid hex representations of GUIDs #4174

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 9 additions & 24 deletions src/main/java/net/rptools/maptool/model/GUID.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,23 @@ public GUID() {
validateGUID();
}

/**
* Creates a new GUID based on the specified GUID value.
*
* @param baGUID the new GUID
* @throws InvalidGUIDException if the GUID is invalid
*/
public GUID(byte[] baGUID) throws InvalidGUIDException {
this.baGUID = baGUID;
validateGUID();
}

/**
* Creates a new GUID based on the specified hexadecimal-code string.
*
* @param strGUID the guid as a hexadecimal-code string
* @throws InvalidGUIDException if the GUID is invalid
*/
public GUID(String strGUID) {
if (strGUID == null) throw new InvalidGUIDException("GUID is null");
if (strGUID == null) {
throw new InvalidGUIDException("GUID is null");
}

try {
this.baGUID = HexFormat.of().parseHex(strGUID);
} catch (Exception e) {
throw new InvalidGUIDException("Invalid format for GUID");
}

this.baGUID = HexFormat.of().parseHex(strGUID);
validateGUID();
}

Expand All @@ -77,17 +73,6 @@ private void validateGUID() throws InvalidGUIDException {
throw new InvalidGUIDException("GUID length is invalid: " + baGUID.length);
}

/**
* Returns the GUID representation of the {@link byte} array argument.
*
* @param bits the {@link byte} array of the GUID
* @return a new GUID instance
*/
public static GUID valueOf(byte[] bits) {
if (bits == null) return null;
return new GUID(bits);
}

/**
* Returns the GUID representation of the {@link String} argument.
*
Expand Down