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. }
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.
No comments:
Post a Comment