-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8u74
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
javac 1.8.0_74
A DESCRIPTION OF THE PROBLEM :
Compiling Java 7 that uses java.util.concurrent.ConcurrentHashMap with JDK8 produces code that is not executable on JDK7. That is attempt to run such code fails with the exception:
Exception in thread "main" java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
at CHMCompilationTest.main(CHMCompilationTest.java:8)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Use JDK8 to compile attached CHMCompilationTest file using the following command:
javac -source 1.7 -target 1.7 CHMCompilationTest.java
NB: This will actually produce a warning:
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
2. Run compiled class using JDK7. I've used the following version:
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Program runs without error and prints:
[]
ACTUAL -
Exception in thread "main" java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
at CHMCompilationTest.main(CHMCompilationTest.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class CHMCompilationTest {
public static void main(String[] args) {
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
Set<Integer> keys = map.keySet();
System.out.println(keys);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use JDK7 to compile Java 7 code.
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
javac 1.8.0_74
A DESCRIPTION OF THE PROBLEM :
Compiling Java 7 that uses java.util.concurrent.ConcurrentHashMap with JDK8 produces code that is not executable on JDK7. That is attempt to run such code fails with the exception:
Exception in thread "main" java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
at CHMCompilationTest.main(CHMCompilationTest.java:8)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Use JDK8 to compile attached CHMCompilationTest file using the following command:
javac -source 1.7 -target 1.7 CHMCompilationTest.java
NB: This will actually produce a warning:
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
2. Run compiled class using JDK7. I've used the following version:
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Program runs without error and prints:
[]
ACTUAL -
Exception in thread "main" java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
at CHMCompilationTest.main(CHMCompilationTest.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class CHMCompilationTest {
public static void main(String[] args) {
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
Set<Integer> keys = map.keySet();
System.out.println(keys);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use JDK7 to compile Java 7 code.
- relates to
-
JDK-8058150 JEP 247: Compile for Older Platform Versions
-
- Closed
-