[logback-dev] [Bug 127] New: LoggerComparator sorts incorrectly

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Fri Feb 15 00:24:55 CET 2008


http://bugzilla.qos.ch/show_bug.cgi?id=127

           Summary: LoggerComparator sorts incorrectly
           Product: logback-classic
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Other
        AssignedTo: logback-dev at qos.ch
        ReportedBy: mark_z at charter.net


ch.qos.logback.classic.spi.LoggerComparator doesn't work as intended, because
it is violating the symmetric property and contract of
java.util.Comparator.compare(T, T).

While Logger l1 is checked against LoggerContext.ROOT_NAME, Logger l2 also
needs to be checked.

Current implementation:

  public int compare(Logger l1, Logger l2) {
    if (l1.getName().equals(LoggerContext.ROOT_NAME)) {
      return -1;
    }
    return l1.getName().compareTo(l2.getName());
  }

Corrected implementation:

  public int compare(Logger l1, Logger l2) {
    if(l1.getName().equals(LoggerContext.ROOT_NAME)){
      return -1;
    }
    if(l2.getName().equals(LoggerContext.ROOT_NAME)){
      return 1;
    }
    return l1.getName().compareTo(l2.getName());
  }


-- 
Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the logback-dev mailing list