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
Post a Comment