Bug in UtilUrl.fromResource() ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in UtilUrl.fromResource() ?

Rene Scheibe
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Just a short question. When resolving the URL for a resource via
UtilUrl.fromResource(String resourceName, ClassLoader loader) why is it
implemented that the most specific match is the last one? See below?

if (url == null) url = loader.getResource(resourceName);
if (url == null) url = loader.getResource(resourceName + ".properties");

This results in a problem, when eg. calling
UtilProperties.getPropertyValue("catalog", "image.server.path").
Scenario: I have another jar in the classpath that contains a "catalog"
folder. I expect to get the property from catalog.properties but the
result is a "catalog" URL from my other jar, which does not include
anything useful and results in NullPointerExceptions in OFBiz.

Regards,
René
- --
René Scheibe * [hidden email]
TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterföhring
Geschäftsführer: Henrik Klagges, Gerhard Müller, Christoph Stock
Sitz: Unterföhring * Amtsgericht München * HRB 135082
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyI+yYACgkQUXs9EHvIuCqawwCeInqjKiFSv4mXAJMYbz/bMXY1
978AnjUS4sN334TCgAdoYoQvURz5smFN
=IB2w
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Bug in UtilUrl.fromResource() ?

Adam Heath-2
On 09/09/2010 10:20 AM, Rene Scheibe wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Just a short question. When resolving the URL for a resource via
> UtilUrl.fromResource(String resourceName, ClassLoader loader) why is it
> implemented that the most specific match is the last one? See below?
>
> if (url == null) url = loader.getResource(resourceName);
> if (url == null) url = loader.getResource(resourceName + ".properties");
>
> This results in a problem, when eg. calling
> UtilProperties.getPropertyValue("catalog", "image.server.path").
> Scenario: I have another jar in the classpath that contains a "catalog"
> folder. I expect to get the property from catalog.properties but the
> result is a "catalog" URL from my other jar, which does not include
> anything useful and results in NullPointerExceptions in OFBiz.

The bug here is not the ordering of those lines, but the calling code
requesting just 'catalog'.  The calling code should directly request
'catalog.properties'.

There was a similiar bug years(ages) ago, where calling code requested
'security', instead of 'security.properties'.  As you can imagine,
'security' is a rather general term, and it clashed with other locations.