Backport of https://github.com/hazelcast/hazelcast/pull/1386