Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.12
    • Fix Version/s: 2.0
    • Component/s: Java API
    • Labels:
      None
    • Number of attachments :
      0

      Description

      at least in class JavaMethod

      public int hashCode() {
              int hashCode = name.hashCode();
              if (returns != null) hashCode *= returns.hashCode();
              hashCode *= getParameters().length;
              return hashCode;
          }
      

      when parameter.set has zero length, hashcode turns to be zero as well

      this affects usage in Maps

      improvement would be to use:

      http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/builder/HashCodeBuilder.html

      this could be also wrong in other classes

        Activity

        Hide
        Lars K. W. Gohlke added a comment -
        public int hashCode() { 
            int hashCode = name.hashCode(); 
            if (returns != null) 
                 hashCode *= returns.hashCode(); 
            hashCode *= getParameters().length; 
            return hashCode; 
        }
        
        Show
        Lars K. W. Gohlke added a comment - public int hashCode() { int hashCode = name.hashCode(); if (returns != null ) hashCode *= returns.hashCode(); hashCode *= getParameters().length; return hashCode; }
        Robert Scholte made changes -
        Field Original Value New Value
        Description at least in class JavaMethod

        {code]
        public int hashCode() {
                int hashCode = name.hashCode();
                if (returns != null) hashCode *= returns.hashCode();
                hashCode *= getParameters().length;
                return hashCode;
            }
        {code}

        when parameter.set has zero length, hashcode turns to be zero as well

        this affects usage in Maps

        improvement would be to use:

        http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/builder/HashCodeBuilder.html

        this could be also wrong in other classes
        at least in class JavaMethod

        {code}
        public int hashCode() {
                int hashCode = name.hashCode();
                if (returns != null) hashCode *= returns.hashCode();
                hashCode *= getParameters().length;
                return hashCode;
            }
        {code}

        when parameter.set has zero length, hashcode turns to be zero as well

        this affects usage in Maps

        improvement would be to use:

        http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/builder/HashCodeBuilder.html

        this could be also wrong in other classes
        Hide
        Robert Scholte added a comment -

        I'll review alle hashcodes, but I don't want to depend on commons-lang just for this.
        Right now QDox has zero compile-time dependencies and I'd like to keep it that way.
        But hashCodes which could result in 0 are indeed wrong.

        Show
        Robert Scholte added a comment - I'll review alle hashcodes, but I don't want to depend on commons-lang just for this. Right now QDox has zero compile-time dependencies and I'd like to keep it that way. But hashCodes which could result in 0 are indeed wrong.
        Hide
        Lars K. W. Gohlke added a comment -

        sum the hashcodes up, would be the first step and

        in this special case the call signature with the full qualified classname would be good for hashing

        Show
        Lars K. W. Gohlke added a comment - sum the hashcodes up, would be the first step and in this special case the call signature with the full qualified classname would be good for hashing
        Hide
        Robert Scholte added a comment -

        Fixed in rev. 1293
        Please verify it and close the issue if it is valid.

        Show
        Robert Scholte added a comment - Fixed in rev. 1293 Please verify it and close the issue if it is valid.
        Robert Scholte made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Robert Scholte [ rfscholte ]
        Fix Version/s 2.0 [ 15636 ]
        Resolution Fixed [ 1 ]
        Hide
        Lars K. W. Gohlke added a comment -

        what about varargs in JavaParameter hashcode? Now (int ... x) and (int x) would result in the same hash

        https://fisheye.codehaus.org/browse/qdox/trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaParameter.java?r=1293#to126

        the rest is ok as I know.

        Show
        Lars K. W. Gohlke added a comment - what about varargs in JavaParameter hashcode? Now (int ... x) and (int x) would result in the same hash https://fisheye.codehaus.org/browse/qdox/trunk/qdox/src/main/java/com/thoughtworks/qdox/model/DefaultJavaParameter.java?r=1293#to126 the rest is ok as I know.
        Hide
        Robert Scholte added a comment -

        Fixed in rev. 1296
        Just made me realize that I have to review all the equals() as well.

        Show
        Robert Scholte added a comment - Fixed in rev. 1296 Just made me realize that I have to review all the equals() as well.

          People

          • Assignee:
            Robert Scholte
            Reporter:
            Lars K. W. Gohlke
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: