Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
Description
There's a bug in JSON-LD Java 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():
JsonLdRDF rdf = new JsonLdRDF(); JsonLdLiteral lit1 = rdf.createLiteral("Hello"); JsonLdLiteral lit2 = rdf.createLiteral("Hello there"); assertNotEquals(lit1, lit2);
The above will fail because JsonLdLiteralImpl.equals does a short JsonLdLiteral-specific call to the deeper .compareTo:
if (obj instanceof JsonLdLiteral) { final JsonLdLiteral other = (JsonLdLiteral) obj; return asJsonLdNode().compareTo(other.asJsonLdNode()) == 0; }
Similarly, using .contains or .stream matching a literal object backed by a JSON-LD Graph or Dataset will wrongly match any literal:
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));