exception java.lang.ClassCircularityError

Discussion in 'Java' started by arraylist, Mar 16, 2011.

  1. arraylist

    arraylist

    Joined:
    Mar 16, 2011
    Messages:
    1
    Hi. I have some problem. I send from server to client stream bytes by socket, which contains serialized object and his implementation class. This part of bytes, which contains implementation class I load it my own ClassLoader:


    public class MyLoader extends ClassLoader {

    byte[] buf;

    public MyLoader(byte[] buf) {
    this.buf = buf;
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
    return defineClass(null, buf, 0, buf.length);
    }


    the rest part of bytes is readed by ObjectReader, which extends ObjectInputStream, because I need to apply my ClassLoader(MyLoader):


    public class ObjectReader extends ObjectInputStream {

    byte[] buf;

    public ObjectReader(InputStream input, byte[] buf) throws IOException {
    super(input);
    this.buf = buf;
    }

    @Override
    protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException
    {
    String name = desc.getName();
    try {
    return Class.forName(name, false, new MyLoader(buf));
    } catch (ClassNotFoundException ex) {
    throw ex;
    }
    }
    }


    When I run this code I obtain exception:


    java.lang.ClassCircularityError: blabla/Impl
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :616)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :466)
    at register.MyLoader.findClass(MyLoader.java:46)


    Can you help me with this error. I used to NetBeansIDE. When I run this code in desktop project no exception thrown, but when I run it in web project this exception occur.

    Thanks.
    arraylist, Mar 16, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harald Kirsch
    Replies:
    4
    Views:
    2,819
    Harald Kirsch
    Aug 31, 2004
  2. jclang@web.de

    ClassCircularityError

    jclang@web.de, Jan 20, 2005, in forum: Java
    Replies:
    1
    Views:
    4,652
    John C. Bollinger
    Jan 20, 2005
  3. JPractitioner
    Replies:
    13
    Views:
    20,127
    Roedy Green
    Feb 24, 2006
  4. clusardi2k@aol.com
    Replies:
    13
    Views:
    1,396
    Stuart
    Sep 23, 2012
  5. morpheous.sigma@gmail.com
    Replies:
    2
    Views:
    441
Loading...

Share This Page