commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stian Soiland-Reyes (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COMMONSRDF-56) JSON-LD Literals wrongly compare equal
Date Wed, 08 Feb 2017 22:42:41 GMT

    [ https://issues.apache.org/jira/browse/COMMONSRDF-56?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15858642#comment-15858642
] 

Stian Soiland-Reyes commented on COMMONSRDF-56:
-----------------------------------------------

I added workarounds in JsonLdLiteralImpl to not use .compareTo() short-cut, as well as for
JsonLdDataset/JsonLdGraph to not use .compareTo() in its {{quadFilter}} if matching two literals
(instead if will create a {{JsonLdLiteralImpl}} to do a RDF 1.1 comparison. This should also
handle COMMONSRDF-51.)

> 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
>            Assignee: 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 {{JsonLdLiteral}}-specific
call to the deeper {{.compareTo}}:
> {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)

Mime
View raw message