S1854: Remove this useless assignment to local variable "sourceEnvId" with lambdas

  • SonarJava 6.0
  • SonarQube 7.9.1 LTS
  • Sonar Maven Plugin:
final Long sourceEnvId = (Long) calculateSourceEnvId(); // S1854 is triggered

final Env sourceEnv = (Env) getEnvironments()
                .filter(env -> env.getId().equals(sourceEnvId)) 

The variable sourceEnvId is used inside lambda but despite that the S1854 is triggered (should happen only when the var was not used at all)

1 Like

In this Implementation of org.springframework.mail.javamail.MimeMessagePreparator

return mimeMessage -> {
  final MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
  final String replyToAddress = mailProperties.getReplyTo();
  if (!isBlank(replyToAddress)) {

S1481 says that messageHelper and replyToAddress are unused.
Nowadays this pops up in old code. Due to that we are in an lambda too, this may corralate to original topic