Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError: javax/cache/Cache when mocking HazelcastInstance with 3.7 #8352

Closed
kobalski opened this issue Jun 9, 2016 · 3 comments · Fixed by #8434
Closed

NoClassDefFoundError: javax/cache/Cache when mocking HazelcastInstance with 3.7 #8352

kobalski opened this issue Jun 9, 2016 · 3 comments · Fixed by #8434

Comments

@kobalski
Copy link

kobalski commented Jun 9, 2016

In our hibernate modules we do not have jcache dependencies in the classpath. When I upgrade hazelcast version to 3.7-SNAPSHOT, I got java.lang.NoClassDefFoundError: javax/cache/Cache error when mocking HazelcastInstance. Here is a simple reproducer from a hibernate test :

@RunWith(HazelcastSerialClassRunner.class)
@Category({QuickTest.class, ParallelTest.class})
public class HazelcastQueryResultsRegionTest {

    private HazelcastInstance instance;

    @Test
    public void testPut() {
        instance = mock(HazelcastInstance.class);
    }
}
@kobalski kobalski added this to the 3.7 milestone Jun 9, 2016
@serkan-ozal serkan-ozal self-assigned this Jun 9, 2016
@serkan-ozal
Copy link
Contributor

serkan-ozal commented Jun 10, 2016

Seems that since ICache is at the signature of HazelcastInstance, Mockito try to load javax.cache.Cache at some point while creating proxy instance.

I have not thought about it much yet but the easiest solution/workaround (should we for such cases?) might be changing the signature to Object getCache(String name) at the signature of HazelcastInstance but this will enforce users to explicitly cast to Cache on their code.

We can also change the signature as <C> C getCache(String name) so when the left-hand variable is javax.cache.Cache typed, there will be no explicit casting required but still this allows casting to any type which is not javax.cache.Cache.

I had also thought this at the beginning of the PRD:

interface CacheAwareHazelcastInstance extends HazelcastInstance {

    Cache getCache(String name);

}   

But it still complex and JCache users must cast (also check for JCache support) their instances to CacheAwareHazelcastInstance.

@shakuzen
Copy link

shakuzen commented Jun 11, 2016

I can also confirm this issue when using Hazelcast 3.7-EA with even the simplest Spring Boot application (create a project from http://start.spring.io/ with no dependencies selected, add Hazelcast dependency version 3.7-EA to your POM, add a @Bean method that instantiates a HazelcastInstance to the main class, startup the application, observe java.lang.NoClassDefFoundError: javax/cache/Cache error). Only solution for Spring Boot users I have found so far is to add the cache-api as a dependency or downgrade to 3.6.x.

@jerrinot
Copy link
Contributor

@shakuzen: many thanks for your report. We have to solve this before 3.7 RC is out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment