arne-bdt commented on issue #2795:
URL: https://github.com/apache/jena/issues/2795#issuecomment-2439653100

   > `LiteralLabel `assumes that the datatypes can be compared by reference.
   
   LiteralLabel daoes not make such an assumption. `Objects.equals(a, b)` does 
not compare by reference. The code looks like this:
   
![image](https://github.com/user-attachments/assets/d7a57dee-0b8b-4bf2-8a42-a67caf844907)
   
   In my option the root cause of the whole problem is that the implementations 
of `RDFDatatype` do not override `equals(Object other)` and `hashCode()`. 
   So we indeed rely on reference equality, which I guess is a really bad 
thing. 
   
   That is what makes duplicated entries possible in the first place.
   
   In the `testUserDefRepeated` from your 
[PR](https://github.com/apache/jena/pull/2796), I think the types should be 
equal:
   ```java
   RDFDatatype type1 = new BaseDatatype("urn:x-jena-dt:repeated");
   RDFDatatype type2 = new BaseDatatype("urn:x-jena-dt:repeated");
   
   // Check precondition
   assertEquals("Datatypes should be equal", type1, type2);
   ```
   This assert currently fails.
   
   I propose to implement `equals()` and `hashCode()` in `BaseDatatype` like 
this:
   
   ```java
   @Override
   public boolean equals(Object other) {
       if(other != null
               && this.getURI().equals(((BaseDatatype)other).getURI())
               && this.getClass().equals(other.getClass())) {
           return true;
       }
       return false;
   }
   
   @Override
   public int hashCode() {
       return super.uri.hashCode();
   }
   ```
   I am not sure if the implementing class should be part of the equality 
check. Checking it feels safer.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to