Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,24 @@
}
}
}
boolean hasDecimalPoint = constant_repr.contains(".");
boolean hasScientificNotation = (constant_repr.contains("E") || constant_repr.contains("e"))
&& !constant_repr.startsWith("0x") && !constant_repr.startsWith("0X");
Comment on lines +188 to +189

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the hexadecimal exclusion here applies only to scientific notation, not to the decimal-point test. That means something like 0x1.23 is still classified as repr_decimal.

This is not a regression, as the behavior already existed before this pull request. Maybe something to note for the future.

boolean repr_decimal = hasDecimalPoint || hasScientificNotation;

Check warning on line 190 in src/main/java/gov/nasa/pds/tools/validate/SpecialConstantChecker.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=NASA-PDS_validate&issues=AaAqvvmtvKLTf8kMhUId&open=AaAqvvmtvKLTf8kMhUId&pullRequest=1664
// For ASCII numeric fields, the value arrives as BigDecimal. Compare directly
// against a decimal constant representation to avoid lossy BigDecimal→Double→BigInteger
// conversion that causes missing_constant values like "-.99999" to never match.
if (number instanceof BigDecimal && repr_decimal) {

Check warning on line 194 in src/main/java/gov/nasa/pds/tools/validate/SpecialConstantChecker.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this instanceof check and cast with 'instanceof BigDecimal bigdecimal'

See more on https://sonarcloud.io/project/issues?id=NASA-PDS_validate&issues=AaAqvvmtvKLTf8kMhUIe&open=AaAqvvmtvKLTf8kMhUIe&pullRequest=1664
BigDecimal constant = SpecialConstantBitPatternTransforms.asBigDecimal(constant_repr, radix);
return constant.compareTo((BigDecimal) number) == 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big thumbs-up for compareTo πŸŽ‰

}
if (number instanceof BigDecimal) number = ((BigDecimal)number).doubleValue();
if (number instanceof Byte) number = BigInteger.valueOf(number.byteValue());
if (number instanceof Double) number = BigInteger.valueOf(Double.doubleToRawLongBits((Double)number));
if (number instanceof Float) number = BigInteger.valueOf(Float.floatToRawIntBits((Float)number) & 0xFFFFFFFFL);
if (number instanceof Integer || number instanceof UnsignedInteger) number = BigInteger.valueOf(number.intValue());
if (number instanceof Long || number instanceof UnsignedLong) number = BigInteger.valueOf(number.longValue());
if (number instanceof Short) number = BigInteger.valueOf(number.shortValue());
boolean repr_decimal = constant_repr.contains (".") ||
((constant_repr.contains("E") || constant_repr.contains("e")) &&
!(constant_repr.startsWith("0x") || constant_repr.startsWith("0X")));
if (repr_decimal) {
BigDecimal constant = SpecialConstantBitPatternTransforms.asBigDecimal(constant_repr, radix);
return constant.equals (number);
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/features/4.2.x.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ Feature: 4.2.x
# github1635: M4A/AAC should be a recognized encoding type; content validation not yet supported β†’ WARNING not ERROR
| 1635 | 1 | "github1635" | "--skip-context-validation -t {datasrc}/audio_m4a.xml" | "summary:totalWarnings=1,summary:messageTypes:warning.validation.content_validation_not_yet_supported=1" |

# github1660: missing_constant must suppress min/max range errors in ASCII table fields
| 1660 | 1 | "github1660" | "--skip-context-validation -t {datasrc}/pccds.xml" | "summary:productValidation:passed=1,summary:totalErrors=0,summary:totalWarnings=2,summary:messageTypes:warning.label.bad_schematypens=1,summary:messageTypes:warning.label.missing_schematron_spec=1" |

#end
Loading
Loading