Quick-Tip: never forget empty methods anymore

Friday, September 18, 2015 at 2:02 PM UTC

Today again I stumbled upon runtime null pointer exceptions - and I was almost going crazy because I was sure that it could not produce one. The reason was simple: I created a new method in an interface and implemented this also in the class that used it. In one class I forgot to put something inside the method and it returned null by default - this is how DDE fills empty methods.

To avoid this just modify a code template for empty methods like this:

Mark the entry "Code, Method Body", hit the edit button and place the following code in the dialog:

// ${todo} Auto-generated method stub
throw new UnsupportedOperationException("${enclosing_method}(...) is not yet implemented");

You will get a readable exception message containing the method name so you don't have to search from where it came.

Thanks to my colleague Stephan Koops for this cool tip Lächelnd







Leave a comment right here