Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. @CheckForNull
  2. public Object canReturnNull(){
  3. return null;
  4. }
  5.  
  6. public Object canAlsoReturnNull(){
  7. return null;
  8. }
  9.  
  10. public void testMethod(){
  11. if(canReturnNull()!=null){
  12. Class cls = canReturnNull().getClass(); //Sonar complains about possible NP
  13. }
  14. if(canAlsoReturnNull()!=null){
  15. Class cls = canAlsoReturnNull().getClass(); //Sonar does not complain about possible NP
  16. }
  17. }
  18.  
  19. public void testMethod2(){
  20. Object o = canReturnNull();
  21. if(o !=null){
  22. Class cls = o.getClass(); //Sonar does not complain anymore
  23. }
  24. if(canAlsoReturnNull()!=null){
  25. Class cls = canAlsoReturnNull().getClass(); //Sonar does not complain about possible NP
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement