Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Spec# looks very interesting!</p> <p>When something like that isn't available, I generally test non-private methods with a run-time null-check, and assertions for internal methods. Rather than code the null check explicitly in each method, I delegate that to a utilities class with a check null method:</p> <pre><code>/** * Checks to see if an object is null, and if so * generates an IllegalArgumentException with a fitting message. * * @param o The object to check against null. * @param name The name of the object, used to format the exception message * * @throws IllegalArgumentException if o is null. */ public static void checkNull(Object o, String name) throws IllegalArgumentException { if (null == o) throw new IllegalArgumentException(name + " must not be null"); } public static void checkNull(Object o) throws IllegalArgumentException { checkNull(o, "object"); } // untested: public static void checkNull(Object... os) throws IllegalArgumentException { for(Object o in os) checkNull(o); } </code></pre> <p>Then checking turns into:</p> <pre><code>public void someFun(String val1, String val2) throws IllegalArgumentException { ExceptionUtilities.checkNull(val1, "val1"); ExceptionUtilities.checkNull(val2, "val2"); /** alternatively: ExceptionUtilities.checkNull(val1, val2); **/ /** ... **/ } </code></pre> <p><em>That</em> can be added with editor macros, or a code-processing script. <strong>Edit:</strong> The verbose check could be added this way as well, but I think it's significantly easier to automate the addition of a single line.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload