-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-5058 S1144: FP when encountering nested class's private met…
…hod without semantics
- Loading branch information
Showing
2 changed files
with
93 additions
and
35 deletions.
There are no files selected for viewing
35 changes: 34 additions & 1 deletion
35
...t/src/main/files/non-compiling/checks/unused/UnusedPrivateMethodWithUknownResolution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
package checks.unused; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.client.ClientHttpRequestInterceptor; | ||
|
||
public class UnusedPrivateMethodWithUknownResolution { | ||
|
||
private void init(@Observes Object object) {} // Compliant | ||
private void init2(@UnknownAnnotation Object object) {} // Noncompliant | ||
|
||
|
||
void sonarJava5012Minimal() { | ||
Z b = () -> bar(); | ||
} | ||
|
||
class Bar { | ||
private static void bar() { | ||
} | ||
} | ||
|
||
List<ClientHttpRequestInterceptor> sonarJava5012AsReported() { | ||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(); | ||
|
||
User userToAuthenticate = new User(); | ||
|
||
interceptors.add((request, body, execution) -> { | ||
request.getHeaders().set(HttpHeaders.AUTHORIZATION, "Bearer " + userToAuthenticate.token()); | ||
return execution.execute(request, body); | ||
}); | ||
|
||
return interceptors; | ||
} | ||
|
||
class User { | ||
public User() {} | ||
private String token() { // Compliant | ||
return "123456"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters