ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerome Lacoste <>
Subject System.getProperties() returns an empty list when unit test runwithin Ant
Date Fri, 16 Aug 2002 14:23:45 GMT
Hi Anties,

I've got this strange problem: one of my UnitTest fails when I run it 
within Ant, while it doens't fail when I run it directly from the same VM.
I've had trouble like that before and they are usualy environment 
related but this one is very strange:
Here's the code of my Unit Test:

 public void testSystemGetProperties() {
    // Skip debug code to printout System.getProperties()
    if (System.getProperties().size() == 0)
      fail("WARNING something is wrong in your environment. 
System.getProperties().size() == 0");

As you can see, System.getProperties().size() == 0 fails when I run this 
test within ant. According to the API this should never happen.
Even more strange is that if I try to access any single System property 
within the same code, I will obtain it without problem!
I.e. System.getProperty("user.dir") works OK but System.getProperties() 
still returns an empty list!!

The following batch file demonstrate the problem for me:

 > type runtest.bat
%JAVA_HOME%\bin\java -cp 

The first call works while the second doesn't

My Ant target is realy simple:
    <target name="" if="testcase" depends="compile.tests"
      description="Runs the specified JUnit test case">
      <junit printsummary="withOutAndErr" haltonfailure="yes">
            <path refid="tests.classpath" />
        <formatter type="plain" usefile="false" />
              <test name="${testcase}" />

where the classpath is set using a fileset filter of all jar file in my 
lib directories + my classes dir

It seems to be an environment problem, but I can't figure it out.
I first though it to be a JDK problem, but given the fact that my test 
works when I invoke it from the command line but not within Ant, I am 
I've searched throught the Ant mailing list, the releases notes for Ant 
1.5, Sun's bug database and Google without luck.

I am currently downloading a newer version of Ant (1.5) and of the JDK 
(1.4.1beta) to rerun my tests, but on my modem line, it's going to take 
some time.
In the meantime I submit my problem to you in case one of you spots a 

Some more information about my environment:

I am developing on WinNT 4.0.

Here's my environment:

D:\>ant -version
Ant version 1.4.1 compiled on October 11 2001

 >%JAVA_HOME%\bin\java -version
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

Attached are:
- SysProp_fromJDK: output of Properties printed out by my test code when 
code executed from the command line:
- SysProp_fromAnt:   Same properties printed out by my test code when 
code is executed within Ant

Notice how System.getProperties() displays 0 elements but all its 
properties are effectively found!

Here's the diff of the two output files:

2     <! Displaying 0 element(s) in properties [System.getProperties()]:
       !> Displaying 50 element(s) in properties [System.getProperties()]:
32     <! p->user.timezone=Europe/Berlin
         !> p->user.timezone=
36     <! 

[Don't ask me why the "user.timezone" is not properly propagated.]

Only noticeable difference is the java.class.path, but isn't that normal?



View raw message