Fixes for GRAILS-10977

This is a fix for http://jira.grails.org/browse/GRAILS-10977 including testcase