Author: bodewig Date: Sun Jun 3 15:30:31 2012 New Revision: 1345687 URL: http://svn.apache.org/viewvc?rev=1345687&view=rev Log: COMPRESS-187 - make empty comments compare equal to no comments in ZIP entries
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=1345687&r1=1345686&r2=1345687&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java Sun Jun 3 15:30:31 2012 @@ -666,13 +666,13 @@ public class ZipArchiveEntry extends jav String myComment = getComment(); String otherComment = other.getComment(); if (myComment == null) { - if (otherComment != null) { - return false; - } - } else if (!myComment.equals(otherComment)) { - return false; + myComment = ""; + } + if (otherComment == null) { + otherComment = ""; } return getTime() == other.getTime() + && myComment.equals(otherComment) && getInternalAttributes() == other.getInternalAttributes() && getPlatform() == other.getPlatform() && getExternalAttributes() == other.getExternalAttributes() Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java?rev=1345687&r1=1345686&r2=1345687&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java Sun Jun 3 15:30:31 2012 @@ -235,4 +235,20 @@ public class ZipArchiveEntryTest extends ZipArchiveEntry entry2 = new ZipArchiveEntry("bar"); assertFalse(entry1.equals(entry2)); } + + /** + * Tests comment's influence on equals comparisons. + * @see https://issues.apache.org/jira/browse/COMPRESS-187 + */ + public void testNullCommentEqualsEmptyComment() { + ZipArchiveEntry entry1 = new ZipArchiveEntry("foo"); + ZipArchiveEntry entry2 = new ZipArchiveEntry("foo"); + ZipArchiveEntry entry3 = new ZipArchiveEntry("foo"); + entry1.setComment(null); + entry2.setComment(""); + entry3.setComment("bar"); + assertEquals(entry1, entry2); + assertFalse(entry1.equals(entry3)); + assertFalse(entry2.equals(entry3)); + } }