<div dir="ltr"><br><div class="gmail_extra">On Wed, May 29, 2013 at 5:16 AM, Rod Widdowson <span dir="ltr"><<a href="mailto:rdw@steadingsoftware.com" target="_blank">rdw@steadingsoftware.com</a>></span> wrote:<br><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">More status.<br>
<br>
The upshot of the discussion on Friday was that we actually do need to<br>
tristate in these situations (yes/no/failure), either explicitly or via<br>
throwing an exception.<br>
<br></blockquote><div><br></div><div style>I agree with Scott that the yes/no/throw implementation is undesirable and confusing.</div><div style>My inclination with these sorts of interfaces is determine whether the throw scenario is really *exceptional*.</div>
<div style>I try to avoid throwing exceptions as part of the normal execution of any routine.</div><div style>You're better off if exceptions represent things that shouldn't happen regularly.</div><div style><br>
</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This means that our use of Predicate (from Guava) becomes problematic since<br>
they do not understand tristate and making them throw a (checked) Exception<br>
would change the signature so they wouldn't be Predicate any more.<br>
<br>
Tom and I discussed this yesterday. There are 3 ways to do this all of<br>
which have down sides. I have no particular favourite from any of them<br>
<br>
1) Keep the current code but arrange for the Predicates to throw an<br>
unchecked Exception. Then in the upper layers we can either convert this to<br>
a FilteringException or "do the right thing" - which is to say log the<br>
error, deny *all* attribute release (we have to do this since we cannot know<br>
the scope of the operation). This worries me somewhat (but then so do all<br>
the options)<br>
<a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html" target="_blank">http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html</a> .<br>
<br>
Since it causes least entropy at this stage and allows us to move forward<br>
it's Tom's preferred ("least unfavorite") option.<br>
<br>
2) Invent our own TristatedPredicate class (with a static method to generate<br>
one from a Guava Predicate)<br>
<br>
3) Invent our own PredicateThatThrows class (with a similar static method).<br>
Unfortunately due to the oddness of java's type mechanism it cannot be a<br>
<br>
class ThrowablePredicate<I, T extends Exception> {<br>
abstract boolean Apply(I in) throws T;<br>
}<br>
<br></blockquote><div><br></div><div style>It's not clear to me if the failure scenario always represents something exceptional, but given these three options, I think I'd go with #2 or #3.</div><div style>I'd avoid intentionally implementing a try-catch-rethrow, but I can't speak to the scope here.</div>
<div style>Just my 2 cents. (or perhaps 1.5)</div><div style><br></div><div style>--Daniel Fisher</div><div style><br></div></div></div></div>