You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Irving Cordova <ir...@irvingc.com> on 2012/02/08 21:19:35 UTC
Felix throwing IOException instead of FileNotFoundException
Hi,
I am currently using a 3rd party component in a small project of mine. This
component tries to dynamically load resources from a given URL, it does
this by trying several extensions for a base name, and returns success when
it finds a resource that matches the base name and extension. For this
dynamic loading it depends on URL.openStream(). If openStream returns
FileNotFoundException it continues looking, but if openStream returns
IOException it assumes something is wrong with the resource, stops looking
and throws an exception. This works fine in a non OSGi environment, and
also inside equinox, however it does not work inside Felix. Felix throws a
IOException with the message: "Resource does not exist" instead of a
FileNotFoundException. Compare the stack traces:
Felix:
java.io.IOException: Resource does not exist:
bundle://93.0:1/resource/myresource.stg
at
org.apache.felix.framework.URLHandlersBundleURLConnection.<init>(URLHandlersBundleURLConnection.java:131)
at
org.apache.felix.framework.URLHandlersBundleStreamHandler.openConnection(URLHandlersBundleStreamHandler.java:64)
at java.net.URL.openConnection(URL.java:945)
at java.net.URL.openStream(URL.java:1010)
Equinox:
java.io.FileNotFoundException: /resource/myresource.stg
at
org.eclipse.osgi.framework.internal.protocol.bundleresource.Handler.findBundleEntry(Handler.java:51)
at
org.eclipse.osgi.framework.internal.core.BundleResourceHandler.openConnection(BundleResourceHandler.java:175)
at java.net.URL.openConnection(URL.java:945)
at java.net.URL.openStream(URL.java:1010)
Shouldn't the appropriate exception be FileNotFoundException ?
Regards,
Irving Cordova
http://irvingc.com
Re: Felix throwing IOException instead of FileNotFoundException
Posted by Irving Cordova <ir...@irvingc.com>.
> I still suggest you open up a feature request issue for the framework so we can track it. Thanks.
Thanks Richard!
I have now opened the request:
https://issues.apache.org/jira/browse/FELIX-3342
Regards,
Irving Cordova
http://irvingc.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Felix throwing IOException instead of FileNotFoundException
Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 2/8/12 3:48 PM, Richard S. Hall wrote:
> On 2/8/12 15:19 , Irving Cordova wrote:
>> Hi,
>>
>> I am currently using a 3rd party component in a small project of
>> mine. This
>> component tries to dynamically load resources from a given URL, it does
>> this by trying several extensions for a base name, and returns
>> success when
>> it finds a resource that matches the base name and extension. For this
>> dynamic loading it depends on URL.openStream(). If openStream returns
>> FileNotFoundException it continues looking, but if openStream returns
>> IOException it assumes something is wrong with the resource, stops
>> looking
>> and throws an exception. This works fine in a non OSGi environment, and
>> also inside equinox, however it does not work inside Felix. Felix
>> throws a
>> IOException with the message: "Resource does not exist" instead of a
>> FileNotFoundException. Compare the stack traces:
>>
>> Felix:
>>
>> java.io.IOException: Resource does not exist:
>> bundle://93.0:1/resource/myresource.stg
>> at
>> org.apache.felix.framework.URLHandlersBundleURLConnection.<init>(URLHandlersBundleURLConnection.java:131)
>>
>> at
>> org.apache.felix.framework.URLHandlersBundleStreamHandler.openConnection(URLHandlersBundleStreamHandler.java:64)
>>
>> at java.net.URL.openConnection(URL.java:945)
>> at java.net.URL.openStream(URL.java:1010)
>>
>> Equinox:
>>
>> java.io.FileNotFoundException: /resource/myresource.stg
>> at
>> org.eclipse.osgi.framework.internal.protocol.bundleresource.Handler.findBundleEntry(Handler.java:51)
>>
>> at
>> org.eclipse.osgi.framework.internal.core.BundleResourceHandler.openConnection(BundleResourceHandler.java:175)
>>
>> at java.net.URL.openConnection(URL.java:945)
>> at java.net.URL.openStream(URL.java:1010)
>>
>> Shouldn't the appropriate exception be FileNotFoundException ?
>
> It doesn't necessarily seem like this is more appropriate. We are not
> talking about a file in the file system, we are talking about a
> resource in a JAR file. I see nothing in the API JavaDoc that
> indicates that openConnection() should through a
> FileNotFoundException, nor specifically should it through such an
> exception to indicate a less severe error type than IOException.
s/through/throw/g
Sorry about that.
>
> So, I guess the question is, do should we modify the framework to
> always throw FileNotFoundException when it cannot find the resource to
> participate in this non-standard protocol?
>
> It's not clear to me that it makes sense to me, but you could open a
> feature request in JIRA and assign it to the framework component for
> consideration.
I talked with Thomas Watson (Equinox lead) about this and he agreed that
IOException is completely reasonable. He said that Equinox throws FNFE
because that is what URLClassLoader used to do when Equinox used that as
its class loader, when they switched to a custom class loader a user
complained when they started throwing IOExceptions so they switched back
to FNFEs.
I still suggest you open up a feature request issue for the framework so
we can track it. Thanks.
-> richard
>
> Thanks.
>
> -> richard
>
>>
>> Regards,
>>
>> Irving Cordova
>> http://irvingc.com
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Felix throwing IOException instead of FileNotFoundException
Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 2/8/12 15:19 , Irving Cordova wrote:
> Hi,
>
> I am currently using a 3rd party component in a small project of mine. This
> component tries to dynamically load resources from a given URL, it does
> this by trying several extensions for a base name, and returns success when
> it finds a resource that matches the base name and extension. For this
> dynamic loading it depends on URL.openStream(). If openStream returns
> FileNotFoundException it continues looking, but if openStream returns
> IOException it assumes something is wrong with the resource, stops looking
> and throws an exception. This works fine in a non OSGi environment, and
> also inside equinox, however it does not work inside Felix. Felix throws a
> IOException with the message: "Resource does not exist" instead of a
> FileNotFoundException. Compare the stack traces:
>
> Felix:
>
> java.io.IOException: Resource does not exist:
> bundle://93.0:1/resource/myresource.stg
> at
> org.apache.felix.framework.URLHandlersBundleURLConnection.<init>(URLHandlersBundleURLConnection.java:131)
> at
> org.apache.felix.framework.URLHandlersBundleStreamHandler.openConnection(URLHandlersBundleStreamHandler.java:64)
> at java.net.URL.openConnection(URL.java:945)
> at java.net.URL.openStream(URL.java:1010)
>
> Equinox:
>
> java.io.FileNotFoundException: /resource/myresource.stg
> at
> org.eclipse.osgi.framework.internal.protocol.bundleresource.Handler.findBundleEntry(Handler.java:51)
> at
> org.eclipse.osgi.framework.internal.core.BundleResourceHandler.openConnection(BundleResourceHandler.java:175)
> at java.net.URL.openConnection(URL.java:945)
> at java.net.URL.openStream(URL.java:1010)
>
> Shouldn't the appropriate exception be FileNotFoundException ?
It doesn't necessarily seem like this is more appropriate. We are not
talking about a file in the file system, we are talking about a resource
in a JAR file. I see nothing in the API JavaDoc that indicates that
openConnection() should through a FileNotFoundException, nor
specifically should it through such an exception to indicate a less
severe error type than IOException.
So, I guess the question is, do should we modify the framework to always
throw FileNotFoundException when it cannot find the resource to
participate in this non-standard protocol?
It's not clear to me that it makes sense to me, but you could open a
feature request in JIRA and assign it to the framework component for
consideration.
Thanks.
-> richard
>
> Regards,
>
> Irving Cordova
> http://irvingc.com
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org