2

I create the Hibernate metamodel classes as the article. http://www.thoughts-on-java.org/static-metamodel/

Sonar give me this critical issue that I want to fix: Issue screenshot

Sonar suggestion is

Noncompliant Code Example

public class Greeter { public static Foo foo = new Foo(); ... }

Compliant Solution

public class Greeter { public static final Foo FOO = new Foo();
... }

But SingularAttribute is interface.

Can anyone give me some suggestion?

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
Adun
  • 21
  • 2

1 Answers1

1

In your case I'd ignore that SonarQube Warning, as there's good reason why the field is defined as volatile (see Q&A here). Also the JPA Spec defines the need for the 'volatile' Keyword.

Also, since these classes are generated you can't really change them anyways.

You could add a @SuppressWarning("squid:S2386") to the classes, but again that won't work because the classes are generated (repeatably in your build as i assume).

So you could either mark all those Issues as false positive in Sonar or ignore those (generated) classes altogether by setting sonar.exclusions to something like "*_.java"

Community
  • 1
  • 1
tom
  • 1,455
  • 1
  • 8
  • 13