Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter for empty constructors that do not have arguments should be expanded #1575

Open
rebse opened this issue Feb 1, 2024 · 0 comments
Open

Comments

@rebse
Copy link

rebse commented Feb 1, 2024

If your utility class has no private constructor, Sonarqube will complain with
java:S1118 “Utility classes should not have public constructors”

which is right. The Sonarqube rule desciption has

class StringUtils { // Compliant

  private StringUtils() {
    throw new IllegalStateException("Utility class");
  }

  public static String concatenate(String s1, String s2) {
    return s1 + s2;
  }

}

It's best practice to throw an exception, as i learned.
But when i use the exception i'll get

4e7564f071b96160afdc2021cdca8907cdbf7f9b

You should expand the filter for also private constructors throwing an exception, as this is best practice.
Those filters where introduced with JaCoCo 0.8.0
https://github.com/jacoco/jacoco/wiki/FilteringOptions#filters-for-code-where-test-execution-is-questionable-or-impossible-by-design

Gilbert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant