Community
Participate
Working Groups
Build 20020425++ The following code compiled with javac and run with java return '0'. Compiled with the JDT compiler and run will java (in eclipse) return '-1'. public class Foo2 { public static void main(String[] args) { int x = -8; x += 7.8f; System.out.println(x); } } The problem is when you generate the bytecode, you try to optimise the code by used the iinc opcode if possible. But you do that even if the right operand is a floating-point value, that can generate some probleme if we work on negative value (as in the example). I fix the probleme in my target by replacing the line 393 of SingleNameReference.generateCompoundAssignment(BlockScope, CodeStream, MethodBinding, Expression, int, int, boolean) with : if (((assignConstant = expression.constant) != NotAConstant) && /* new code */ ((incrementTypeId = assignConstant.typeID()) != T_float) && (incrementTypeId != T_double) && /* */ ((increment = assignConstant.intValue()) == (short) increment)) {
Indeed, we should not optimize this case. Good find. Fixed