ClassNotFoundException

14 views
Skip to first unread message

zvik...@gmail.com

unread,
May 18, 2009, 8:15:16 AM5/18/09
to jsonmarshaller
I have a class A that contains a reference to another class B.

Calling TwoLattes.createMarshaller with class A fails with
ClassNotFoundException thrown for the nested class B.

Code is running in application server and both classes A & B are in
the same location. What might be the source of the problem?

thanks

Pascal-Louis Perez

unread,
May 18, 2009, 1:20:39 PM5/18/09
to jsonmar...@googlegroups.com
Would you have some sample code? Is this fully reproducible or intermittent?

PL
--
Play, Learn, Earn - www.kaChing.com

zvik...@gmail.com

unread,
May 19, 2009, 2:28:15 AM5/19/09
to jsonmarshaller

Classes are below.
I'd also like to point out that after changing the followings in
EntitySignatureVisitor

ClassLoader loader = Thread.currentThread
().getContextClassLoader(); //Added
Class<?> c = Class.forName(className.replace('/',
'.'),false,loader); // Added

// Class<?> c = Class.forName(className.replace('/', '.'));

the problem has disappeared.

Class A is:
@com.twolattes.json.Entity
public class ShoppingCartView implements java.io.Serializable,
java.lang.Cloneable {
@com.twolattes.json.Value
(name = "shoppingCartId", optional = true)
private java.lang.String m_ShoppingCartId;
@com.twolattes.json.Value
(name = "totalOc", optional = true)
private java.lang.Double m_TotalOc;
@com.twolattes.json.Value
(name = "shoppingCartItems", optional = true)
private
com.amdocs.css.core.order.shoppingcart.ShoppingCartItemView[]
m_ShoppingCartItems;
}

Class B is:
@com.twolattes.json.Entity
public class ShoppingCartItemView implements java.io.Serializable,
java.lang.Cloneable {
@com.twolattes.json.Value
(name = "shoppingCartItemId", optional = true)
private java.lang.String m_ShoppingCartItemId;
@com.twolattes.json.Value
(name = "quantity", optional = true)
private java.lang.Integer m_Quantity;
@com.twolattes.json.Value
(name = "oc", optional = true)
private java.lang.Double m_Oc;
@com.twolattes.json.Value
(name = "isConfigure", optional = true)
private java.lang.Boolean m_IsConfigure;
}


On May 18, 8:20 pm, Pascal-Louis Perez <pascallouispe...@gmail.com>
wrote:
> Would you have some sample code? Is this fully reproducible or intermittent?
>
> PL
>

Pascal-Louis Perez

unread,
May 19, 2009, 2:48:44 AM5/19/09
to jsonmar...@googlegroups.com
Based on your fix, it seams that the class loader which loaded the
EntitySignatureVisitor (I suppose the json jar?), is unable to find
ShoppingCartItemView. It would be interesting to know what is the
class path on which the JsonMarshaller is loaded, as well as the
classpath of the ShoppingCartItemView.

Since things work with the context class loader (the one that was used
to create the current thread) it means that your class loaders are
somewhat isolated from each other (very normal in a web app context).

It might be wise for the JsonMarshaller to allow passing the class
loader to be used, something like

TwoLattes.createMarshaller(Foo.class, myClassLoader);

this way it would be easy to override the default behavior.

Does that sound reasnnable?

PL

zvik...@gmail.com

unread,
May 20, 2009, 8:36:03 AM5/20/09
to jsonmarshaller
Yes, it'll be helpfull. It requires changes to the library, right?

I'm still puzzled regrading how the containing class was loaded while
the nested class has not.

On May 19, 9:48 am, Pascal-Louis Perez <pascallouispe...@gmail.com>
wrote:
> Play, Learn, Earn -www.kaChing.com- Hide quoted text -
>
> - Show quoted text -

Pascal-Louis Perez

unread,
Jun 4, 2009, 9:37:32 AM6/4/09
to jsonmar...@googlegroups.com
It does, yes.

It is hard to say without knowing the code, but it is feasible that
the outer class is loaded by the framework but the inner class is
never referenced prior to the JM accessing it. The JVM has no notion
of inner classes, it is pure syntactic sugar offered by Java and so it
is absolutely feasible to load an outer class without loading the
inner class.

PL

zvik...@gmail.com

unread,
Jun 7, 2009, 9:36:40 AM6/7/09
to jsonmarshaller
Do you think the fix will be part of the next version?

Actually the two classes are defined in separate files and one class
simply references the other.

On Jun 4, 4:37 pm, Pascal-Louis Perez <pascallouispe...@gmail.com>
wrote:
> >> Play, Learn, Earn -www.kaChing.com-Hide quoted text -

Pascal-Louis Perez

unread,
Jun 7, 2009, 4:08:14 PM6/7/09
to jsonmar...@googlegroups.com
The best way to ensure that, is to submit a patch.

It might make it, yes. But the issue 2 and 20 have higher priority.

PL
Reply all
Reply to author
Forward
0 new messages