Rule S1125 simplify expression results into an error


This is about the recent feature that allows for a quick fix on some of the warnings.

import java.util.Collection;

public class TestSonarS1125 {

    Collection<?> collection;
    boolean isNonEmpty() {
        return collection == null ? false : !collection.isEmpty();

When I click on “Simplify the expression”, here is what happens:

    boolean isNonEmpty() {
        return !collection == null && !collection.isEmpty();

What is expected to happen:

    boolean isNonEmpty() {
        return collection != null && !collection.isEmpty();
  • Operating system: Windows
  • SonarLint plugin version: 7.4
  • Is connected mode used: No

Thanks & regards,

Hey there.

Thanks for the report! We already have this bug tracked here ([SONARJAVA-4241] - Jira), and I’ll link this thread to that ticket for visibility.