[prev in list] [next in list] [prev in thread] [next in thread] 

List:       axis-user
Subject:    [axis 2] Issue with JarFileClassLoader.getResources() / findResources()
From:       Davide Silvestre <ds () cdrator ! com>
Date:       2014-11-13 10:20:39
Message-ID: D4EC96AC4947594DB8EA4A9CEEA957BA73FB515BFE () CDRSRVEX
[Download RAW message or body]

Hi,
I have an axis2 application (axis version 1.6.2 and Java7u51) that is internally \
using the ServiceLoader. The ServiceLoader needs to retrieve the implementation files \
as resouces from the META-INF/services folders inside any of the jars. As the \
ServiceLoader is scanning the ContextClassLoader to retrieve this kind of resources I \
have set the context class loader to be of type "service". In this way it will \
contain all the jars of the aar package. The classloader used is of type \
JarFileClassLoader and I think I have found a bug in the findResources(String name) \
method. This method will load the resources from the parent classloader and from the \
classloader itself in an order that can be changed by configuration.

When the resources are retrieved from the parent classloader then it is just \
invoking: parent.getResources(name);

When it tries to retrieve the resources from the urls of the classloader itself then \
it invokes: super.findResources(name);
and this will invoke the findResources(String name) implementation in the \
java.net.URLClassLoader class. This method is not scanning directly the urls of the \
classloader, but it delegates to an object of type URLClassPath that is initialized \
in the constructor. The problem is that in the JarFileClassLoader the constuctor \
methods do invoke the super contructor in the URLClassLoader that has to initialize \
the URLClassPath, but it does that using an emtpy url array and not the original \
array.

    public JarFileClassLoader(URL[] urls) {
        super(EMPTY_URLS);
        this.acc = AccessController.getContext();
        addURLs(urls);
    }

I also tried with different version of Java but because of this bug I am never able \
to successfully invoke getResources() or findResources() if I use a \
JarFileClassLoader.

Anybody has experieced the same? Is there a fix for this?

Thanks
Davide


[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:3.0cm 2.0cm 3.0cm 2.0cm;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=DA link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>Hi,<o:p></o:p></p>

<p class=MsoNormal>I have an axis2 application (axis version 1.6.2 and
Java7u51) that is internally using the ServiceLoader. The ServiceLoader needs
to retrieve the implementation files as resouces from the META-INF/services
folders inside any of the jars.<o:p></o:p></p>

<p class=MsoNormal>As the ServiceLoader is scanning the ContextClassLoader to
retrieve this kind of resources I have set the context class loader to be of
type &quot;service&quot;. In this way it will contain all the jars of the aar
package.<o:p></o:p></p>

<p class=MsoNormal>The classloader used is of type JarFileClassLoader and I
think I have found a bug in the findResources(String name) method.<o:p></o:p></p>

<p class=MsoNormal>This method will load the resources from the parent
classloader and from the classloader itself in an order that can be changed by
configuration.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>When the resources are retrieved from the parent classloader
then it is just invoking:<o:p></o:p></p>

<p class=MsoNormal>parent.getResources(name);<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>When it tries to retrieve the resources from the urls of the
classloader itself then it invokes:<o:p></o:p></p>

<p class=MsoNormal>super.findResources(name);<o:p></o:p></p>

<p class=MsoNormal>and this will invoke the findResources(String name) implementation
in the java.net.URLClassLoader class. This method is not scanning directly the
urls of the classloader, but it delegates to an object of type URLClassPath
that is initialized in the constructor.<o:p></o:p></p>

<p class=MsoNormal>The problem is that in the JarFileClassLoader the constuctor
methods do invoke the super contructor in the URLClassLoader that has to
initialize the URLClassPath, but it does that using an emtpy url array and not
the original array.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:Consolas;color:black'>&nbsp;&nbsp;&nbsp; </span><b><span
style='font-size:10.0pt;font-family:Consolas;color:#7F0055'>public</span></b><span
style='font-size:10.0pt;font-family:Consolas;color:black'>
JarFileClassLoader(URL[] </span><span style='font-size:10.0pt;font-family:Consolas;
color:#6A3E3E'>urls</span><span style='font-size:10.0pt;font-family:Consolas;
color:black'>) {</span><span \
style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:Consolas;color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span><b><span style='font-size:10.0pt;font-family:Consolas;color:#7F0055'>super</span></b><span
 style='font-size:10.0pt;font-family:Consolas;color:black'>(</span><b><i><span
style='font-size:10.0pt;font-family:Consolas;color:#0000C0'>EMPTY_URLS</span></i></b><span
 style='font-size:10.0pt;font-family:Consolas;color:black'>);</span><span
style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:Consolas;color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span><b><span style='font-size:10.0pt;font-family:Consolas;color:#7F0055'>this</span></b><span
 style='font-size:10.0pt;font-family:Consolas;color:black'>.</span><span
style='font-size:10.0pt;font-family:Consolas;color:#0000C0'>acc</span><span
style='font-size:10.0pt;font-family:Consolas;color:black'> = \
AccessController.<i>getContext</i>();</span><span \
style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:Consolas;color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
addURLs(</span><span \
style='font-size:10.0pt;font-family:Consolas;color:#6A3E3E'>urls</span><span \
style='font-size:10.0pt;font-family:Consolas;color:black'>);</span><span \
style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:Consolas;
color:black'>&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:Consolas;
color:black'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal>I also tried with different version of Java but because of
this bug I am never able to successfully invoke getResources() or
findResources() if I use a JarFileClassLoader.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Anybody has experieced the same? Is there a fix for \
this?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Thanks<o:p></o:p></p>

<p class=MsoNormal>Davide<o:p></o:p></p>

</div>

</body>

</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic