0
votes

I've been testing both the rules "Correctness - Possible null pointer dereference" and "Correctness - Possible null pointer dereference in method on exception path" on my sonar instance. Unfortunately, the following code is never detected as wrong

 public ResultatsDTO getContent(String userName, String roid) {
    ResultatsDTO resultats = null;
    try {

        resultats = GetDocContentCaller.instance().getDocumentContent(
                userName, roid);

    } catch (Exception e) {
        LOGGER.error(
                "Erreur dans l'appel de l'ejb lors du telechargement du document docBaseId"
                        + roid, e);
        if (resultats.getErrorCode() == 0) {
            resultats.setErrorCode(ERROR_CODE_104);
            resultats.setMessage("erreur lors de l appel du web service");
        }
    }
    return resultats;
}

Netbeans detects correctly this issue but sonar 3.6.1 doesn't.

Is it normal ? Is it the good rule ?

Thanks for your help

1
This code isn't even valid to compile - test isn't definitely assigned. - Jon Skeet
@JonSkeet Why it shouldn't compile? What has definite assignment to do with it? May be I'm missing something? - Rohit Jain
My code was wrong. I updated that. - Alexandre T
The previous one with empty try block compiled fine for me... Is there something I'm missing? - Thihara
@Thihara. It would compile with empty try-block. But not, when you assign something to test in the try block. But now the code is completely changed. - Rohit Jain

1 Answers

0
votes

Sonar is a code review tool not a compiling tool.This is a compiling error it will detect by compiler.