Question

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?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top