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 ca0492717f..ae80de28af 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 @@ -85,4 +85,9 @@ void annotated(){} @MyAnnotation2() String endpoint_url_path = "/a-great/path/for-this-example"; // Compliant, an annotation is applied on the variable + void reachFullCoverage(){ + int path = 0; + path = 10; + } + } 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 2f336e08fb..04f2a2ff51 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 @@ -209,7 +209,8 @@ private static boolean isHardcodedURI(ExpressionTree expr) { @Nullable private static String stringLiteral(ExpressionTree expr) { ExpressionTree unquoted = ExpressionUtils.skipParentheses(expr); - if (unquoted instanceof LiteralTree literalTree) { + + if (unquoted instanceof LiteralTree literalTree && literalTree.is(Tree.Kind.STRING_LITERAL)) { return LiteralUtils.trimQuotes(literalTree.value()); } return null;