In Java, throwing Error is reserved for the JVM/the most catastrophic of problems in the system. Things that are truly unrecoverable. This code throws Error (maybe more code than just this, did not look deeper). If a malformed string is attempted to be decoded by the library, it would be more correct to throw Exception or something which extends Exception (maybe re-use the DecodingException?). A malformed consent string is a recoverable issue.
public void decodeSegmentsFromBitStrings(List<String> segmentBitStrings) throws DecodingException {
for (int i = 0; i < this.segments.length && i < segmentBitStrings.size(); i++) {
String segmentBitString = segmentBitStrings.get(i);
if (segmentBitString != null && segmentBitString.length() > 0) {
int index = 0;
for (int j = 0; j < this.segments[i].length; j++) {
String fieldName = this.segments[i][j];
if (this.fields.containsKey(fieldName)) {
try {
AbstractEncodableBitStringDataType<?> field = this.fields.get(fieldName);
String substring = field.substring(segmentBitString, index);
field.decode(substring);
index += substring.length();
} catch (Exception e) {
throw new Error("Unable to decode " + fieldName, e);
}
} else {
throw new Error("Field not found: '" + fieldName + "'");
}
}
}
}
}
In Java, throwing Error is reserved for the JVM/the most catastrophic of problems in the system. Things that are truly unrecoverable. This code throws Error (maybe more code than just this, did not look deeper). If a malformed string is attempted to be decoded by the library, it would be more correct to throw Exception or something which extends Exception (maybe re-use the DecodingException?). A malformed consent string is a recoverable issue.