7

I have a J2EE project with the following characteristics:

CDI 1.0
Dynamic Web Module 3.0
Java 1.7 (it's being changed to 1.8)
JSF 2.0
JPA 2.0

I'm running SonarQube 5.6.6 rules against it and it felt into the rule

Classes from "com.sun." and "sun." packages should not be used
squid : S1191

Classes in com.sun.* and sun.* packages are considered implementation details, and are not part of the Java API. They can cause problems when moving to new versions of Java because there is no backwards compatibility guarantee. Such classes are almost always wrapped by Java API classes that should be used instead.

because I'm using classes com.sun.faces.application.ApplicationAssociate and com.sun.faces.application.ApplicationResourceBundle.

I've seached another threads about this and most of them say I should change the rule to exclude the specific package or class.

I think there is no point in simply circumvent the rule, so I would like to know if there are actualy java API (1.7 or 1.8) classes for these sun classes.

If not, I believe it's better to keep the alert until java API classes become available for these sun classes.

Any tip/advice on this?

Steve C
  • 18,876
  • 5
  • 34
  • 37
Cássio
  • 329
  • 3
  • 11
  • The classes you are using are from a specific implementation of JSF (JavaServer Faces). JSF is not part of the Java SE standard library so you will not find equivalents in the JDK 7 and 8 API and they are also not going to be added in the future. – Jesper May 09 '17 at 12:30

1 Answers1

19

That's a bug in SonarQube. It's overgeneralizing the sun.* package as mentioned in Why Developers Should Not Write Programs That Call 'sun' Packages to com.sun.* package. This is incorrect. Oracle didn't mean to say that in abovelinked article. SonarQube should really only penalize usage of sun.* package or whatever is internally used by an arbitrary JRE/JDK implementation. The com.sun.* package is not JRE/JDK API/impl related at all.

Either turn off the S1191 rule, or mark all hits on com.sun.* as false positive.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555