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

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