commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stian Soiland-Reyes (JIRA)" <>
Subject [jira] [Created] (COMMONSRDF-56) JSON-LD Literals wrongly compare equal
Date Wed, 08 Feb 2017 19:18:41 GMT
Stian Soiland-Reyes created COMMONSRDF-56:

             Summary: JSON-LD Literals wrongly compare equal
                 Key: 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]( 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 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 citcuit:

        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("");
        JsonLdIRI p = rdf.createIRI("");
        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));

This message was sent by Atlassian JIRA

View raw message