I was able to replicate this problem on geotools from version 12.2 (probably going further back) till the newest master.
The issue is the following.
I have a layer which basically has 2 sets of filters (a wms request). One comming from the CQL_FILTER (filtering the attributes A, B,C) and the other comming from the SLD (filtering the attributes D, E).
The one comming from the SLD has an unsupported part (strTrim on E) which forces the features to be post-filtered by GeoTools. This filtering happens in the ArcSDEDataStore:getFeatureReader:
// use the full filter in this case, no sure how it was unpacked
reader = new FilteringFeatureReader<SimpleFeatureType, SimpleFeature>(reader,
This is where the problem lies. We filter the features using the query filter (filtering attributes A, B, C, D, E), but the features have already been sub-typed (which happens in the ArcSDEQuery:getQuerySchema) to contain only the query and the unsupported filter properties (we only have the D and E atttributes) so filtering against the full filter fails for all the features. This only happens when we have the unsupported filter.
Now, the solution is to check if we have the unsupported filter and in such case include all the query (or is using the full filter properies enough?) and the full filter properties for the sub-typing. This way the post filtering will be done correctly.