Backport of the fix for [GEOT-4744] on the 11.x branch

Please look at the following JIRA http://jira.codehaus.org/browse/GEOT-4744.