> >>>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.



_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to