In my java code, is the key sonarlint question s1166 a false positive?

SonarLint 1.0. 0 for eclipse marks a key problem in my code, and I can't understand why and how to solve it Is this really false to me – or what did I miss?

import org.apache.log4j.Logger;

[...]

public final class Foo {

    private static final Logger logger = Logger.getLogger(Foo.class);

    [...]

    public static void foo() {

        MyCommand command = new MyCommand(foo,bar);
        try {
            commandService.executeCommand(command);
        } catch (CommandException e) {
            logger.error("My command execution Failed",e);
        }
    }

    [...]

The following is an excerpt that matches the sonarlint Rule Description:

In my opinion, my code conforms to the first variant of a given compatible solution, but sonarlint does not accept it

Not long ago, there was another discussion of sonar rule s1166, but it didn't really have the same problem as me

Editor: answer the following questions: I use log4j for logging I extended the code to reflect this

Solution

In fact, you are recording the message and stack trace of the original exception; This is a false discovery

It may be that the rules do not have the specific knowledge of log4j, but lack the full knowledge of all log bases. The fact that exceptions are passed as parameters is enough

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>