ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs PropertyTest.java
Date Wed, 23 Jul 2003 15:14:23 GMT
bodewig     2003/07/23 08:14:22

  Modified:    src/etc/testcases/taskdefs property.xml
               src/main/org/apache/tools/ant/taskdefs Property.java
               src/testcases/org/apache/tools/ant/taskdefs
                        PropertyTest.java
  Added:       src/etc/testcases/taskdefs property4.properties
  Log:
  resolveAllProperties would be caught in an endless loop when trying to
  expand b -> ${a} -> ${a}.  It would keep replacing ${a} for ${a} as it
  only detected a circular reference if the expansion pointed back to b.
  
  PR: 21825
  
  Revision  Changes    Path
  1.7       +5 -0      ant/src/etc/testcases/taskdefs/property.xml
  
  Index: property.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/property.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- property.xml	18 Jun 2003 08:10:21 -0000	1.6
  +++ property.xml	23 Jul 2003 15:14:18 -0000	1.7
  @@ -36,4 +36,9 @@
       <property name="someprop" value="value" prefix="prefix"/>
     </target>
   
  +  <!-- caused an endless loop, PR 21825 -->
  +  <target name="testCircularReference">
  +    <property file="property4.properties"/>
  +  </target>
  +
   </project>
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/property4.properties
  
  Index: property4.properties
  ===================================================================
  a=${a}
  b=${a}/b
  
  
  
  1.65      +4 -1      ant/src/main/org/apache/tools/ant/taskdefs/Property.java
  
  Index: Property.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- Property.java	19 Jul 2003 11:20:13 -0000	1.64
  +++ Property.java	23 Jul 2003 15:14:19 -0000	1.65
  @@ -573,6 +573,8 @@
               String value = props.getProperty(name);
   
               boolean resolved = false;
  +            Vector expandedReferences = new Vector();
  +            expandedReferences.addElement(name);
               while (!resolved) {
                   Vector fragments = new Vector();
                   Vector propertyRefs = new Vector();
  @@ -588,11 +590,12 @@
                           String fragment = (String) i.nextElement();
                           if (fragment == null) {
                               String propertyName = (String) j.nextElement();
  -                            if (propertyName.equals(name)) {
  +                            if (expandedReferences.contains(propertyName)) {
                                   throw new BuildException("Property " + name
                                                            + " was circularly "
                                                            + "defined.");
                               }
  +                            expandedReferences.addElement(propertyName);
                               fragment = getProject().getProperty(propertyName);
                               if (fragment == null) {
                                   if (props.containsKey(propertyName)) {
  
  
  
  1.11      +12 -0     ant/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java
  
  Index: PropertyTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/PropertyTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PropertyTest.java	23 Jun 2003 09:07:30 -0000	1.10
  +++ PropertyTest.java	23 Jul 2003 15:14:19 -0000	1.11
  @@ -116,4 +116,16 @@
           fail("Did not throw exception on invalid use of prefix");
       }
   
  +    public void testCircularReference() {
  +        try {
  +            executeTarget("testCircularReference");
  +        } catch (BuildException e) {
  +            assertEquals("Circular definition not detected - ", true,
  +                         e.getMessage().indexOf("was circularly defined") 
  +                         != -1);
  +            return;
  +        }
  +        fail("Did not throw exception on circular exception");
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message