FP on squid:S1481 when using nested Streams

Description:
Unused variable warning when using variable within nested streams.

Sonar Version:

  • SonarLint IntelliJ 4.0.0.2916, Java 8

Minimum code example:

public void example() {
        final MutableInt count = new MutableInt(1);
        Stream.empty().forEach(item -> {
            Stream.of(item)
                .forEach(batch -> {
                    log.debug("Processing batch: {}", count.getAndIncrement());
                });
        });
    }

Hi,

This is a tricky one as it is a subtle variation (on another rule) of this one : https://jira.sonarsource.com/browse/SONARJAVA-2084

There is not a lot to be done on your side besides mark the issue as false positive.

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