harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vera Petrashkova (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-1930) [drlvm][classlib] java.lang.Class.newInstance() sometimes returns unexpected IllegalAccessException when several threads try to create instance of package access class
Date Fri, 20 Oct 2006 10:38:36 GMT
[drlvm][classlib] java.lang.Class.newInstance() sometimes returns unexpected IllegalAccessException
when several threads try to create instance of package access class
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: HARMONY-1930
                 URL: http://issues.apache.org/jira/browse/HARMONY-1930
             Project: Harmony
          Issue Type: Bug
          Components: DRLVM
         Environment: Windows and Linux
            Reporter: Vera Petrashkova


If some public method declared in the public class creates new instance of the package access
class
and this method is invoked by several threads then result is not stable.
Sometimes java.lang.Class.newInstance() throws IllegalAccessException.

Code for reproducing:
-----------------testClassNewInstance.java--------------
public class testClassNewInstance extends Thread {

    private static String[] clsN = { "testClassNewInstance", "cl1", "cl2", "cl11",
            "cl12", "cl21", "cl22", "cl111", "cl112", "cl121", "cl122",
            "cl211", "cl212", "cl221", "cl222", "cl1111", "cl1112", "cl1121",
            "cl1122", "cl1211", "cl1212", "cl1221", "cl1222", "cl2111",
            "cl2112", "cl2121", "cl2122", "cl2211", "cl2212", "cl2221",
            "cl2222" };

    public int test() { 
        String nm = "";
        try {
            for (int t = clsN.length - 1; t >=0; t--) {
                nm = clsN[t];  
                Class cl = Class.forName(nm);
                testClassNewInstance t3 = (testClassNewInstance)cl.newInstance();
            }
        } catch (Throwable e) {
            e.printStackTrace(System.err);
            return 106;
        }
        return 104;
    }

    public static int thN = 10;
    private int index;

    public testClassNewInstance(int index) {
        this.index = index;
    }
    public testClassNewInstance() {
        this.index = -1;
    }
    public void run() {
        System.err.println("Thread: "+this.index+" res="
                +new testClassNewInstance().test());
    }
    public static void main(String [] args) {
        try {
            // the first argument defines the number of threads 
            // (default value: 10)
            if (args.length > 0) {
                thN = Integer.parseInt(args[0]);
            }
            Thread [] tt = new testClassNewInstance[thN];
            for (int t = 0; t < thN; t++) {
                tt[t] = new testClassNewInstance(t);
            }
            for (int t = 0; t < thN; t++) {
                tt[t].start();
            }
            for (int t = 0; t < thN; t++) {
                tt[t].join();
            }
        } catch (Throwable e) {
          e.printStackTrace();
        }
    }
}

class cl1 extends testClassNewInstance {
}
class cl11 extends cl1 {
}
class cl12 extends cl1 {
}
class cl111 extends cl11 {
}
class cl112 extends cl11 {
}
class cl121 extends cl12 {
}
class cl122 extends cl12 {
}
class cl1111 extends cl111 {
}
class cl1112 extends cl111 {
}
class cl1121 extends cl112 {
}
class cl1122 extends cl112 {
}
class cl1211 extends cl121 {
}
class cl1212 extends cl121 {
}
class cl1221 extends cl122 {
}
class cl1222 extends cl122 {
}
class cl2 extends testClassNewInstance {
}
class cl21 extends cl2 {
}
class cl22 extends cl2 {
}
class cl211 extends cl21 {
}
class cl212 extends cl21 {
}
class cl221 extends cl22 {
}
class cl222 extends cl22 {
}
class cl2111 extends cl211 {
}
class cl2112 extends cl211 {
}
class cl2121 extends cl212 {
}
class cl2122 extends cl212 {
}
class cl2211 extends cl221 {
}
class cl2212 extends cl221 {
}
class cl2221 extends cl222 {
}
class cl2222 extends cl222 {
}
-----------------------------------------------------

The result is not stable so run one of these  commands several times (~10).

java -cp . testClassNewInstance 5
java -cp . testClassNewInstance

 
Output on RI:
--------------------------
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

Thread: 4 res=104
Thread: 0 res=104
Thread: 3 res=104
Thread: 1 res=104
Thread: 2 res=104
 

 
Output on Harmony:
----------------------------
Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors,
as applicable.
java version "1.5.0" 
pre-alpha : not complete or compatible
svn = r464471, (Oct 20 2006), Linux/ia32/gcc 3.3.3, release build
http://incubator.apache.org/harmony
java.lang.IllegalAccessException: A member of the "class cl2221" with "" modifiers can not
be accessed from the "class java.lang.Class"
        at java.lang.reflect.ReflectExporter.checkMemberAccess(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at testClassNewInstance.test(testClassNewInstance.java:15)
        at testClassNewInstance.run(testClassNewInstance.java:35)
java.lang.IllegalAccessException: A member of the "class cl2221" with "" modifiers can not
be accessed from the "class java.lang.Class"
        at java.lang.reflect.ReflectExporter.checkMemberAccess(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at testClassNewInstance.test(testClassNewInstance.java:15)
        at testClassNewInstance.run(testClassNewInstance.java:35)
java.lang.IllegalAccessException: A member of the "class cl2221" with "" modifiers can not
be accessed from the "class java.lang.Class"
        at java.lang.reflect.ReflectExporter.checkMemberAccess(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at testClassNewInstance.test(testClassNewInstance.java:15)
        at testClassNewInstance.run(testClassNewInstance.java:35)
Thread: 1 res=106
Thread: 4 res=106
Thread: 0 res=106
Thread: 2 res=104
Thread: 6 res=104
Thread: 7 res=104
Thread: 3 res=104
Thread: 9 res=104
Thread: 5 res=104
Thread: 8 res=104
 

Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors,
as applicable.
java version "1.5.0"

pre-alpha : not complete or compatible
svn = r464471, (Oct 20 2006), Windows/ia32/msvc 1310, release build
http://incubator.apache.org/harmony
java.lang.IllegalAccessException: A member of the "class cl1222" with "" modifiers can not
 be accessed from the "class java.lang.Class"
        at java.lang.reflect.ReflectExporter.checkMemberAccess(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at testClassNewInstance.test(testClassNewInstance.java:15)
        at testClassNewInstance.run(testClassNewInstance.java:35)
Thread: 2 res=104
Thread: 3 res=104
java.lang.IllegalAccessException: A member of the "class cl1222" with "" modifiers can not
 be accessed from the "class java.lang.Class"
        at java.lang.reflect.ReflectExporter.checkMemberAccess(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at testClassNewInstance.test(testClassNewInstance.java:15)
        at testClassNewInstance.run(testClassNewInstance.java:35)
Thread: 0 res=104
Thread: 4 res=106
Thread: 1 res=106



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message