Classloader.getResources() and IBM JDK

Kinman Chung and I  had a nice debugging session discovering an interesting difference in the classloading behavioural differences on Sun/Oracle vs IBM J2SE. Writing a small summary of our findings incase this may help someone in the future.

We are working on GlassFish Server Open Source Edition 3.1.1, a minor update release to the just released 3.1 version . One of the key features of 3.1.1 is improved Platform Support for AIX .

When debugging issues we ran into an error as shown below

javax.validation.ValidationException: Unable to find a default provider
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)

So we got the bean validation sources to see what was going wrong.

We noticed a difference with respect  to the bean validation   In Source code for Validation.java there is a line 317 which looks for the META-INF/services/javax.validation.spi.ValidationProvider


Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE )

The above line has no elements on IBM JDK but was returning proper values on Sun/Oracle JDK

Kinman and I were debugging this with respect to IBM vs Sun/Oracle classloader and to give you some info this is what IBM J2SE ClassLoader.getResources() does


ClassLoader up = this;
do {
       Enumeration e = up.findResources(resName);
       if (e != null && e.hasMoreElements()) resources.addElement(e);
       if (up == systemClassLoader) break;
       up = up.parent;
       if (up == null) up = systemClassLoader;
   } while (true);


So in IBM jdk the getResources goes up the classloader chain and looks for the findResources()

This is what is done in Sun/Oracle JDK

Enumeration[] tmp = new Enumeration[2];
   if (parent != null) {
       tmp[0] = parent.getResources(name);
   } else {
       tmp[0] = getBootstrapResources(name);
   }
   tmp[1] = findResources(name);


The problem was this class org.jvnet.hk2.osgiadapter.OSGIModuleImpl whose Classloader has a getResources but not findResources overriden. 

This worked  for the non IBM JDK case.

The fix was to add a findResources implementation in our classloader which Sahoo fixed by adding  a findResources implementation in core/kernel/src/main/java/com/sun/enterprise/v3/server/APIClassLoaderServiceImpl.java

Also this means in future every classloader should have findResources implementation to work with  IBM JDK.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

user12615559

Search

Top Tags
Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today