commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stian Soiland-Reyes (JIRA)" <>
Subject [jira] [Commented] (IO-513) Add convenience methods for reading class path resources
Date Wed, 14 Sep 2016 16:38:20 GMT


Stian Soiland-Reyes commented on IO-513:

I agree with Gary that there should be variants with the ClassLoader as an additional parameter,
(or even required parameter), use of these functions will, unlike getResourceAsStream(), lead
to errors in environments with multiple classloaders (e.g. OSGi, or perhaps even within Tomcat),

IOUtils.class.getResource(name) will use the classloader of IOUtils, which might not have
access to the classloader that holds the resource you want. It's all fine if you run on a
single classpath (e.g. java -classpath loads:of:tsuff). 

And so a library using IOUtils.resourceTo* methods without providing the ClassLoader might
break by anyone trying to use it in such "enterprise" environments. 

Perhaps using the (a bit slow) Reflection.getCallerClass() is a better default if no ClassLoader
is provided and the resource can't be found? Or what do folks think - is that too much magic?

Better javadoc might help (if devs read it) - but for sure the variant providing the ClassLoader.

> Add convenience methods for reading class path resources
> --------------------------------------------------------
>                 Key: IO-513
>                 URL:
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Behrang Saeedzadeh
>            Priority: Minor
>              Labels: beginner, features, github-import, newbie
> Add convenience methods to {{IOUtils}} for reading class path resources and returning
them as {{String}}, {{byte[]}}, and {{URL}} respectively.
> Github PR:

This message was sent by Atlassian JIRA

View raw message