String.contains(null)留神了
引言:
今天同事发现我封装的SQL分离,有个很2B的异常——“NullPointerException”。丢人丢大发了,留个爪印,以后用新方法得先留神说明书了~。=
正文:
直接上测试代码:
/** * Returns true if and only if this string contains the specified * sequence of char values. * * @param s the sequence to search for * @return true if this string contains <code>s</code>, false otherwise * @throws NullPointerException if <code>s</code> is <code>null</code> * @since 1.5 */ public boolean contains(CharSequence s) { return indexOf(s.toString()) > -1; }