diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index 1a97eee58..abf4dce6d 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -142,7 +142,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection { } - private final boolean preserveBC = delegateIteratorToList(); + private Boolean preserveBC; private Union union = null; @@ -687,7 +687,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection { return ((Path) getCheckedRef()).iterator(); } dieOnCircularReference(); - if (preserveBC) { + if (getPreserveBC()) { return new FileResourceIterator(null, list()); } return union == null ? EMPTY_ITERATOR @@ -726,8 +726,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection { * The default behavior of this method is to return true for any subclass * that implements list(); this can, of course, be avoided by overriding * this method to return false. It is not expected that the result of this - * method should change over time; thus it is called a single time during instance - * initialization. + * method should change over time, thus it is called only once. * @return true if iterator() should delegate to list(). */ protected boolean delegateIteratorToList() { @@ -742,4 +741,11 @@ public class Path extends DataType implements Cloneable, ResourceCollection { return false; } } + + private synchronized boolean getPreserveBC() { + if (preserveBC == null) { + preserveBC = delegateIteratorToList() ? Boolean.TRUE : Boolean.FALSE; + } + return preserveBC.booleanValue(); + } }