Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-21

CompressUtils#compareByteArrays() looks wrong

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.0
    • None
    • None

    Description

      CompressUtils#compareByteArrays() looks wrong.

      The Javadoc says that it compares two byte arrays, however the arrays are treated differently:

      public static boolean compareByteArrays(byte[] source, byte[] match) {
              int i = 0;
              while(source.length < i || i < match.length ) {
                  if(source[i] != match[i]) {
                      return false;
                  }
                  i++;
              }
              return true;
          }
      

      The code will keep checking bytes from match[] until there is a mismatch with source[].
      If source[] is shorther than match[] then ArrayOutOfBoundsException will be generated.

      If source[] is longer than match[], then trailing bytes in source[] will be ignored.

      Neither behaviour seems particularly useful...

      The method does not appear to be used, so perhaps it should just be deleted?

      Attachments

        Activity

          People

            Unassigned Unassigned
            sebb Sebb
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: