hazelcast / hazelcast-hibernate

A distributed second-level cache for Hibernate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hibernate.class.getPackage().getImplementationVersion() returning null in PhoneHomeInfo class

Guisi opened this issue · comments

I am using hazelcast-hibernate53:2.2.1, with HazelcastLocalCacheRegionFactory as the Hibernate cache region factory.

When running my application inside an embedded Tomcat (tomcat-embed-jasper:8.5.63), I'm getting this NullPointerException:

Caused by: java.lang.NullPointerException: null
	at java.base/java.net.URLEncoder.encode(URLEncoder.java:224)
	at java.base/java.net.URLEncoder.encode(URLEncoder.java:196)
	at com.hazelcast.hibernate.PhoneHomeInfo$QueryStringBuilder.tryEncode(PhoneHomeInfo.java:99)
	at com.hazelcast.hibernate.PhoneHomeInfo$QueryStringBuilder.addParam(PhoneHomeInfo.java:93)
	at com.hazelcast.hibernate.PhoneHomeInfo.buildQueryString(PhoneHomeInfo.java:76)
	at com.hazelcast.hibernate.PhoneHomeInfo.<init>(PhoneHomeInfo.java:50)
	at com.hazelcast.hibernate.HazelcastLocalCacheRegionFactory.<clinit>(HazelcastLocalCacheRegionFactory.java:31)

That happens because for some reason the hibernate implementation version in the classloader is null when building the PhoneHomeInfo query string:

private String buildQueryString(boolean isLocalRegion) {
        return new QueryStringBuilder()
                .addParam("version", version)
                .addParam("hibernate-version", Hibernate.class.getPackage().getImplementationVersion())
                .addParam("region-type", isLocalRegion ? "local" : "distributed")
                .build();
    }

Could this be changed to do something like read it from a system property or env variable when the value is null, or even use a default value?

Yes, it's a trivial classloading bug. We'll take care of that and release a bugfix