Version
6.2.0
What happened?
Reporter: ting668
Environment
- Apache Jena Version:
6.2.0
- Java Version:
21.0.12+8-LTS
Description
While testing Apache Jena using an intuitive approach inspired by attribute constraints, I found that the numeric-to-boolean constructor returns true for a NaN double: xsd:boolean("NaN"^^xsd:double) evaluates to true, so a FILTER on the cast accepts a row it should reject.
Under the numeric-to-boolean cast, NaN and zero are false and non-zero values are true: 1.0 (as xsd:double or xsd:float) is true, while "NaN"^^xsd:double and "0.0"^^xsd:double are false.
How to Reproduce and Expected Behavior
Note: The queries below are a minimized, simplified example reproducing the bug.
Buggy query (with the default graph loaded with the N-Triples data below):
SELECT ?s WHERE { ?s <urn:pub:p> ?v . FILTER(<http://www.w3.org/2001/XMLSchema#boolean>(?v)) } ORDER BY ?s
Data (default graph, N-Triples):
<urn:pub:nanDouble> <urn:pub:p> "NaN"^^<http://www.w3.org/2001/XMLSchema#double> .
<urn:pub:zeroDouble> <urn:pub:p> "0.0"^^<http://www.w3.org/2001/XMLSchema#double> .
<urn:pub:oneDouble> <urn:pub:p> "1.0"^^<http://www.w3.org/2001/XMLSchema#double> .
<urn:pub:nanFloat> <urn:pub:p> "NaN"^^<http://www.w3.org/2001/XMLSchema#float> .
<urn:pub:oneFloat> <urn:pub:p> "1.0"^^<http://www.w3.org/2001/XMLSchema#float> .
<urn:pub:background> <urn:pub:other> <urn:pub:value> .
Expected behavior: only the 1.0 values cast to true:
[{"s":"<urn:pub:oneDouble>"},{"s":"<urn:pub:oneFloat>"}]
Actual behavior: the row carrying "NaN"^^xsd:double is also returned:
[{"s":"<urn:pub:nanDouble>"},{"s":"<urn:pub:oneDouble>"},{"s":"<urn:pub:oneFloat>"}]
In the same run the "NaN"^^xsd:float value was not accepted; the wrong true result was observed for the xsd:double NaN.
This suggests that the boolean cast of an xsd:double does not apply the specified mapping of NaN to false, so a value that should be rejected passes the filter.
Relevant output and stacktrace
Are you interested in making a pull request?
None
Version
6.2.0
What happened?
Reporter: ting668
Environment
6.2.021.0.12+8-LTSDescription
While testing Apache Jena using an intuitive approach inspired by attribute constraints, I found that the numeric-to-boolean constructor returns
truefor aNaNdouble:xsd:boolean("NaN"^^xsd:double)evaluates totrue, so aFILTERon the cast accepts a row it should reject.Under the numeric-to-boolean cast,
NaNand zero arefalseand non-zero values aretrue:1.0(asxsd:doubleorxsd:float) istrue, while"NaN"^^xsd:doubleand"0.0"^^xsd:doublearefalse.How to Reproduce and Expected Behavior
Note: The queries below are a minimized, simplified example reproducing the bug.
Buggy query (with the default graph loaded with the N-Triples data below):
Data (default graph, N-Triples):
Expected behavior: only the
1.0values cast totrue:Actual behavior: the row carrying
"NaN"^^xsd:doubleis also returned:In the same run the
"NaN"^^xsd:floatvalue was not accepted; the wrongtrueresult was observed for thexsd:doubleNaN.This suggests that the boolean cast of an
xsd:doubledoes not apply the specified mapping ofNaNtofalse, so a value that should be rejected passes the filter.Relevant output and stacktrace
Are you interested in making a pull request?
None