Skip to content

Commit

Permalink
Merge pull request #889 from NASA-PDS/patch_844
Browse files Browse the repository at this point in the history
Catch NumberFormatException when values in data do not match spec in label
  • Loading branch information
jordanpadams committed May 9, 2024
2 parents 5c056fa + 29e3f84 commit 03c830f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/main/java/gov/nasa/pds/tools/validate/ProblemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public enum ProblemType {
INVALID_MEMBER_STATUS("error.inventory_table.invalid_member_status"),

INVENTORY_DUPLICATE_LIDVID("error.inventory.duplicate_lidvid"),


ARRAY_INVALID_SPECIAL_CONSTANT("error.array.invalid_special_constant"),
FIELD_INVALID_SPECIAL_CONSTANT("error.field.invalid_special_constant"),
// Referential Integrity Checking messages

DUPLICATE_VERSIONS("error.integrity.duplicate_versions"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ private void validatePosition(Array array, ArrayObject arrayObject, ArrayLocatio
ProblemReporter reporter = new ArrayProblemReporter(this, ExceptionType.WARNING,
ProblemType.ARRAY_VALUE_OUT_OF_SPECIAL_CONSTANT_MIN_MAX_RANGE, ArrayContentValidator.tableNameReportStr,
location);
isSpecialConstant = SpecialConstantChecker.isConformantSpecialConstant(value, array.getSpecialConstants(), reporter);
try {
isSpecialConstant = SpecialConstantChecker.isConformantSpecialConstant(value, array.getSpecialConstants(), reporter);
} catch (NumberFormatException nfe) {
addArrayProblem(ExceptionType.ERROR, ProblemType.ARRAY_INVALID_SPECIAL_CONSTANT,
"One of the special constants could not be converted to the numeric data type of the array", location);
}
}

// LOG.debug("validatePosition:dataType,isSpecialConstant,array.getSpecialConstants()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,15 @@ private void checkSpecialMinMax(String value, SpecialConstants specialConstants,
if (specialConstants != null) {
FieldProblemReporter reporter = new FieldProblemReporter(this, ExceptionType.WARNING,
ProblemType.FIELD_VALUE_OUT_OF_SPECIAL_CONSTANT_MIN_MAX_RANGE, recordLocation, fieldIndex);
isSpecialConstant = SpecialConstantChecker.isConformantSpecialConstant(number.stripTrailingZeros(),
specialConstants, reporter);
try {
isSpecialConstant = SpecialConstantChecker.isConformantSpecialConstant(number.stripTrailingZeros(),
specialConstants, reporter);
} catch (NumberFormatException nfe) {
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_INVALID_SPECIAL_CONSTANT,
"One of the special constants could not be converted to the numeric data type of the table cell",
recordLocation, fieldIndex);
}
}

if (!isSpecialConstant) {
Double dnumber = number.doubleValue();
if (minimum != null) {
Expand Down

0 comments on commit 03c830f

Please sign in to comment.