java - Is there a Sonar, Findbugs, or PMD rule that detects this possible NPE that CodePro detects? -


let's have block of code this:

map<string, object> mappy =      (map<string, object>)pextraparameters.get(serviceclientconstants.extra_parameters);  if (pssresponsebean!=null) {     mappy.put(addressresearchcontext.csi_response_bean, (addressnotfoundresponsebean)pssresponsebean); // line may  throw null pointer } 

is there sonar, findbugs, or pmd rule flag "mappy" potentially null? apparently codepro flags this, , need provide similar, if possible.

the problem findbugs treats unannotated items if annotated @nullable causes ignore nullness checks against them. can create empty java.util package annotated custom @returnvaluesarecheckfornullbydefault annotation (modify @returnvaluesarenonnullbydefault), apply every method in every class in package.

@returnvaluesarecheckfornullbydefault package java.util;  import edu.umd.cs.findbugs.annotations.returnvaluesarecheckfornullbydefault; 

another option create map facade has uses @checkfornull annotation.

public class annotatedmap<k, e> implements map<k, e> {     private final map<k, e> wrapped;      @checkfornull     public e get(k key) {         return wrapped.get(key);     }     ... } 

update: see previous answer similar question complete details on implementing advice.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -