Saturday, July 25, 2009

Notational Conventions

Notational Conventions explained for many specifications:-
http://tools.ietf.org/html/rfc2119

Tuesday, July 7, 2009

Find Bugs

Find Bugs is an eclipse plugin which shows the common errors in Java. I use the eclipse plugin, and as a Best Practice for java developers this should be used while development. :)

e.g.
For a piece of code the following error was received

When piece of code in given below:-
1. Long id = request.getId();
2.
3. if(request == null || id == null) {
4. throw new RuntimeException("id cannot be null");
5. }
Find the error if you can... :)

The check for request == null is fruitless, since if request is null the line 1 will fail. Below is provided the corrected code and thus removes the bug.
1. if(request == null || request.getId() == null) {
2. throw new RuntimeException("id cannot be null");
3. }

Long id = request.getId();


A note of caution, the code inspection tools need to be used intelligently, it may sometimes flag code as bug that may have been done for some valid reason. Ignore them in this case.