Java project - duplicates

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

For Java, there’s indeed a threshold of 10 statements but you cannot change it according to the documentation.

Anyway, I don’t see how the 2 methods could be considered as duplicate. The first one contains:

return (Map<String, List<String>>) claims.get("filters");

and the second one:

return claims.get("language", String.class);

Well even if we only consider the first part before and the second part after those return statements, that should raise a flag.
At least to the human eye. And we’re not talking about generics here and ways to refactor code.
The question is if Sonar is intelligent enough to see that by maybe setting the threshold lower.
But I guess your answer suggests a ‘no’.

I confirm that you cannot configure SonarQube/SonarCloud to detect a duplication in that case.