diff --git a/WHATSNEW b/WHATSNEW index cc70b0f7b..951b3e1cd 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -121,6 +121,14 @@ Changes that could break older environments: handling on certain Java VMs. Bugzilla issue 5003. + * 's totalproperty was platform dependent because it relied + on java.io.File#compareTo. It has now been made platform + independent, which means that totalPropery values obtained on + Windows (and other systems where the sort order of File is not case + sensitive) can be different from the values obtained with earlier + versions of Ant. + Bugzilla Report 36748. + Fixed bugs: ----------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Checksum.java b/src/main/org/apache/tools/ant/taskdefs/Checksum.java index 353af08ca..96bcf5907 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Checksum.java +++ b/src/main/org/apache/tools/ant/taskdefs/Checksum.java @@ -27,6 +27,7 @@ import java.io.FileInputStream; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Iterator; @@ -550,8 +551,18 @@ public class Checksum extends MatchingTask implements Condition { // Convert the keys (source files) into a sorted array. Set keys = allDigests.keySet(); Object[] keyArray = keys.toArray(); - // File is Comparable, so sorting is trivial - Arrays.sort(keyArray); + // File is Comparable, but sort-order is platform + // dependent (case-insensitive on Windows) + Arrays.sort(keyArray, new Comparator() { + public int compare(Object o1, Object o2) { + File f1 = (File) o1; + File f2 = (File) o2; + return f1 == null ? (f2 == null ? 0 : -1) + : (f2 == null ? 1 + : f1.getName().compareTo(f2.getName()) + ); + } + }); // Loop over the checksums and generate a total hash. messageDigest.reset(); for (int i = 0; i < keyArray.length; i++) { diff --git a/src/tests/antunit/taskdefs/checksum-test.xml b/src/tests/antunit/taskdefs/checksum-test.xml index ba55ef096..d1ae33e81 100644 --- a/src/tests/antunit/taskdefs/checksum-test.xml +++ b/src/tests/antunit/taskdefs/checksum-test.xml @@ -31,7 +31,7 @@ -