diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1075.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1075.html index bfa52b4f018..3da4bd9d5bd 100644 --- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1075.html +++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1075.html @@ -10,11 +10,20 @@

Why is this an issue?

For all those reasons, a URI should never be hard coded. Instead, it should be replaced by a customizable parameter.

Further, even if the elements of a URI are obtained dynamically, portability can still be limited if the path delimiters are hard-coded.

This rule raises an issue when URIs or path delimiters are hard-coded.

+

Exceptions

+

This rule does not raise an issue when:

+

How to fix it

Code examples

Noncompliant code example

 public class Foo {
+  public static final String FRIENDS_ENDPOINT = "/user/friends"; // Compliant path is relative and has only two parts
+
   public Collection<User> listUsers() {
     File userList = new File("/home/mylogin/Dev/users.txt"); // Noncompliant
     Collection<User> users = parse(userList);
@@ -40,4 +49,19 @@ 

Compliant solution

} }
+

Exceptions examples:

+
+public class Foo {
+  public static final String FRIENDS_ENDPOINT = "/user/friends"; // Compliant path is relative and has only two parts
+
+  public static final String ACCOUNT = "/account/group/list.html"; // Compliant path is used in an annotation
+
+  @Value("${base.url}" + ACCOUNT)
+  private String groupUrl;
+
+  @MyAnnotation()
+  String path = "/default/url/for/site"; // Compliant path is annotated
+
+}
+
diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S115.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S115.html index 54b462e0446..5b992c1584a 100644 --- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S115.html +++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S115.html @@ -46,6 +46,19 @@

Compliant solution

OPTION_TWO; } +

Exceptions

+

The rule applies to fields of primitive types (for example, float), boxed primitives (Float), and Strings. We do not +apply it to other types, which can be mutated, or have methods with side effects.

+
+public static final Logger log = getLogger(MyClass.class);
+public static final List<Integer> myList = new ArrayList<>();
+
+// call with side-effects
+log.info("message")
+
+// mutating an object
+myList.add(28);
+

Resources

External coding guidelines