3
votes

In the following code I get a warning from the squid:RedundantThrowsDeclarationCheck rule on the Foo1Exception (behind the throws keyword): Remove the redundant '!unknownSymbol!' thrown exception declaration(s).

Foo.java:

public class Foo {

    public static boolean bar(final String test) throws Foo1Exception, Foo2Exception {

        if (test.startsWith("a"))  {
            throw new Foo1Exception();
        } else if (test.startsWith("b")) {
            throw new Foo2Exception();
        } else if (test.startsWith("c")) {
            return true;
        }

        return false;
    }

}

Both exceptions are decrlared in seperate files:

Foo1Exception.java:

class Foo1Exception extends Exception {}

Foo2Exception.java:

class Foo2Exception extends Exception {}

I think this is a false positive, isn't it? Also interesting: I don't get this message directly in SonarQube (web interface) only in the SonarLint plugin in IntelliJ IDEA. Any Ideas?

I'm using: IntelliJ IDEA 2016.2.2; SonarLint 2.3 (with working server binding); SonarQube 5.6; SonarQube Java Plugin 4.0; Java 8

1
Do you fetch rules from the same server (may be remote)? or just using default rule set?? - Supun Wijerathne
How is your project setup exactly ? this seems like the type of the exception is not resolved and that's why an issue is (wrongly) raised. Is the source code of that exception in the same module ? can you share details about that ? - benzonico
@SupunWijerathne, I have configured my remote server and clicked the "Update binding" button. And it's working. I'm using this since a few month without any problems and after changing rules on the server, clicking the "update" button I got the updated rules in SonarLint. Is that what you mean? - Josef Reichardt
@benzonico, I don't know what you exactly want to know, sry. I'm working on a large multi module maven project and for my test which is described above I just created three new java classes (each in a seperate file) inside of one module. If I declare the two exception classes inside the Foo class as inner classes it works correctly. Only if they are in seperate Files the false positive messages are shown. - Josef Reichardt
@CptS Have you fetched new rules using sonarqube plugin also? If two plugins are using different rule sets, obviously there can be mismatches between the issues they are generating. That's what I asked. :) In general SonarQube should report more issues -> All SonarLint issues + some others, since sonarlint runs independently on each file, while sonarqube is global. - Supun Wijerathne

1 Answers

2
votes