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)


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

Hello @ruslanbes and @rbuer,

Indeed, this is an unexpected result, I created a ticket to track this issue.

Thank you for the feedback and the reproducers.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.