hazelcast/hazelcast — pull request #2748 by mattunderscorechampion (2014-06-17 20:18:11+00:00)
Title: Fix service loader returned implementation may not be castable

I found an issue with the service loader implementation. The service loader is not guaranteed to return a service implementation that is compatible with the requested service interface.

At work I was getting a ClassCastException during the tests. In our tests we use a classloader to provide isolation. This classloader does not delegate everything to the parent, I added a test case to cover this.

I added a check that the object returned by the service loader can be cast to the requested class. I removed the use of the method findHighestReachableClassLoader which was causing the wrong classloader to be used.

The findHighestReachableClassLoader method was introduced in [#2279](https://github.com/hazelcast/hazelcast/pull/2279), not clear what case it was trying to solve.