Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @CheckForNull
- public Object canReturnNull(){
- return null;
- }
- public Object canAlsoReturnNull(){
- return null;
- }
- public void testMethod(){
- if(canReturnNull()!=null){
- Class cls = canReturnNull().getClass(); //Sonar complains about possible NP
- }
- if(canAlsoReturnNull()!=null){
- Class cls = canAlsoReturnNull().getClass(); //Sonar does not complain about possible NP
- }
- }
- public void testMethod2(){
- Object o = canReturnNull();
- if(o !=null){
- Class cls = o.getClass(); //Sonar does not complain anymore
- }
- if(canAlsoReturnNull()!=null){
- Class cls = canAlsoReturnNull().getClass(); //Sonar does not complain about possible NP
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement