I have a Java project.
I’d like Sonar to detect duplicates for the following code:
private Map<String, List<String>> getFiltersMapFromToken() {
String token = getStoredToken().replace(prefix, "");
try {
Claims claims = Jwts.parser()
.setSigningKey(secret.getBytes())
.parseClaimsJws(token)
.getBody();
return (Map<String, List<String>>) claims.get("filters");
} catch (Exception ex) {
LOGGER.error(INTERNAL_ERROR, ex);
}
return null;
}
private String getLanguageFromToken() {
String token = getStoredToken().replace(prefix, "");
try {
Claims claims = Jwts.parser()
.setSigningKey(secret.getBytes())
.parseClaimsJws(token)
.getBody();
return claims.get("language", String.class);
} catch (Exception ex) {
LOGGER.error(INTERNAL_ERROR, ex);
}
return null;
}
As I understand there’s less than 10 statements here but it’s clearly a duplicate to my eye.
Is there a way to achieve this? Maybe with sonar.cpd.* which I didn’t find among the settings?
Thanks