exception java.lang.ClassCircularityError

Joined
Mar 16, 2011
Messages
1
Reaction score
0
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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top