Uploaded image for project: 'Apache Commons RDF'
  1. Apache Commons RDF
  2. COMMONSRDF-56

JSON-LD Literals wrongly compare equal

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 0.3.0
    • jsonld-java
    • 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));
      

      Attachments

        Activity

          People

            stain Stian Soiland-Reyes
            stain Stian Soiland-Reyes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: