FULL PRODUCT VERSION :
java version: all versions from 1.7.0_04 up to 1.7.0_10
Java HotSpot(TM) 64-Bit Server VM
FULL OS VERSION :
All amd64 Linux, Windows, MacOS distributions. Not tested on x86 OSes.
A DESCRIPTION OF THE PROBLEM :
Primitive integer array has nonzero elements just after allocation. This situation is in the contradiction with JLS. Such a behavior occurs after jvm performs the compilation of the corresponding place of the code and only if corresponding code contains Arrays.fill(..) statement somewhere after array initialization (but not just after initialization). For more details see simple code example below.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just run the code listed below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: Build success
Actual: RuntimeException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class JvmBug {
public static void main(String[] args) {
int[] a;
int n = 0;
for (int i = 0; i < 100000000; ++i) {
a = new int[10];
for (int f : a)
if (f != 0)
throw new RuntimeException("Array just after allocation: "+ Arrays.toString(a));
Arrays.fill(a, 0);
for (int j = 0; j < a.length; ++j)
a[j] = (n - j)*i;
for (int f : a)
n += f;
}
System.out.println(n);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add Arrays.fill(a,0) just after array initialization.
java version: all versions from 1.7.0_04 up to 1.7.0_10
Java HotSpot(TM) 64-Bit Server VM
FULL OS VERSION :
All amd64 Linux, Windows, MacOS distributions. Not tested on x86 OSes.
A DESCRIPTION OF THE PROBLEM :
Primitive integer array has nonzero elements just after allocation. This situation is in the contradiction with JLS. Such a behavior occurs after jvm performs the compilation of the corresponding place of the code and only if corresponding code contains Arrays.fill(..) statement somewhere after array initialization (but not just after initialization). For more details see simple code example below.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just run the code listed below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: Build success
Actual: RuntimeException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class JvmBug {
public static void main(String[] args) {
int[] a;
int n = 0;
for (int i = 0; i < 100000000; ++i) {
a = new int[10];
for (int f : a)
if (f != 0)
throw new RuntimeException("Array just after allocation: "+ Arrays.toString(a));
Arrays.fill(a, 0);
for (int j = 0; j < a.length; ++j)
a[j] = (n - j)*i;
for (int f : a)
n += f;
}
System.out.println(n);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add Arrays.fill(a,0) just after array initialization.