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] Updated: (HARMONY-4052) [drlvm][kernel] Compatibility: ClassLodert.defineClass() throws ClassFormatError for class with incorrect name only when -Xverify option is set while RI always throws this error
Date Wed, 06 Jun 2007 05:40:26 GMT

     [ https://issues.apache.org/jira/browse/HARMONY-4052?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Vera Petrashkova updated HARMONY-4052:
--------------------------------------

    Attachment: aaa_class.zip

Source code and class file for used aaa class

> [drlvm][kernel] Compatibility: ClassLodert.defineClass() throws ClassFormatError for
class with incorrect name only when -Xverify option is set while RI always throws this error
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-4052
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4052
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>         Environment: Windows and Linux
>            Reporter: Vera Petrashkova
>            Priority: Minor
>
> According to J2SE specification ClassLoader.defineClass(String name, byte[] b, int off,
int len) method throws ClassFormatError if the data did not contain a valid class.
> When the data contain some class with incorrect class name then DRLVM throws ClassFormatError
only if -Xverify option was set.
> Otherwise it throws VerifyError when name is not null and LinkageError when name equals
null.
> RI always throws ClassFormatError when used class contains wrong name.
> The following test demonstrates this issue. It uses synthetic class aaa which are placed
to the attachment
> ---------------------a1.java----------------------
> import java.io.*;
> public class a1 { 
>  
>    public static void main (String[] args) { 
>         byte[] bbb1 = new byte[11];
>         byte[] bbb2 = new byte[500];
>         int lastBytes = 0;
>         String name = "";
>         String name1 = "";
>         try { 
>             Class firstCl = Class.forName("aaa");
>             InputStream is = firstCl.getResourceAsStream("aaa.class");
>             if (is == null) {
>                 System.err.println("Can not open InputStream : aaa.class");
>                 return;
>             }
>             DataInputStream dIn = new DataInputStream(is);
>             dIn.read(bbb1, 0, 11);
>             dIn.readUTF();
>             lastBytes = dIn.read(bbb2, 0, bbb2.length);
>             dIn.close();
>         } catch (Throwable e) {
>             e.printStackTrace();
>             System.err.println("Test failed");
>             return;
>         }
>         myClassLoader cLoad = new myClassLoader();
>         try {
>             name = "[Zaaabbb";
>             name1 = name;
>             System.err.println("Use name: "+name1);
>             ByteArrayOutputStream bos = new ByteArrayOutputStream();
>             DataOutputStream dOut = new DataOutputStream(bos);
>             dOut.write(bbb1, 0, 11);
>             dOut.writeUTF(name);
>             dOut.write(bbb2, 0, lastBytes);
>             dOut.close();
>             byte[] b1 = bos.toByteArray();
>             Class cl = cLoad.defineKlass(name, b1, 0, b1.length);
>             System.err.println("Test failed: ClassFormError was not thrown as expected");
>         } catch (ClassFormatError e) {
>             e.printStackTrace();
>             System.err.println("Test passed");
>         } catch (Throwable e) { 
>             e.printStackTrace(); 
>             System.err.println("Test failed");
>              
>         } 
>         try {
>             name = "[Zaaabbb";
>             name1 = null;
>             System.err.println("Use name: "+name1);
>             ByteArrayOutputStream bos = new ByteArrayOutputStream();
>             DataOutputStream dOut = new DataOutputStream(bos);
>             dOut.write(bbb1, 0, 11);
>             dOut.writeUTF(name);
>             dOut.write(bbb2, 0, lastBytes);
>             dOut.close();
>             byte[] b1 = bos.toByteArray();
>             Class cl = cLoad.defineKlass(name, b1, 0, b1.length);
>             System.err.println("Test failed: ClassFormError was not thrown as expected");
>         } catch (ClassFormatError e) {
>             e.printStackTrace();
>             System.err.println("Test passed");
>         } catch (Throwable e) { 
>             e.printStackTrace(); 
>             System.err.println("Test failed");
>              
>         } 
>     } 
> } 
> class myClassLoader extends ClassLoader {
>     public Class defineKlass(String name, byte[] ar, int st, int len) {
>         return super.defineClass(name, ar, st, len);
>     }
> }
> ---------------------------aaa.ccode------------------------
> magic = xCAFEBABE
> minor_version = 3
> major_version = 45
> constant_pool_count = 12
> constant_pool {
>   /* #1 */ UTF8 = "aaa"
>   /* #2 */ Class = #3
>   /* #3 */ UTF8 = "java/lang/Object"
>   /* #4 */ Class = #1
>   /* #5 */ UTF8 = "<init>"
>   /* #6 */ UTF8 = "()V"
>   /* #7 */ UTF8 = "Code"
>   /* #8 */ Method = #2 #9
>   /* #9 */ NameAndType = #5 #6
>   /* #10 */ UTF8 = "I"
>   /* #11 */ UTF8 = "testF"
> }
> access_flags = PUBLIC SUPER
> this_class = #4
> super_class = #2
> interfaces_count = 0
> fields_count = 1
> fields {
>     field {
>         access_flag = PUBLIC
>         name_index = #11
>         descriptor_index = #10
>         attributes_count = 0
>     }
> }
> methods_count = 1
> methods {
>     method {
>         access_flag = PUBLIC
>         name_index = #5
>         descriptor_index = #6
>         attributes_count = 1
>         attributes {
>             attribute Code {
>             attribute_name_index = #7
>             attribute_length = 17
>             max_stack = 1
>             max_locals = 1
>             code_length = 5
>             code asm {
>                 0:    aload_0
>                 1:    invokespecial #8
>                 4:    return
>             }
>             exception_table_length = 0
>             attributes_count = 0
>             }
>         }
>     }
> }
> attributes_count = 0
> ----------------------------------------
> Run test
> java a1
> java -Xverify a1
> 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)
> Use name: [Zaaabbb
> java.lang.ClassFormatError: Illegal class name "[Zaaabbb" in class file [Zaaabbb
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:41)
> Test passed
> Use name: null
> java.lang.ClassFormatError: Illegal class name "[Zaaabbb" in class file [Zaaabbb
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:62)
> Test passed
> 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)
> Use name: [Zaaabbb
> java.lang.ClassFormatError: Illegal class name "[Zaaabbb" in class file [Zaaabbb
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:41)
> Test passed
> Use name: null
> java.lang.ClassFormatError: Illegal class name "[Zaaabbb" in class file [Zaaabbb
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:62)
> Test passed
> Output on DRLVM:
> ===============
> 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 = r544083, (Jun  4 2007), Windows/ia32/msvc 1310, debug build
> http://harmony.apache.org
> Use name: [Zaaabbb
> java.lang.VerifyError: (class: [Zaaabbb, method: <init>()V) Constructor must be
invoked
>         at java.lang.ClassLoader.defineClass0(ClassLoader.java)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:437)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:378)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:41)
> Test failed
> Use name: null
> java.lang.LinkageError: Illegal attempt to redefine class : [Zaaabbb
>         at java.lang.ClassLoader.defineClass0(ClassLoader.java)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:437)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:378)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:62)
> Test failed
> 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 = r544083, (Jun  4 2007), Windows/ia32/msvc 1310, debug build
> http://harmony.apache.org
> Use name: [Zaaabbb
> java.lang.ClassFormatError: [Zaaabbb: illegal CONSTANT_Class name "[Zaaabbb"
>         at java.lang.ClassLoader.defineClass0(ClassLoader.java)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:437)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:378)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:41)
> Test passed
> Use name: null
> java.lang.ClassFormatError: [Zaaabbb: illegal CONSTANT_Class name "[Zaaabbb"
>         at java.lang.ClassLoader.defineClass0(ClassLoader.java)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:437)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:378)
>         at myClassLoader.defineKlass(a1.java:80)
>         at a1.main(a1.java:62)
> Test passed
> This bug causes the failures of the tests from Stress test suite (https://issues.apache.org/jira/browse/HARMONY-3536)
> stress.org.apache.harmony.test.stress.classloader.MixSynchThreads.LargeClassName.testLargeClassName_W1
> stress.org.apache.harmony.test.stress.classloader.MixThreads.LargeClassName.testLargeClassName_W2
> stress.org.apache.harmony.test.stress.classloader.NotSynchThreads.LargeClassName.testLargeClassName_W1
> stress.org.apache.harmony.test.stress.classloader.NotSynchThreads.LargeClassName.testLargeClassName_W2
> stress.org.apache.harmony.test.stress.classloader.OneThread.LargeClassName.testLargeClassName_W1
> stress.org.apache.harmony.test.stress.classloader.OneThread.LargeClassName.testLargeClassName_W2
> stress.org.apache.harmony.test.stress.classloader.SynchThreads.LargeClassName.testLargeClassName_W1
> stress.org.apache.harmony.test.stress.classloader.SynchThreads.LargeClassName.testLargeClassName_W2

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message