commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shant Stepanian (JIRA)" <>
Subject [jira] [Commented] (VFS-508) Change FileSystemException to inherit from a RuntimeException, and not IOException (patch attached)
Date Mon, 06 Jan 2014 02:58:50 GMT


Shant Stepanian commented on VFS-508:

I'd ask if these exceptions that are exposed in much of the current API (specifically in the
org.apache.commons.vfs2.VFS and org.apache.commons.vfs2.FileObject classes) truly warrant
throwing checked exceptions that programmers must be aware of. However we accomplish this
change, whether by changing the base class of FileSystemException or by changing the signatures
of the VFS and FileObject classes to not throw checked exceptions, does not matter to me

As an example why I don't think many of the calls in these 2 classes warrant checked exceptions,
see the first one from my earlier comment:
* File.listFiles() vs. FileObject.getChildren()

Certainly, something can go wrong if that is called, but I'd argue that in most cases, if
you cannot complete a simple "getChildren" call, that is probably not a "recoverable" error,
as mentioned in Gary's first comment (step 58), and so I should not have to catch an exception
for that. (much like we would not catch errors if, say, we run out of memory). Plus, the core
Java API does not feel these are worthy of throwing checked exceptions, so I'd ask why these
are checked exceptions in VFS

This is one example, but I can certainly come up with more if needed

> Change FileSystemException to inherit from a RuntimeException, and not IOException (patch
> ---------------------------------------------------------------------------------------------------
>                 Key: VFS-508
>                 URL:
>             Project: Commons VFS
>          Issue Type: Improvement
>            Reporter: Shant Stepanian
>         Attachments: changeFileSystemToRuntime.patch
> I'd like to see if we can FileSystemException to inherit from a RuntimeException, and
not IOException
> I searched the JIRA and didn't see any old tickets referring to this, so I'll bring it
up here
> _The reason_
> The reason would go back to the whole "Runtime vs. Checked" exception debate, and I do
prefer the RuntimeException argument that with those, you have the choice on whether to declare
the try/catch block upon usage, whereas Checked exceptions force that on you
> In particular, I bring this up because I feel it hurts the usability of the API to have
all operations as a checked exception. I recently looked to convert my code from using the
regular Java JDK file api to the VFS api, and I found that in a number of places, I now have
to add a try/catch block to handle a checked exception where I previously didn't have to (e.g.
File.listFiles() vs. FileObject.getChildren(), new File("myFile") vs. VFS.getManager().resolveFile("myFile"))
> Having one less impediment to migrate would make it easier to adopt for more people.
As a frame of reference, Hibernate did make a change like this to convert HibernateException
from checked to runtime, and it was fine for them
> _Patch and Impact of Change_
> I've attached a patch of the change - you can see it is very small, and the code still
compiles. I ran a test locally and it failed on some of the external-resource-related bits;
I can follow up on this, but would like to first get your approval on this ticket before proceeding
w/ any more work
> In terms of client changes - this would only impact clients that happened to explicitly
expect an IOException in their catch block, and not directly the FileSystemException. (this
affected one piece of code within VFS itself, but could affect clients).
> But I believe that this still would be a beneficial change, as it would make all clients'
code cleaner and make it easier to adopt

This message was sent by Atlassian JIRA

View raw message