SEC-2656: fix and unit test

this is my fix and unit test for https://jira.spring.io/browse/SEC-2656