From owner-freebsd-java Wed Dec 15 16: 0:58 1999 Delivered-To: freebsd-java@freebsd.org Received: from securitas.net (extern.securitas.net [212.66.1.45]) by hub.freebsd.org (Postfix) with ESMTP id 5606015634; Wed, 15 Dec 1999 16:00:53 -0800 (PST) (envelope-from grossman@securitas.net) Received: from blue.securitas.net (grossman@blue.securitas.net [212.66.0.24]) by securitas.net (8.9.3/8.9.3) with ESMTP id BAA07227; Thu, 16 Dec 1999 01:00:12 +0100 (MET) Received: (from grossman@localhost) by blue.securitas.net (8.8.5/8.7.3) id AAA23703; Thu, 16 Dec 1999 00:58:19 +0100 (MET) Date: Thu, 16 Dec 1999 00:58:19 +0100 (MET) Message-Id: <199912152358.AAA23703@blue.securitas.net> From: Rolf Grossmann MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="7jGBHTmUit" Content-Transfer-Encoding: 7bit To: freebsd-java@FreeBSD.org Cc: java-port@FreeBSD.org Subject: Duplicate Class initialization? X-Mailer: VM 6.62 under Emacs 19.34.2 Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org --7jGBHTmUit Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit Hi all, I'm having a small problem (what seems to be a bug) with the FreeBSD JDK. The static initializer for a class is called the first time when that class is referenced from a third class that is loaded dynamically and a second time after a socket connection has been accepted and the class is referenced from the main program. The exact scenario can be seen from the attached test case. It is the simplest test case I was able to figure out. It does not happen when you access the Class directly before (or without) accepting the socket. To verify the problem, compile the 3 attached classes and run java Main. You will see the classes being initialized. From another shell, make a socket connection to port 2222 on that host. Wonder why Class1 is being initialized again. The problem does not occur on Solaris, so I guess it's FreeBSD specific. It also does not happen when using TYA. I'm using the jdk1.1.8_ELF.V1999-11-9 on FreeBSD 3.3-STABLE (as of 2-3 months ago). Bye, Rolf --7jGBHTmUit Content-Type: text/plain Content-Description: Main.java Content-Disposition: inline; filename="Main.java" Content-Transfer-Encoding: 7bit import java.lang.Class; import java.net.*; import java.io.*; class Main { public static void main (String args[]) { ServerSocket sock; try { sock = new ServerSocket(2222); } catch(IOException e) { System.exit(1); // Security may prevent exit ... return; // but not return } try { Class.forName("Class2"); } catch(ClassNotFoundException e) { } try { Socket s = sock.accept(); Class1.fn(); } catch(IOException e) {} } } --7jGBHTmUit Content-Type: text/plain Content-Description: Class1.java Content-Disposition: inline; filename="Class1.java" Content-Transfer-Encoding: 7bit import java.util.Vector; class Class1 { private static Vector v = new Vector(); static { System.out.println("Init Class1"); } public static void register(Class2 c) { v.addElement(c); System.out.println("register"); } public static void fn() {} } --7jGBHTmUit Content-Type: text/plain Content-Description: Class2.java Content-Disposition: inline; filename="Class2.java" Content-Transfer-Encoding: 7bit class Class2 { static { System.out.println("Start Class2"); Class1.register(new Class2()); System.out.println("End Class2"); } private Class2() { } /* ... */ } --7jGBHTmUit-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message