myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: Validation Messages - javax.faces.validator._MessageUtils
Date Thu, 30 Nov 2006 20:56:14 GMT
R. Müller wrote:
> Hi group,
> i have a very special question concering the validation messages.
> In my special case, i have to put the myfaces-jars to the 
> tomcat-endorsed dir (please don't ask why - its a long story).
> I figured out, if thats the case, myfaces is not able to load the 
> resources and jumps out with a NullPointerException : the classloader is 
> null. Since the javax.faces.validator._MessageUtils tries to load the 
> bundle with the 'facesContext.getClass().getClassLoader()' which is 
> null, for some reason.

I'm surprised that this is null. The classloader hierarchy for modern 
jvms should be something like:

endorsed-extensions classloader
system classloader
tomcat shared classloader
webapp classloader

I expect stuff in the tomcat-endorsed directory gets loaded via the 
endorsed-extensions classloader.

The bootloader is a special one; classes that are loaded by it do indeed 
return null for getClassLoader(). However unless you're mucking around 
with -Xbootclasspath command-line options, only classes from the JDK 
(java.*) will be loaded by this.

So in your case, facesContext.getClass().getClassLoader() should be 
returning the endorsed-extensions classloader which will NOT be null. So 
I can't understand why you are getting the results you see.

You aren't using java 1.3 are you?

> There are several other approachs to load the bundle then, by catching a 
> MissingResourceException, but thats not the point here, there occured a 
> NullPointerExcpetion.
> I've commentet out all the stuff and load the bundle simply with :
> ResourceBundle.getBundle(bundleName,locale)
> without any special classloader and it works for me. :-)
> If some can explain this i would very appriciate...

Have a look at the javadoc for the ResourceBundle.getBundle method. It 
says that the classpath it uses to try to find the resource is that of 
"the caller's classloader".

Suppose you write a custom FacesContext class, and bundle it with your 
webapp, but have the myfaces.jar in a shared dir of the appserver. In 
this case, the existing code will look in your webapp for the resource 
bundle file, while your code will not.

There are no doubt other setups where this code makes a difference. In 
other words, great care would be needed before making any modifications 
to this code.



View raw message