Please see the following test URLs which duplicate the problem:
Does not work:
http://localhost:8080/geoserver/kml/wms?layers=topp:states,topp:states
Partial stack trace:
org.vfny.geoserver.wms.WmsException: No such style: populationpopulation
at org.geoserver.wms.kvp.GetMapKvpRequestReader.parseStyles(GetMapKvpRequestReader.java:1177)
at org.geoserver.wms.kvp.GetMapKvpRequestReader.read(GetMapKvpRequestReader.java:258)
at org.geoserver.ows.Dispatcher.parseRequestKVP(Dispatcher.java:1016)
at org.geoserver.ows.Dispatcher.dispatch(Dispatcher.java:385)
at org.geoserver.ows.Dispatcher.handleRequestInternal(Dispatcher.java:185)
Once this problem is fixed by putting a simple break after line 227 in org.geoserver.wms.util.WMSRequests.java, the filter problem comes into play. I originally fixed this locally and before I could file a bug I ran into the filter problem
The same URL above with the addition of two filters (already URL-escaped for the greater than sign):
http://localhost:8080/geoserver/kml/wms?layers=topp:states,topp:states&CQL_FILTER=LAND_KM%3E400000;LAND_KM%3DLAND_KM
This filter should result in two different layers, the first showing calif and tex and the second showing all states. The two network links created can be individually inspected and will show that both layers were written with the first filter in the list.
The solution involved adding a layer index to the WMSRequest helper methods. This involved some amount of refactoring and some places in the call hierarchy I was unable to determine a layer index to send through. In those cases, I defaulted a 0 which may not be completely correct. I added some code to minimize the chances that this fix causes side effects which, in essence, uses the old logic if the request does not contain multiple layers with the same name. This should be refactored out eventually since it kind of complicates the code.
If you could supply a patch against 1.7.x that would be great. 1.6.x is really close to end of life, but we are releasing 1.6.5 next week, so we can hopefully squeeze this fix in. Let's see if Andrea or Justin have anything to say about doing it a better way. But if they agree and you can get a patch and a unit test exposing the problem in by the end of this week we will do all we can to include the fix.