Null check error message as "is null" or "was null"

Posted by Timo Westkämper on Stack Overflow See other posts from Stack Overflow or by Timo Westkämper
Published on 2010-06-11T11:31:57Z Indexed on 2010/06/11 12:12 UTC
Read the original article Hit count: 560

Filed under:

When doing null checks in Java code, and you throw IllegalArgumentExceptions for null values, what kind of message template do you use?

We tend to use something like this

public User getUser(String username){
   if (username == null){
     throw new IllegalArgumentException("username is null");   
   }
   // ...
}

What is better : "is null" or "was null", and why?

For me "is null" feels more natural.

© Stack Overflow or respective owner

Related posts about java