Bug 61315 - Upgrading from ant 1.6.2 to ant 1.10.1 and isset is not working properly
Summary: Upgrading from ant 1.6.2 to ant 1.10.1 and isset is not working properly
Status: RESOLVED WORKSFORME
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.10.1
Hardware: All All
: P2 blocker (vote)
Target Milestone: 1.10.1
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-18 17:10 UTC by Chandra shekar r chekuri
Modified: 2017-07-23 15:53 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chandra shekar r chekuri 2017-07-18 17:10:03 UTC
We are migrating from ant 1.6.2 to ant 1.10.1 and depending on the isset we execute a work flow .. below is the code.

config.xml

<RMOBINTERMEDIUM>
        <UserName></UserName>
        <Password></Password>
        <SID></SID>
        <Host></Host>
        </RMOBINTERMEDIUM>


<if>
    <isset property="RMOBINTERMEDIUM.UserName"/>
       <then>
        <echo message="schema exists"/>
       </then>


when executing the above code i am getting the "schema exists: printed .while the config.xml has no value set. below is the output

[sqlplus] 11:53:21 SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
  [sqlplus] With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
  [sqlplus] Advanced Analytics and Real Application Testing options
     [echo] rmob exists


NOTE: it still works when i got back to ant 1.6.2 but we need to upgrade to 1.10.1 and the behavior of the isset is not working as desired.
Comment 1 Chandra shekar r chekuri 2017-07-18 17:14:26 UTC
sorry i had a typo in previous result ,this is the result we are seeing 

  [echo] schema exists
Comment 2 Stefan Bodewig 2017-07-18 17:47:28 UTC
You don't show how you read the file.

Can you put the whole example into a simple self-contained build file? Preferably without using ant-contrib, so we get that out of consideration.


<project>
  <condition property="schema" value="exists">
    <isset property="RMOBINTERMEDIUM.UserName"/>
  </condition>
  <property name="schema" value="doesn't exist"/>
  <echo>schema: ${schema}</echo>
</project>

should work well enough for the test. With 1.10.1 I get

$ ant -f /tmp/x.xml -DRMOBINTERMEDIUM.UserName=x
Buildfile: /tmp/x.xml
     [echo] schema: exists

BUILD SUCCESSFUL
Total time: 0 seconds
$ ant -f /tmp/x.xml
Buildfile: /tmp/x.xml
     [echo] schema: doesn't exist

BUILD SUCCESSFUL
Total time: 0 seconds
Comment 3 Chandra shekar r chekuri 2017-07-18 19:06:29 UTC
when I use <condition> <isset> it works fine .

can you test it <if> <isset> and see if its returning the same result ?
Comment 4 Jan Mat 2017-07-19 08:30:34 UTC
This works for with Ant-1.9.6 and Ant-1.10.1

<project xmlns:antcontrib="antlib:net.sf.antcontrib">
  <echo>using built in condition</echo>
  <echo>------------------------</echo>
  <condition property="schema" value="exists">
    <isset property="RMOBINTERMEDIUM.UserName"/>
  </condition>
  <property name="schema" value="doesn't exist"/>
  <echo>schema: ${schema}</echo>

  <echo/>
  <echo>using ant-contrib::if</echo>
  <echo>---------------------</echo>
  <mkdir dir="tmp"/>
  <get 
    src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"
    dest="tmp"
  >
    <flattenmapper/>
  </get>
  <taskdef uri="antlib:net.sf.antcontrib"
           resource="net/sf/antcontrib/antlib.xml"
           classpath="tmp/ant-contrib-1.0b3.jar"/>
  <antcontrib:if>
    <isset property="RMOBINTERMEDIUM.UserName"/>
    <antcontrib:then>
      <echo message="schema exists"/>
    </antcontrib:then>
    <antcontrib:else>
      <echo message="schema does not exists"/>
    </antcontrib:else>
  </antcontrib:if>

</project>
Comment 5 Stefan Bodewig 2017-07-21 14:58:58 UTC
works fine with ant-contrib as well

$ cat f.xml 
<project>
  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <pathelement location="ant-contrib-1.0b3.jar"/>
    </classpath>
  </taskdef>
  <if>
    <isset property="RMOBINTERMEDIUM.UserName"/>
    <then>
      <echo>schema exists</echo>
    </then>
    <else>
      <echo>schema doesn't exists</echo>
    </else>
  </if>
</project>
/tmp$ ant -f f.xml 
Buildfile: /tmp/f.xml
     [echo] schema doesn't exists

BUILD SUCCESSFUL
Total time: 0 seconds
$ ant -f f.xml -DRMOBINTERMEDIUM.UserName=x
Buildfile: /tmp/f.xml
     [echo] schema exists

BUILD SUCCESSFUL
Total time: 0 seconds

So I think it is not isset but rather the way you actually set the property (and which you haven't shown). I'm guessing now that you are using xmlproperty - if so bug 26286 which has been fixed for Ant 1.7.0 might be the root cause. If my guess is correct, then your current script depends on something we have considered a bug and fixed almost 11 years ago.
Comment 6 Stefan Bodewig 2017-07-21 15:02:45 UTC
(In reply to Stefan Bodewig from comment #5)

> If my guess is correct, then your current script depends on
> something we have considered a bug and fixed almost 11 years ago.

and you may work around it by using

<and>
  <isset property="RMOBINTERMEDIUM.UserName"/>
  <not>
    <equals arg1="" args2="${RMOBINTERMEDIUM.UserName}"/>
  </not>
</and>

which should work with 1.6.2 and 1.7.0+
Comment 7 Chandra shekar r chekuri 2017-07-21 15:06:12 UTC
yes, that fixed it .

that is how i change my code and it works now.