-
Bug
-
Resolution: Fixed
-
P3
-
1.1.2
-
1.2alpha2
-
sparc
-
solaris_2.5
-
Not verified
Name: szC45993 Date: 05/13/97
The Java Virtual Machine, chapter 2 Concepts,
section 2.16.5 Detailed Initialization Procedure, claims:
"
7. ... If the initialization of the superclass completes abruptly because of a thrown exception, then lock this Class object, label it erroneous, notify all waiting threads, release the lock, and complete abruptly, throwing the same exception that resulted from initializing the superclass.
"
Meanwhile, undermentioned test shows that the exception is not reARISEN for
class initialization when the initialization of the superclass was completed
abruptly, for example, under the dividing on zero.
The test gives the following mistaken result (jdk_1.1.2):
----------------------------------------------------------------------------
Thread = 1, ss = enter BEGIN CONTINUE exit
Thread = 2, ss = enter BEGIN CONTINUE exit
Thread = 3, ss = enter BEGIN CONTINUE exit
Thread = 4, ss = enter BEGIN CONTINUE exit
Thread = 5, ss = enter BEGIN CONTINUE exit
ERROR5: if the initialization of the superclass completes abruptly because of a thrown exception, then THIS CLASS INITIALIZATION MUST BE COMPLETED ABRUPTLY, throwing the same exception that resulted from initializing the superclass.
----------------------------------------------------------------------------
The result shows that superclass initialization is completed abruptly ("END" is absent
into the String ss value, it means that the "/ by zero" was arisen) but no exception
is arisen under the class initialization.
See sources below.
--------------------- execution05501.java
//File: @(#)execution05501.java 1.1 97/05/13
//Copyright 05/13/97 Sun Microsystems, Inc. All Rights Reserved
package javasoft.sqe.tests.vm.execution.execution055.execution05501;
import java.io.PrintStream;
import java.lang.*;
public class execution05501 {
public static int run(String argv[], PrintStream out) {
try{
execution05501a exca1 = new execution05501a();
exca1.num = 1;
Thread thr1 = new Thread(exca1);
thr1.start();
execution05501a exca2 = new execution05501a();
exca2.num = 2;
Thread thr2 = new Thread(exca2);
thr2.start();
execution05501a exca3 = new execution05501a();
exca3.num = 3;
Thread thr3 = new Thread(exca3);
thr3.start();
execution05501a exca4 = new execution05501a();
exca4.num = 4;
Thread thr4 = new Thread(exca4);
thr4.start();
execution05501a exca5 = new execution05501a();
exca5.num = 5;
Thread thr5 = new Thread(exca5);
thr5.start();
if (thr1.isAlive()){
thr1.join();
}
if (thr2.isAlive()){
thr2.join();
}
if (thr3.isAlive()){
thr3.join();
}
if (thr4.isAlive()){
thr4.join();
}
if (thr5.isAlive()){
thr5.join();
}
} catch (Throwable e) {
out.println("MESSAGE1: Error/Exception in execution05501: "+ e);
return 2;
};
if (execution05501c.strng.indexOf("END") != -1) {
out.println("ERROR4: superclass initialization exception is not arisen!");
return 2;
}
if (execution05501c.res == 2) {
out.println("ERROR5: if the initialization of the superclass completes abruptly because of a thrown exception, then THIS CLASS INITIALIZATION MUST BE COMPLETED ABRUPTLY, throwing the same exception that resulted from initializing the superclass.");
return 2;
}
if (execution05501c.res == 3) {
return 2;
}
return execution05501c.res;
}
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
}
--------------------- execution05501a.java
//File: @(#)execution05501a.java 1.1 97/05/13
//Copyright 05/13/97 Sun Microsystems, Inc. All Rights Reserved
package javasoft.sqe.tests.vm.execution.execution055.execution05501;
class execution05501a implements Runnable {
public int num;
public void run() {
execution05501b excb = null;
///////////////////////////////////////////////////////////////////////////////
//The attempt of the class execution05501b initialization must be here:
///////////////////////////////////////////////////////////////////////////////
try{
excb = new execution05501b();
excb.mthd(num);
} catch (Throwable e) {
System.out.println(e);
if (((Object) e).getClass().getName().indexOf("ExceptionInInitializerError") == -1) {
System.out.println("ERROR1: not ExceptionInInitializerError");
execution05501c.put(3);
return;
}
try{
if (((Object) ((ExceptionInInitializerError) e).getException()).getClass().getName().indexOf("ArithmeticException") == -1) {
System.out.println("ERROR2: not ExceptionInInitializerError");
execution05501c.put(3);
return;
}
execution05501c.put(0);
return;
} catch (Throwable ee) {
System.out.println("MESSAGE3: " + ee);
System.out.println("ERROR3: new instance of the class ExceptionInInitializerError creation instead of E-exception and using this object in place of exception in the following step, BUT WITHOUT E-exception as the argument (must be: new ExceptionInInitializerError(E-exception), but new ExceptionInInitializerError() is really ).");
execution05501c.put(3);
return;
}
};
///////////////////////////////////////////////////////////////////////////////
}
}
--------------------- execution05501b.java
//File: @(#)execution05501b.java 1.1 97/05/13
//Copyright 05/13/97 Sun Microsystems, Inc. All Rights Reserved
package javasoft.sqe.tests.vm.execution.execution055.execution05501;
public class execution05501b extends execution05501d{
static int i = 1;
static int j = 1;
static int k = 5;
static String ss = "enter ";
static {
execution05501c.strng = execution05501c.strng.concat("enter ");
i += 1;
j += 1;
execution05501c.strng = execution05501c.strng.concat(" exit");
ss = ss.concat(execution05501d.str);
ss = ss.concat(" exit");
}
public static void mthd(int num) {
System.out.println("Thread = "+num+", ss = "+ss);
i += j;
}
}
--------------------- execution05501c.java
//File: @(#)execution05501c.java 1.1 97/05/13
//Copyright 05/13/97 Sun Microsystems, Inc. All Rights Reserved
package javasoft.sqe.tests.vm.execution.execution055.execution05501;
import java.io.PrintStream;
public class execution05501c {
public static int res = 2;
public static String strng = "";
public static synchronized void put(int r) {
res = r;
}
public static synchronized int get() {
return res;
}
}
--------------------- execution05501d.java
//File: @(#)execution05501d.java 1.1 97/05/13
//Copyright 05/13/97 Sun Microsystems, Inc. All Rights Reserved
package javasoft.sqe.tests.vm.execution.execution055.execution05501;
public class execution05501d{
static int ii = 1;
static int jj = 1;
static String str = " BEGIN ";
static int kk = 1;
static {
execution05501c.strng = execution05501c.strng.concat(" BEGIN ");
ii += 1;
jj += 1;
execution05501c.strng = execution05501c.strng.concat(" CONTINUE ");
str = str.concat(" CONTINUE ");
//#############################################
kk = 1 / (ii - jj); //DIVIDIN BY ZERO #
//#############################################
execution05501c.strng = execution05501c.strng.concat(" END ");
str = str.concat(" END ");
}
}
---------------------
======================================================================