Author: jkf
Date: Sat Jan 27 15:40:37 2007
New Revision: 500692
URL: http://svn.apache.org/viewvc?view=rev&rev=500692
Log:
Pr: 41284 dependset throws NullPointerException. Sort is not suitable to sort
items in an order that might change during sorting.
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/DependSet.java
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/DependSet.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/DependSet.java?view=diff&rev=500692&r1=500691&r2=500692
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/DependSet.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/DependSet.java Sat
Jan 27 15:40:37 2007
@@ -94,22 +94,7 @@
super.add(NOT_EXISTS);
}
}
- private static class Xest extends Sort {
- private Xest(ResourceCollection rc, ResourceComparator c) {
- super.add(c);
- super.add(rc);
- }
- }
- private static class Oldest extends Xest {
- private Oldest(ResourceCollection rc) {
- super(rc, DATE_ASC);
- }
- }
- private static class Newest extends Xest {
- private Newest(ResourceCollection rc) {
- super(rc, DATE_DESC);
- }
- }
+
private static class HideMissingBasedir implements ResourceCollection {
private FileSet fs;
@@ -220,7 +205,7 @@
log(neTargets + " nonexistent targets", Project.MSG_VERBOSE);
return false;
}
- FileResource oldestTarget = (FileResource) (new
Oldest(targets).iterator().next());
+ FileResource oldestTarget = (FileResource) getOldest(targets);
log(oldestTarget + " is oldest target file", Project.MSG_VERBOSE);
logFuture(sources, datesel);
@@ -230,7 +215,7 @@
log(neSources + " nonexistent sources", Project.MSG_VERBOSE);
return false;
}
- Resource newestSource = (Resource) (new
Newest(sources).iterator().next());
+ Resource newestSource = (Resource) getNewest(sources);
log(newestSource.toLongString() + " is newest source",
Project.MSG_VERBOSE);
return oldestTarget.getLastModified() >=
newestSource.getLastModified();
}
@@ -243,4 +228,29 @@
log("Warning: " + i.next() + " modified in the future.",
Project.MSG_WARN);
}
}
+
+ private Resource getXest(ResourceCollection rc, ResourceComparator c) {
+ Iterator i = rc.iterator();
+ if (!i.hasNext()) {
+ return null;
+
+ }
+ Resource xest = (Resource) i.next();
+ while (i.hasNext()) {
+ Resource next = (Resource) i.next();
+ if (c.compare(xest, next) < 0) {
+ xest = next;
+ }
+ }
+ return xest;
+ }
+
+ private Resource getOldest(ResourceCollection rc) {
+ return getXest(rc, DATE_ASC);
+ }
+
+ private Resource getNewest(ResourceCollection rc) {
+ return getXest(rc, DATE_DESC);
+ }
+
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java?view=diff&rev=500692&r1=500691&r2=500692
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Sort.java Sat
Jan 27 15:40:37 2007
@@ -35,6 +35,10 @@
/**
* ResourceCollection that sorts another ResourceCollection.
+ *
+ * Note that Sort must not be used in cases where the ordering of the objects
+ * being sorted might change during the sorting process.
+ *
* @since Ant 1.7
*/
public class Sort extends BaseResourceCollectionWrapper {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]