Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

static classloading issue...

Thread view: 
asaguden - 15 Feb 2007 12:14 GMT
Hi,
We are facing a hard-to-debug problem i our Weblogic server.
The problem has something to do with errors in the classloading
process.

- Here is the exception:
<exception>
...Root cause of ServletException:    java.lang.NoClassDefFoundError
A.init ( a.java 3 )
</exception>

- Here is the setup ( pseudo code, may not compile ):
<code>
public class A{
   init(){
       B b = new B( );
   }
}

public class B{

   // static attributes
   public static HashMap map;

   private static final String VAL_1 = "value1";
   private static final String VAL_2 = "value2";
   private static final String VAL_3 = "value3";
   private static final String VAL_4 = "value4";
   private static final String VAL_CS = "value4";
   private static final String VAL_BS = "value4";

   private static final List prod_cs =
ProductHelper.getInstance().getAllProducts( new Category(CS) );
   private static final List prod_bs =
ProductHelper.getInstance().getAllProducts( new Category(BS) );
   ...

   // static methods...

   // static block
   static{
       map = new HashMap( );

       map.put(  "val1", VAL_1  );
       map.put(  "val2", VAL_2  );
       map.put(  "val3", VAL_3  );
       map.put(  "val4", VAL_4  );
       map.put(  VAL_BS, prod_bs  );
       map.put(  VAL_CS, prod_cs  );
      ...

   }
   }
}
</code>

As seen in the exception, probable cause is that B is not initialized.
Can someone explain
exactly what happens in the scenario where something in
ProductHelper.getInstance().getAllProducts()
fails...?

PS. The names have been changed to protect the bla bla...

Regards asaguden
Andrey Ryabov - 15 Feb 2007 13:13 GMT
> Hi,
> We are facing a hard-to-debug problem i our Weblogic server.
[quoted text clipped - 62 lines]
>
> Regards asaguden

Sounds like an exception throws in static initializer.
Check if  ProductHelper.getInstance().getAllProducts( new
Category(CS)); throws exception..
In generally it's very bad idea to perform any except trivial
initialization in static initializer
Daniel Pitts - 17 Feb 2007 01:49 GMT
> Hi,
> We are facing a hard-to-debug problem i our Weblogic server.
[quoted text clipped - 62 lines]
>
> Regards asaguden

Consider the bla bla protected :-)

Anyway, if you are using Spring, Hibernate, or any other library that
relies on cglib, you might get this exception after a number of hot-
deploys.

We've seen this happen in Resin, where after a while, we start getting
spurious NoClassDefFoundError and OutOfMemoryError: Java heap space

If this still occures with a cold deploy (restarting the container),
then it is a problem somewhere else.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.