LPS-40995

Hey Hugo,

Could you send this to Sergio? (related to: https://github.com/sergiogonzalez/liferay-portal/pull/1086) This is now an urgent issue for a client.

I didn't want to send straight to Sergio because I had to add a handful of commits.