Class.forName fails after a while (but runs at the start...)

Hello ,
I have a strange trouble on a very old application.
The context: (don't laught...)
-Webpshere Application server 2.03, jdk 1.1.8.

I have the following code :
    try {
      Class c = Class.forName(className);
      obj = (Object) c.newInstance();
    } catch (ClassNotFoundException ex) {
      Debug.logln("Class not found Exception: " + className);
      Debug.log(ex);


It can runs a full week (24/7), a full month, and sometimes, the forName throw the ClassNotFoundException...
And this for a single class, which IS in the class path because it runs well...
 
Any idea ?

(Please don't troll with "upgrade the app server, change the jdk, ... " ;). I have to stick with this.)

Jaycee
JayceeAsked:
Who is Participating?
 
WebstormCommented:
I guess my comment may get the points.
0
 
sciuriwareCommented:
Class.forName() follows the current classloader. Does it change underway?

;JOOP!
0
 
JayceeAuthor Commented:
Nope ...
It's a standart webapp, that runs 24/7, the server (software & hardware) and app server is used only for this application, and no human acivity on the config is done.
and I guess the classloader wouldn't change by itself ...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sciuriwareCommented:
That depends, may be some part of the application sets a different classloader.

Many stable and reliable applications contain a part that is seldom used, but that spoils the whole run.
I speak from 35 years of automation: computers don't make mistakes and you can't be sure of anything.
I've seen programs that suddenly dump 750Mb of waste, because there was this little subroutine that never had failed until ..........................

Go and check all sources and (!!!!) all added jar's or packages; open source is open, not unfailing .........................

;JOOP!
0
 
JayceeAuthor Commented:
The app uses some dll for SAP calls...
the majority of jar used is proprietary, and not opened. (and jad all class is not a solution ;)).
Do you know a way to detect a classlaoder / classpath /  ..  modification ?
I can add a check before each forName.
Can I programmatically store it and reset it if it's changed ? (I never play with classloader modification on runtime ... )

Thanks for your help so far...
0
 
sciuriwareCommented:
I too, never played with toys I didn't understand.

Now, the Class.forName() fails for a class that it should load.
Is it invalid or 'pointing' at a wrong place?
I guess that the classloader initially 'points' at the area defined by CLASSPATH.
So, could you try to load another class (after the failure) that just got to be there?

Here I rest my case, only "objects" and "CEHJ" might help you further.

GENIUSES, HELP!!


;JOOP! (only wizard)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Are you using System.getProperties () or setProperties () anywhere?
0
 
JayceeAuthor Commented:
nope...
0
 
WebstormCommented:
Hi Jaycee,

You may use the same classloader as initially, by using a ClassLoader reference :

ClassLoader loader;

// When you application start :
loader=Thread.currentThread().getContextClassLoader();

// Instead of Class.forName, use :
Class c = loader.loadClass(className);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.