Java 1.6 Tomcat 6.0.35 Ubuntu Linux 12.04 I thought about posting this to a Java list but I can't reproduce it 'standalone' so I thought I'd have a go here.
It's quite long and involved... I have a web application that lists items for sale by category I have a facade that publishes a method that contracts to return a list of categories ordered alphabetically The category 'Miscellaneous' is required to be appended to the end of the list. My facade calls out to a database server that returns a List<Category> in random order. I then call collections.sort on the list and return the result. I've been messing around with various things and I have come up against a very strange problem. One way of satisfying the contract is to write the Category class as follows I'm not suggesting this is in any way acceptable industrial strength code, I'm doing it to illustrate a point. public class Category implements Comparable<Category>{ private Integer categoryId = 0; private String category = ""; @Override public int compareTo(Category c) { if(category.equals("Miscellaneous")){ return 1; } else{ return category.compareTo(c.category); } } etc If I test this by running a client of the facade I get the expected results, the list is ordered as required with "Miscellaneous" on the end However, and here's the thing, When my app starts an initialisation servlet runs, calls the facade method and puts the resulting List on the application context. When I render the list via a custom tag the list has in some way been altered so that the String "Miscellaneous" is in it's 'natural' position not what I want at all. I have tried everything I can think of to reproduce this behaviour in a standalone Java program but the list is always returned as required. When I call the method from a servlet the list is always returned in it's natural order, I know collections.sort is being executed as the list is in alpha order, it's almost as if the comparator is being replaced in some way I have no servlet filters or any other code 'in the way' between the facade and the initialization servlet. Any ideas ? TIA Lyallex