Community
Participate
Working Groups
Using 1217, the following code doesn't return the right result when executed. public class A { public static void main(String[] args) { double[] tab = new double[] {-0.0}; System.out.print(tab[0]); } } When executed, we return: 0.0 instead of -0.0. javac and jikes returns the right result. The bug comes from the optimization for array initializers that optimizes out the default values. We should check if the double value is equals to -0.0 or different from 0.0 before we optimize out the constant. For now we simply check different from 0. Here is a suggested fix for this: In org.eclipse.jdt.internal.compiler.ast.ArrayInitializer::generateCode: case T_int : case T_short : case T_byte : case T_char : case T_float : case T_long : case T_double : if (expr.constant.doubleValue() != 0) { codeStream.dup(); codeStream.generateInlinedValue(i); expr.generateCode(currentScope, codeStream, true); codeStream.arrayAtPut(elementsTypeID, false); } break; with: case T_int : case T_short : case T_byte : case T_char : case T_long : if (expr.constant.longValue() != 0) { codeStream.dup(); codeStream.generateInlinedValue(i); expr.generateCode(currentScope, codeStream, true); codeStream.arrayAtPut(elementsTypeID, false); } break; case T_float : case T_double : double constantValue = expr.constant.doubleValue(); if (constantValue == -0.0 || constantValue != 0) { codeStream.dup(); codeStream.generateInlinedValue(i); expr.generateCode(currentScope, codeStream, true); codeStream.arrayAtPut(elementsTypeID, false); } break; This would fix the same bug for float constants. With this patch, we have the right result.
Ok by me.
Fixed and released in 2.1 stream. Regression tests added.
Verified.