[Bug 127] New: LoggerComparator sorts incorrectly

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@qos.ch ReportedBy: mark_z@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.

http://bugzilla.qos.ch/show_bug.cgi?id=127 ------- Comment #1 from matt.fowles@gmail.com 2008-02-15 01:51 ------- Don't you also need to handle the case where they are both ROOT_NAME? -- 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.

http://bugzilla.qos.ch/show_bug.cgi?id=127 ------- Comment #2 from mark_z@charter.net 2008-02-15 02:24 ------- Good point! public int compare(Logger l1, Logger l2) { if(l1.getName().equals(l2.getName())){ return 0; } 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.

http://bugzilla.qos.ch/show_bug.cgi?id=127 noreply.ceki@qos.ch changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #3 from noreply.ceki@qos.ch 2008-03-04 11:53 ------- Fixed in revision 1624. I added a test case as well. The LoggerComparator is only used via the JMX configurator. Are you using it by any chance? -- 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.

http://bugzilla.qos.ch/show_bug.cgi?id=127 ------- Comment #4 from mark_z@charter.net 2008-03-04 15:38 ------- Thanks for the fix. The JMX looks appealing, but I don't see how I can get it to work from our target environment, IBM WebSphere Application Server 6.1 - at least not with having to handle some additional security considerations, etc. I may look into it again, but for now, I was just working on a simple status/configuration JSP. I noticed this bug when I was listing the loggers out to the page. -- 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.

http://bugzilla.qos.ch/show_bug.cgi?id=127 ------- Comment #5 from noreply.ceki@qos.ch 2008-03-04 17:47 ------- Mark, thank you for your reply. -- 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.
participants (1)
-
bugzilla-daemon@pixie.qos.ch