Skip to content

Commit

Permalink
Merge pull request #4174 from kwvanderlinde/feature/3852-fix-fallback…
Browse files Browse the repository at this point in the history
…-exception

Handle invalid hex representations of GUIDs
  • Loading branch information
cwisniew authored Jun 24, 2023
2 parents cbd7c76 + 459241d commit b73929a
Showing 1 changed file with 9 additions and 24 deletions.
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

0 comments on commit b73929a

Please sign in to comment.