exception java.lang.ClassCircularityError

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

  1. arraylist


    Mar 16, 2011
    Likes Received:
    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;

    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 {
    this.buf = buf;

    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.

    arraylist, Mar 16, 2011
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.