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?
In Java, we can exclude Sonar checks using the built-in @SuppressWarnings annotation. This works exactly the same way as suppressing compiler warnings. All we have to do is specify the rule identifier, in this case java:S106.
The SonarQube Quality Model divides rules into four categories: Bugs, Vulnerabilities, Security Hotspots and Code Smells.
SonarQube Community Edition is free. All other SonarQube editions are commercial and require a paid license. SonarCloud is entirely free for all open source projects.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With