You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jena.apache.org by "ting668 (via GitHub)" <gi...@apache.org> on 2026/09/20 02:11:31 UTC

[I] `FILTER(?v > 1e0)` accepts `"NaN"^^xsd:double` (numeric `>` comparison with `NaN` returns `true`) [jena]

ting668 opened a new issue, #4235:
URL: https://github.com/apache/jena/issues/4235

   ### 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 a method based on attribute-constraint analysis, I found that a numeric ordering comparison in a `FILTER` accepts a `NaN` value: `"NaN"^^xsd:double > 1e0` evaluates to `true`, so a row carrying `NaN` passes a filter that should reject it.
   
   Under the SPARQL operator mapping, `>` on numeric operands follows XPath numeric comparison, in which any comparison involving `NaN` is `false`. Of the values below, only `2.0` should satisfy `?v > 1e0`.
   
   ## 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):
   
   ```sparql
   PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
   SELECT ?s ?v WHERE {
     ?s <urn:p> ?v .
     FILTER(?v > 1e0)
   }
   ```
   
   Data (default graph, N-Triples):
   
   ```nt
   <urn:nan> <urn:p> "NaN"^^<http://www.w3.org/2001/XMLSchema#double> .
   <urn:two> <urn:p> "2.0"^^<http://www.w3.org/2001/XMLSchema#double> .
   ```
   
   Expected behavior: the greater-than comparison with `NaN` is `false`, so only the `2.0` row matches:
   
   ```text
   [{"s":"<urn:two>","v":"\"2.0\"^^xsd:double"}]
   ```
   
   Actual behavior: the row carrying `"NaN"^^xsd:double` is also returned:
   
   ```text
   [{"s":"<urn:nan>","v":"\"NaN\"^^xsd:double"},{"s":"<urn:two>","v":"\"2.0\"^^xsd:double"}]
   ```
   
   This suggests that the numeric greater-than comparison treats `NaN` as comparable and greater than the constant instead of evaluating to `false`, so rows that should be filtered out are kept.
   
   
   ### Relevant output and stacktrace
   
   ```shell
   
   ```
   
   ### Are you interested in making a pull request?
   
   None


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [I] `FILTER(?v > 1e0)` accepts `"NaN"^^xsd:double` (numeric `>` comparison with `NaN` returns `true`) [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on issue #4235:
URL: https://github.com/apache/jena/issues/4235#issuecomment-5748850735

   Confirmed
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org