Autoboxing & Null Pointers

By this time, you should all be used to the java 5 concepts and most of you might be using them in your development. There are few naunces to the auto boxing, which we should be handling carefully.

One fine day, in a flow, suddenly i get a NPE. Looking through the logs, i was astonished to find where it occurred.

Long userId = args.getParameter("UserId");

int resultCount = updateAllUserInfo(userId, userVO); -- The line where NPE occured.

For an instance, i was wondering, how will NPE occur without us doing any object related operations!

Have a look at the updateAllUserInfo() method signature below.


private updateAllUserInfo(long userId, UserVO userVO){
.
.
}


The user id i pass to the method is a Long object, but the method takes in the primitive long. With the tiger, java takes care of converting an object to primitive value & hence the exception.

interesting finding for the day!




Powered by ScribeFire.

Comments