Bug not detected RSPEC-2200

Hi Team,

The expected SonarQube bug appears not to be caught in the code below, even though it’s caught in a very similar code as seen in the screenshot. Any thoughts?

import java.util.Arrays;

class CompareToBugExample {

    static class CustomString implements Comparable<CustomString> {
        private final String value;

        public CustomString(String value) {
            this.value = value;
        }
        @Override
        public int compareTo(CustomString other) {
            return this.value.compareTo(other.value);
        }
    }
    public boolean showBug(CustomString a, CustomString b) {
        int result = a.compareTo(b);
        result = a.compareTo(b); 
        if (result == -1) { values
            return true;
        } else if (result == 1) { 
            return false;
        } else {
            return false;
        }
    }
    public static void main(String[] args) {
        CustomString cs1 = new CustomString("apple");
        CustomString cs2 = new CustomString("banana");
        CompareToBugExample example = new CompareToBugExample();
        boolean result = example.showBug(cs1, cs2);
        System.out.println("Comparison result: " + result);
    }
}

Sonarqube version 25.5
Lang: Java
SonarScanner version: 5.0.1.3006

Screenshot of code scan results

1 Like

Hello, thanks for the multiple reports.

I have created this ticket to group them up and keep track of them. We will investigate them as soon as we have the capacity for it!

Have a good day :slight_smile: