DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6289>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6289

java.lang.ClassFormatError during instantiation of translets





------- Additional Comments From [EMAIL PROTECTED]  2002-02-13 23:16 -------
Ok, finally I could gain some more information about what's wrong here. I 
compiled the stylesheet and did a transformation (using the cmdline classes). 
It worked fine for me as well. Then I figured out that the difference between 
what I do to instantiate translets and what the cmdline classes do is the 
following. The cmdline classes use:

Class.forName() and newInstance() to instantiate a translet.

Fair enough. But what I do to instantiate is using the defineClass(String,byte
[],int,int) method in java.lang.ClassLoader. This is neccesary to avoid writing 
translets to the disk. Rather I fetch the bytecode from XSLTC and instantiate 
them this way. This saves I/O and seems to be the direct way to do it. But this 
is exactly what causes the problem. The defineClass(...) method throws that 
ClassFormatError. I have no clue why the Error does not appear when using 
newInstance(), but thats the facts.

I included a sample file showing the problem.

What can we do?

--------------------------------------------------------

import java.io.*;
import org.apache.xalan.xsltc.Translet;

public class TestLoader extends ClassLoader {

        public static void main(String[] args) throws Exception {

                final Class clazz = Class.forName("input_xsltc_bug_6289");
                final Translet translet = (Translet) clazz.newInstance();
                System.out.println("clazz.newInstance() successful");

                FileInputStream fis = new FileInputStream(
                        new File("input_xsltc_bug_6289.class")
                );
                ByteArrayOutputStream out = new ByteArrayOutputStream();

                int c = fis.read();
                while (c != -1) {
                        out.write(c);
                        c = fis.read();
                }
                TestLoader t = new TestLoader();
                Class c = t.defineClass(null, out.toByteArray(), 0, 
out.toByteArray().length);
                System.out.println("defineClass() successful");
        }

        public Class myDefineClass(String name,byte[] bytes,int off,int length) 
{
                return defineClass(name,bytes,off,length);
        }
}

Reply via email to