diff --git a/java-checks-test-sources/default/src/main/java/checks/HardcodedURICheckSample.java b/java-checks-test-sources/default/src/main/java/checks/HardcodedURICheckSample.java index 8ecbcc7419..68c792ff75 100644 --- a/java-checks-test-sources/default/src/main/java/checks/HardcodedURICheckSample.java +++ b/java-checks-test-sources/default/src/main/java/checks/HardcodedURICheckSample.java @@ -35,6 +35,7 @@ void foo(String s, String var) throws URISyntaxException { new File("", s); // Compliant new File("", s + "/" + s); // Noncompliant {{Remove this hard-coded path-delimiter.}} // ^^^ + String path1 = "a" + "/" + "b"; // Noncompliant {{Remove this hard-coded path-delimiter.}} new URI("http:https"); // Compliant new URI("http://www.mywebsite.com"); // Noncompliant {{Refactor your code to get this URI from a customizable parameter.}} diff --git a/java-checks/src/main/java/org/sonar/java/checks/HardcodedURICheck.java b/java-checks/src/main/java/org/sonar/java/checks/HardcodedURICheck.java index 63f18525b9..14d3f2faf3 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/HardcodedURICheck.java +++ b/java-checks/src/main/java/org/sonar/java/checks/HardcodedURICheck.java @@ -179,6 +179,8 @@ private void checkVariable(VariableTree tree) { String stringLiteral = stringLiteral(initializer); if (stringLiteral == null) { + // The check below applies only to binary expressions, so we apply it only if the initializer is not a literal. + reportStringConcatenationWithPathDelimiter(initializer); return; }