Git Product home page Git Product logo

Comments (4)

goneall avatar goneall commented on May 29, 2024

@nicoweidner Excellent catch - thanks for the review!

For most of the cases, the previous check for contains will return true even if it is a IndividualUriValue. The extra check is primarily for external references (the enum implementations will likely be caught by the previous check).

I'm thinking we could fix this specific issue by changing the class check from:

if (!(comp instanceof SimpleUriValue)) {

to:

if (!(comp instanceof IndividualUriValue)) {

Looking further, some of the other implementations of IndividualUriValue should also override equals and hashcode to use the URI value so that it will be equal to a SimpleUriValue with the same URI.

Probably needs a bit more review and thought before committing the changes - let me know what you think.

As far as making the check symmetric - I agree this is a possible issue.

from spdx-java-library.

goneall avatar goneall commented on May 29, 2024

After thinking about this a bit more, I'm pretty convinced anything that implements IndividualUriValue should override equals/hashcode to use the URI value for equality. The one exception is is the class implementing IndividualUriValue inherits from ModelObject which already overrides equals using the ID for equality.

@nicoweidner I'll create a PR with the changes for this. If you have some time, feel free to tackle the symmetric issue.

from spdx-java-library.

goneall avatar goneall commented on May 29, 2024

@nicoweidner I created a PR to update equals for IndividualUriValues.

In thinking about this some more, SimpleUriValue is typically only used when storing a property - when it is re-inflated back to a model object, it is typically cast to the appropriate type. So this it will not likely cause a problem in practice. That being said, it is a bug since the SimpleUriValue may be used for other purposes and the semantics of IndividaulUriValue should be equal if the URI's are equal.

I did go ahead and update the ModelObjects that implement IndividualUriValue to override equals.

The only implemenations of IndividualUriValue I did not update was the enumerations. Since the equals method in enums are final, I could not override the method.

Please check out the PR and let me know if my logic and updates make sense.

from spdx-java-library.

nicoweidner avatar nicoweidner commented on May 29, 2024

For most of the cases, the previous check for contains will return true even if it is a IndividualUriValue. The extra check is primarily for external references (the enum implementations will likely be caught by the previous check).

Ah, you are right that the previous check should catch various IndividualUriValue implementations. I completely missed that when looking at the two lines about IndividualUriValue in isolation 😅 . In the end, it boils down to how the equals method works in each case. All enum implementations should be fine.

I will think about how the other cases behave. It probably makes more sense to comment directly on the PR since you already made changes there, so I will do that.

from spdx-java-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.