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

Posted on 2006-05-19
Medium Priority
Last Modified: 2010-03-31
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);

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.)

Question by:Jaycee
  • 3
  • 3
  • 2
  • +1
LVL 24

Expert Comment

ID: 16716144
Class.forName() follows the current classloader. Does it change underway?


Author Comment

ID: 16716159
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 ...
LVL 24

Expert Comment

ID: 16716376
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 .........................

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 16716413
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...
LVL 24

Expert Comment

ID: 16716662
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.


;JOOP! (only wizard)
LVL 30

Expert Comment

by:Mayank S
ID: 16717544
Are you using System.getProperties () or setProperties () anywhere?

Author Comment

ID: 16717554
LVL 13

Expert Comment

ID: 16732600
Hi Jaycee,

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

ClassLoader loader;

// When you application start :

// Instead of Class.forName, use :
Class c = loader.loadClass(className);
LVL 13

Accepted Solution

Webstorm earned 1000 total points
ID: 16930501
I guess my comment may get the points.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question