TL;DR - we changed all declarations of ConcurrentHashMap to Map.
The current project has a number of components. Some are to be deployed on a Java 7 runtime, others make use of newer capabilities on a Java 8 runtime. While trying to streamline the build process using Jenkins, this issue came up while I was switching over from Java 7 to 8. We'd normally assume that it'd suffice for Maven to build with the specific major version in mind using maven.compiler.source and maven.compiler.target configured either in the POM or over the command line. Despite these additions, the runtime would still complain of the following error somewhere in our codes:
java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
A bit of searching turned up this post that explained
Notably the Java 1.7 ConcurrentHashMap#keySet() returns aSet<K>
while the 1.8 ConcurrentHashMap#keySet() returns aConcurrentHashMap.KeySetView<K,V>
.
The OP then proceeded to suggested to simply edit the declaration of the ConcurrentHashMap to Map as a workaround.
Other solutions I found mentioned
- configuring the -bootclasspath of the Maven build path to point to the rt.jar of the older JDK;
- setting up a separate Jenkins/Maven for both halves of the project targetting different Java versions;
Editing the declaration would still seem less painful in the long run.
Digging further turned up a bug report which was closed as "Not an issue". The workaround suggested was not exactly helpful, compared to the first article I'd located, but apparently it was related to JSR166.
No comments:
Post a Comment