Bug 1362 - class initialisation for task java is not well done
Summary: class initialisation for task java is not well done
Status: RESOLVED DUPLICATE of bug 1613
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.3
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-04-17 09:19 UTC by pedro Cristian
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments
a jar with the test case. (1.24 KB, application/octet-stream)
2001-04-17 09:28 UTC, pedro Cristian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pedro Cristian 2001-04-17 09:19:12 UTC
It seems that the java-task doesn't initialize the class the same way as the 
java tool.

Here is a use case:
u.A and t.B are two classes. 
main is defined only in A.
java t.B should call t.B class initialisation
but when used inside a ant buildfile it doesn't work this way :
---------------------------------------------------------------
U:\test>ant
Buildfile: build.xml

compile:

run:
A CLASS INITIALIZATION<<<<<< hey what about B!
MAIN
I am a A.

all:

BUILD SUCCESSFUL

Total time: 1 second

U:\test>java -classpath build t.B
A CLASS INITIALIZATION
B CLASS INITIALIZATION<<<< Ok that is better!
MAIN
I am a B.

Here is a list of files and contents :

build.xml
-------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<project name="test" default="all">
<target name="all" depends="run" />

<target name="run" depends="compile">
  <java className="t.B">
    <classpath>
      <pathelement path="build"/>
    </classpath> 
  </java>
</target>

<target name="compile">
  <javac destdir="build" srcdir=".">
    <patternset>
      <include name="**/*.java"/>
    </patternset>
    <classpath>
      <pathelement path="."/>
    </classpath>
  </javac>
</target>
<target name="init">
  <mkdir dir="build"/>
</target>
</project>
------------------------------
t/B.java:
------------------------------
package t;
public class B extends u.A
{
  static 
  {
    System.out.println("B CLASS INITIALIZATION");
    setA(new B());
  }
  public String toString()
  { 
    return "I am a B.";
  }
}
------------------------------
u/A.java:
------------------------------
package u;
public class A
{
  public static void main(String [] args){
    System.out.println("MAIN");
    System.out.println(a);
  }
  static A a=new A();
  
  static 
  {
    System.out.println("A CLASS INITIALIZATION");
  }
  
  protected static void setA(A oa)
  {
    a=oa;
  }
   
  public String toString()
  { 
    return "I am a A.";
  }
       
}

Any clue of what is wrong?
Comment 1 pedro Cristian 2001-04-17 09:28:07 UTC
Created attachment 94 [details]
a jar with the test case.
Comment 2 Stefan Bodewig 2001-05-03 06:32:54 UTC

*** This bug has been marked as a duplicate of 1613 ***
Comment 3 Magesh Umasankar 2002-01-17 11:15:32 UTC
Using IBM JDK 1.1.8, even if I invoke java -classpath build t.B from the 
commandline, it still doesn't print out "B CLASS INITIALIZATION".  In other
words, IBM's JDK1.1.8 implementation of static initialization is flawed, IMO.
Comment 4 Magesh Umasankar 2002-01-17 12:09:37 UTC
In IBM JDK 1.3, it works as it should on the commandline. i.e., it prints
"B CLASS INITIALISATION" properly.  Would it be a good stand to take if we say 
Ant's <java> task will work only as good as the JVM's java task?