FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux yaroska-lenovo 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Initializing Map in static block in enum.
While filling the map with stream.parallel main thread blocks.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java EnumInitTest
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
console output:
start...
BANANA
end.
ACTUAL -
start...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class EnumInitTest {
public static void main(String[] args) {
System.out.println("start...");
System.out.println(Fruit.BANANA);
System.out.println("end.");
}
}
----------------------
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public enum Fruit {
APPLE, BANANA, UNKNOWN;
private static final Map<String, Fruit> FRUITS_BY_NAME = new ConcurrentHashMap<>();
static {
Arrays.stream(Fruit.values()).parallel().forEach(t -> {
FRUITS_BY_NAME.put(t.name(), t);
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
remove parallel() call
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux yaroska-lenovo 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Initializing Map in static block in enum.
While filling the map with stream.parallel main thread blocks.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java EnumInitTest
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
console output:
start...
BANANA
end.
ACTUAL -
start...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class EnumInitTest {
public static void main(String[] args) {
System.out.println("start...");
System.out.println(Fruit.BANANA);
System.out.println("end.");
}
}
----------------------
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public enum Fruit {
APPLE, BANANA, UNKNOWN;
private static final Map<String, Fruit> FRUITS_BY_NAME = new ConcurrentHashMap<>();
static {
Arrays.stream(Fruit.values()).parallel().forEach(t -> {
FRUITS_BY_NAME.put(t.name(), t);
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
remove parallel() call