Stian Soiland-Reyes created COMMONSRDF-56:
---------------------------------------------
Summary: JSON-LD Literals wrongly compare equal
Key: COMMONSRDF-56
URL: https://issues.apache.org/jira/browse/COMMONSRDF-56
Project: Apache Commons RDF
Issue Type: Bug
Components: jsonld-java
Reporter: Stian Soiland-Reyes
Fix For: 0.3.0
There's a [bug in JSON-LD
Java](https://github.com/jsonld-java/jsonld-java/pull/190) in
{{Node.compareTo()}} for Literals, namely, they don't compare the values of the
literal, language or datatype, which in Commons RDF can wrongly match a
literal, say in dataset.stream() or in Literal.equals():
{code}
JsonLdRDF rdf = new JsonLdRDF();
JsonLdLiteral lit1 = rdf.createLiteral("Hello");
JsonLdLiteral lit2 = rdf.createLiteral("Hello there");
assertNotEquals(lit1, lit2);
{code}
The above will fail because JsonLdLiteralImpl.equals does a short citcuit:
{code}
if (obj instanceof JsonLdLiteral) {
final JsonLdLiteral other = (JsonLdLiteral) obj;
return asJsonLdNode().compareTo(other.asJsonLdNode()) == 0;
}
{code}
Similarly, using .contains or .stream matching a literal object backed by a
JSON-LD Graph or Dataset will wrongly match any literal:
{code}
JsonLdDataset dataset = rdf.createDataset();
JsonLdIRI s = rdf.createIRI("http://example.com/s");
JsonLdIRI p = rdf.createIRI("http://example.com/p");
JsonLdLiteral lit1 = rdf.createLiteral("Hello");
JsonLdLiteral lit2 = rdf.createLiteral("Other");
dataset.add(null, s, p, lit1);
assertTrue(dataset.contains(Optional.empty(), s, p, lit2));
assertFalse(dataset.contains(Optional.empty(), s, p, lit2));
{code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)