tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: This is just plain ... odd.
Date Thu, 08 Nov 2012 22:37:18 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lyallex,

On 11/8/12 8:35 AM, Lyallex wrote:
> 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.

There's something to that "can't reproduce it standalone" that you
should be worried about.

> I have a facade that publishes a method that contracts to return a
> list of categories ordered alphabetically

All problems in computer science can be solved by another layer of
abstraction. Sure you can't fit a Proxy to a Service in there?

> 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.
> 
> [ ... ]
> 
> 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.

What does that "custom tag" do? A beer says it sorts something. Or,
maybe you have some silly client-side process that sorts the entries
after they are loaded into the browser.

> 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

Are you using Collections.sort() or are you using a sorted collection?
If you are calling Collections.sort() then the list is sorted once and
it can be mutated. If you have a sorted list, then the comparator
could conceivably be "replaced" (but really only by creating a new
Collection).

> I have no servlet filters or any other code 'in the way' between
> the facade and the initialization servlet.

Sounds like the problem is between the application scope and the page.
Custom tag? Secondary sort?

Simple test that doesn't require you to read any of your own code:

Wrap the sorted collection in the application scope with
Collections.unmodifiableList(sortedList). Now you'll get an exception
with a stack trace whenever any code tries to re-sort it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlCcNB4ACgkQ9CaO5/Lv0PDLuACgp/C8BkyI0cPOY5YoiwlJHnwe
td0AniTAY+GDt1h1cI45Czj9VMqLuu7U
=HvRr
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message