Browse Source

Pr: 41284 dependset throws NullPointerException. Sort is not suitable to sort items in an order that might change during sorting.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@500692 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 18 years ago
parent
commit
29866fce1d
2 changed files with 32 additions and 18 deletions
  1. +28
    -18
      src/main/org/apache/tools/ant/taskdefs/DependSet.java
  2. +4
    -0
      src/main/org/apache/tools/ant/types/resources/Sort.java

+ 28
- 18
src/main/org/apache/tools/ant/taskdefs/DependSet.java View File

@@ -94,22 +94,7 @@ public class DependSet extends MatchingTask {
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 @@ public class DependSet extends MatchingTask {
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 @@ public class DependSet extends MatchingTask {
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 @@ public class DependSet extends MatchingTask {
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);
}

}

+ 4
- 0
src/main/org/apache/tools/ant/types/resources/Sort.java View File

@@ -35,6 +35,10 @@ import org.apache.tools.ant.types.resources.comparators.DelegatedResourceCompara

/**
* 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 {


Loading…
Cancel
Save