Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-40818

Use of hashCode might cause bugs in the future

    XMLWordPrintable

Details

    • Bug
    • Status: RESOLVED
    • Minor
    • Resolution: Non-Issue
    • 12.4, 12.5, 19.0, 20.0
    • None
    • content review
    • None
    • Hide

      Please add a Test Plan here.

      Show
      Please add a Test Plan here.

    Description

      Looking at the contentreview code, I noticed it uses the hashCode() of a string literal to generate a hopefully-unique-hopefully-stable ID:

      https://github.com/sakaiproject/sakai/blob/883dfdf3a31a337d77b3fb46d24d619f8a5e67d1/content-review/impl/turnitin-oc/src/main/java/org/sakaiproject/contentreview/turnitin/oc/ContentReviewServiceTurnitinOC.java#L555

      I'm not totally across what's going on with this code, but it looked like it was storing that ID in the database for future use, and I don't think it's safe to assume that hasCode's value will be stable.

      At the risk of language lawyering, the docs for hashCode say:

      Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.

      which I think means that value could legally change across restarts. The quick testing I've done suggests it's pretty stable at the moment, but just thought I'd flag the issue to avoid nasty surprises in the future.

      Gliffy Diagrams

        Zeplin

          Attachments

            Activity

              People

                ern Earle R Nietzel
                marktriggs Mark Triggs
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Git Integration