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
[BACKPORT] JCache detection improvement #7899
[BACKPORT] JCache detection improvement #7899
Conversation
I think it should be extended to prevent 1.0.0-PFD from being used: http://stackoverflow.com/questions/36387190/error-in-jcache-implementation-with-hazelcast-completeconfiguration-class-not-fo/36387326#36387326 Maybe give it an error which states to use 1.0.0 final version! |
269ee94
to
057ca88
Compare
Amended to require JCache cache-api 1.0.0. In case class |
} | ||
for (String className : JCACHE_ADDITIONAL_REQUIRED_CLASSES) { | ||
if (!ClassLoaderUtil.isClassAvailable(classLoader, className)) { | ||
if (HINT_LOGGED.compareAndSet(false, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this logging logic? Because the logging check is global but availability check is classloader based.
I mean, assume that there are at least two different classloader and none of them knows jcache (can't detect jcache classes). In this case, this log message is displayed for only one of them, not for both of them.
Therefore, I think, logging should be responsibility of the caller of JCacheDetector
.
👍 minor comment |
057ca88
to
a3e0b64
Compare
Thanks Serkan, I have amended the code so that the caller can pass its own logger which will be used to log the warning in case JCache < 1.0.0 is located on the classpath. |
I have discussed with @vbekiaris and to me using explicit version number in the code base (
Therefore, I prefer simple My offer is public static boolean isJcacheAvailable(ClassLoader classLoader) {
return isJcacheAvailable(classLoader, null);
}
public static boolean isJcacheAvailable(ClassLoader classLoader, ILogger logger) {
if (!ClassLoaderUtil.isClassAvailable(classLoader, JCACHE_CACHING_CLASSNAME)) {
// no cache-api jar in the classpath
return false;
}
for (String className : JCACHE_ADDITIONAL_REQUIRED_CLASSES) {
if (!ClassLoaderUtil.isClassAvailable(classLoader, className)) {
if (logger != null) {
logger.warning("An outdated version of JCache API was located in the classpath, please use newer versions of "
+ "JCache API rather than 1.0.0-PFD or 0.x versions.");
}
return false;
}
}
return true;
} |
@serkan-ozal: what's the semantic of the Your example could be improved like this: JCacheVersion version = checkJCacheVersion(classloader, logger);
if (version.isAtLeastVersion(V1_0_0) {
[...]
} Is it still ugly? |
It is not ugly and we had discussed very similar ideas with @vbekiaris yesterday. But my point is that the callers of |
ok, fair enough. |
…oint of JCache detection. Also, we now test for additional classes that guarantee JCache 1.0.0 is on the classpath.
a3e0b64
to
8ca344d
Compare
Thank you all for your contributions, code was updated according to comments. |
👍 |
1 similar comment
👍 |
This issue is still there .I have javax.cache (1.0.0) as dependency in my project and using Hazelcast (3.11). -------Error message----
|
@Dineshseervi: can you shed some light into your setup? Are you using any application container/server? Is JCache loaded by a different classloader than Hazelcast? |
@jerrinot |
@Dineshseervi thanks for update! |
@Dineshseervi any updates on the issue? Can you compress your project and open a new issue with it so we follow up on this? |
This PR fixes #7854 by introducing a separate utility class com.hazelcast.cache.impl.JCacheDetector which handles JCache detection; specifically we make sure we locate a number of classes which are available since JCache 1.0.0-PFD but not in previous versions which caused NoClassDefFound exception as shown in #7810 (therefore when JCache 0.9 or 0.5 is in the classpath, Hazelcast will consider JCache is not available).