CodePro Analytix - I don't get the Audit rule "Variable Has Null Value"

285 Views Asked by At

I'm testing CodePro Anlaytix (Eclipse plug-in) to check for code style in a project. CPA tells me that "Variable has null value" for the variable "titleParam" and "descParam" in the setters.

Here's the class:

/**
 * fdas fsda fsda fsa
 * @version 1.0
 */
public class CodeProItem {

    /**
     * Field title.
     */
    private String title;

    /**
     * Field desc.
     */
    private String desc;

    /**
     * Method getTitle.
     * @return String
     */
    public String getTitle() {
        return title;
    }

    /**
     * Method setTitle.
     * @param titleParam String
     */
    public void setTitle(String titleParam) {        
        this.title = titleParam;
    }

    /**
     * Method getDesc.
     * @return String
     */
    public String getDesc() {
        return desc;
    }

    /**
     * Method setDesc.
     * @param descParam String
     */
    public void setDesc(String descParam) {
        this.desc = descParam;
    }

}

Here's the summary of the rule (from CPA doc):

A variable that is guaranteed to have a null value and is used in an expression may indicate that the programmer forgot to initialize variable with its actual value.

The rule "Variable has null value" is activated and this is an example of code that would be caught by this rule (from CPA doc):

public boolean myMethod(String param)
{
    String tmp = null;
    if (tmp.equals(param)) {
        return true;
    } else {
        return false;
}   
}

I get the example, but why does it say that my parameters in the setters are null?

1

There are 1 best solutions below

1
On BEST ANSWER

It seems like a bug for me. If it would say it might be null and should be checked, that is possible. But unless it is called with a known null value somewhere else (that is possible and often possible to find out statically), the error makes no sense. However, if the caller provides the issue, then simply the error marker is misplaced.

Generally, I use FindBugs - that is optimized not to give false warnings, but works quite nice in my experience.