|
| Problem | What is the cause of java.lang.NullPointerException | | Cause | The Java runtime throws java.lang.NullPointerException when an application attempts to use a null value as if it were an object. The most likely cause is when the application attempts to invoke a method on an object that it believes has been initiated, but that is, in fact, null. Applications developed in C or C++ (and other languages) would trap with a segmentation violation in this case, but the Java runtime detects the null object and throws java.lang.NullPointerException instead. Other reasons this exception might be raised include the following:- Accessing attributes (such as, instance variables) on the null object;
- Attempting to use the null object as if it were an array;
- Throwing a null object as if it were an instance of java.lang.Throwable.
Basically, any attempt to operate on an object that has not been initiated will result in this exception. | | Solution | When customers report a java.lang.NullPointerException you should ask them to send you the Java stack trace that shows the call stack up to the point where the exception was thrown. Following are the cases you're most likely to encounter:- If it was thrown while executing customer application code you should explain to them these typical reasons for why this exception occurs and ask them to review their application to ensure this verifies that objects have been initiated before attempting to use them.
- If the exception is thrown while executing in WebSphere code, then it still may be a bug in the customer's application and confirming that will involve determining if there is application code being executed higher in the call stack. It may be necessary to request the Java source to the customer's code that appears in the call stack before the exception.
- If the exception is thrown while executing in WebSphere code then it may be a bug in WebSphere Application Server. If the problem can easily be repeated, you should ask the customer to enable tracing for the WebSphere class hierarchy from the call stack and then send the resulting trace and logs to the backend for further analysis. If the problem is difficult to recreate, then gather the existing WebSphere logs and a description of what the application was doing when the exception occurred.
Coding errors that might result in java.lang.NullPointerException include, but are not limited to the following:- Allocating a class variable but failing to initiate it (such as, "new" it) before using it;
- Passing null as an object parameter to a method.
| |
| |
| |
|
Product categories: Software, Application Servers, Distributed Application & Web Servers, WebSphere Application Server, Servlet Engine/Web Container Operating system(s): Multi-Platform Software version: 3.5, 4.0, 5.0 Software edition: Edition Independent Reference #: 1003414 IBM Group: Software Group Modified date: 2004-07-28
(C) Copyright IBM Corporation 2000, 2004. All Rights Reserved.
|