Patch: merge File.toURI() from Classpath
Bryce McKinlay
mckinlay@redhat.com
Tue Jul 6 15:41:00 GMT 2004
Ranjit Mathew wrote:
>Mohan Embar wrote:
>
>
>>Just out of curiosity, why is the result of new InternalError()
>>being explicitly cast to an InternalError?
>>
>>
>
>Look closely - it's the return value (a Throwable) from
>initCause() that is being cast into an InternalError:
>
>+ // Can't happen.
>+ throw (InternalError) new InternalError("Unconvertible file: "
>+ + this).initCause(use);
>
>
I wonder if we should standardize on using RuntimeException in these
cases. A quick grep through the source code shows that we use both
InternalError and RuntimeException for these "shouldn't/can't happen"
catch blocks in various cases. I think RuntimeException would be a
better choice, since it has a proper "cause" constructor for re-throwing
exceptions.
Its also probably not worth bothering with string constants in the
"can't happen" cases. This case could be rewritten as:
--- File.java 6 Jul 2004 02:52:54 -0000 1.39
+++ File.java 6 Jul 2004 15:38:12 -0000
@@ -893,8 +893,7 @@
catch (URISyntaxException use)
{
// Can't happen.
- throw (InternalError) new InternalError("Unconvertible file: "
- + this).initCause(use);
+ throw new RuntimeException(use);
}
}
Bryce
More information about the Java-patches
mailing list