javasonarqubeerrorprone

ErrorProne Varargs doesn't agree for overridden method VS SonarQube java:S923 Do not use varargs


What I am trying to achieve:

Write a code public final class MyService implements CommandLineRunner { which complies with both ErrorProne and SonarQube.

Here is the code snippet:

public final class MyService implements CommandLineRunner {

@Override
    public void run(final String... args) {
        doSomething();
    }

@Override
    public void run(final String[] args) {
        doSomething();
    }

What did I try:

If I use the public void run(final String[] args) {, SonarQube will flag java:S923 Functions should not be defined with a variable number of arguments, ErrorProne is happy.

If I use the public void run(final String... args) { ErrorProne will flag the Varargs doesn't agree for overridden method while SonarQube is happy.

Question:

Is there a way to make both of them happy with some smarter code?


Solution

  • Try to remove 'final' in final String... args. ErrorProne may be complaining about mismatching with run method from SpringBoot CLR where it has no 'final' keyword.