classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Re: RFC: Patch for duplicate entries in serialPersistentFie


From: Stuart Ballard
Subject: [cp-patches] Re: RFC: Patch for duplicate entries in serialPersistentFields
Date: Sun, 11 Dec 2005 18:39:12 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

> >>>Why not do similar and throw the InvalidClassException from
> >>>ObjectStreamClass.lookup()?
> >>>(But then document that clearly in our version of course.)
> >>
> >>Because we would not have the same API. ObjectStreamClass.lookup may not 
> >>throw any exception (except the default ones like Error, NPE, ...).
> > 
> > 
> > O man, it is a checked exception... How ugly.
> > I see why you don't want to do that.

This is an ugly suggestion, but it may provide a way to achieve compatibility
with this particular broken part of the spec.

Jeroen pointed out to me a while back that you can use generics to throw an
unchecked exception:

private class Evil<T extends Throwable> {
  private static void evilThrow(Throwable t) throws T {
    throw (T) e; // Unchecked cast, will always succeed!
  }
}
...

Evil<RuntimeException>.evilThrow(new InvalidClassException());

This works because Evil<RuntimeException>.evilThrow only declares that it will
throw RuntimeException but the cast from InvalidClassException to
RuntimeException is an unchecked one which disappears at runtime. So this code
really will throw an InvalidClassException from a method that doesn't declare
itself as throwing one.

Evil! But maybe the way to go in this case?

Stuart.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]