commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] Created: (SANDBOX-287) CompressUtils#compareByteArrays() looks wrong
Date Wed, 11 Feb 2009 19:17:02 GMT
CompressUtils#compareByteArrays() looks wrong

                 Key: SANDBOX-287
             Project: Commons Sandbox
          Issue Type: Bug
          Components: Compress
            Reporter: Sebb

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;
        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?

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message