Skip to content

Commit

Permalink
SONARJAVA-5149 report issues with path delimiters in variable declara…
Browse files Browse the repository at this point in the history
…tion (#4962)
  • Loading branch information
erwan-serandour authored Dec 16, 2024
1 parent 5f85f13 commit 76c87a6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 76c87a6

Please sign in to comment.