Skip to content

Commit 76c87a6

Browse files
SONARJAVA-5149 report issues with path delimiters in variable declaration (#4962)
1 parent 5f85f13 commit 76c87a6

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

java-checks-test-sources/default/src/main/java/checks/HardcodedURICheckSample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void foo(String s, String var) throws URISyntaxException {
3535
new File("", s); // Compliant
3636
new File("", s + "/" + s); // Noncompliant {{Remove this hard-coded path-delimiter.}}
3737
// ^^^
38+
String path1 = "a" + "/" + "b"; // Noncompliant {{Remove this hard-coded path-delimiter.}}
3839

3940
new URI("http:https"); // Compliant
4041
new URI("http://www.mywebsite.com"); // Noncompliant {{Refactor your code to get this URI from a customizable parameter.}}

java-checks/src/main/java/org/sonar/java/checks/HardcodedURICheck.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ private void checkVariable(VariableTree tree) {
179179

180180
String stringLiteral = stringLiteral(initializer);
181181
if (stringLiteral == null) {
182+
// The check below applies only to binary expressions, so we apply it only if the initializer is not a literal.
183+
reportStringConcatenationWithPathDelimiter(initializer);
182184
return;
183185
}
184186

0 commit comments

Comments
 (0)