TomohitoNakayama wrote:

> Hello.
> Daniel and David.
> 
> Thank you.
> Two of your comments recalled me use of SanityManager.
> 
> The modifications shown in next are relating part of the new patch.
> 
> First part:
> +        if(SanityManager.DEBUG){
> +        SanityManager.ASSERT( blob != null ||
> +                      clob != null,
> +                      "Either blob or clob must be non-null.");
> +        }
> +
> +        if(blob != null){
> +        is = blob.getBinaryStream();
> +       +        }else if(clob != null){
> +        is = new ReEncodedInputStream(clob.getCharacterStream(),
> +                          NetworkServerControlImpl.DEFAULT_ENCODING);
> 
<snip>

> Using SanityManager, overhead of tests can be removed.

Those look ok, sometimes I get concerned about overuse of
SanityManager/debug code that can obscure the actual code.
With checking for null in sanity blocks, sometimes I see it as not worth
it, e.g.

  String s = somemethod();
  if (SanityManager.DEBUG)
  {
     if (s == null)
         SanityManager.THROWASSERT(" OH NO s is null");
  }
  return s.length();

My contention for code like this that the sanity check is not work it
and dominates the real code, focuses the eye on the check rather than
the actual code. Since s.length() will throw a NPE if s is null, the
check is already built into the Java language.

This, in my opinion, is much cleaner.

    return somemethod().length();


and during development time, any NPE can be resolved through the
information in the stack trace or use of a debugger.

Similar for other checks, like sanity instanceof

  Object o = somemethod();
  if (SanityManager.DEBUG)
  {
     if (o != null && !(o instanceof org.apache.derby.some.clazz))
         SanityManager.THROWASSERT(" OH NO o is not a
org.apache.derby.some.clazz it is a " + o.getClass());
  }
  return (org.apache.derby.some.clazz) o;

much cleaner:

   return (org.apache.derby.some.clazz) somemethod();

Dan.





Reply via email to