Community
Participate
Working Groups
In my build of eclipse: I20050201-0800 i have this test file: public class Test { public Test() { super(); } public Object convert(Object value) { Double d = (Double)value; d = (d/100); return d; } public static void main(String[] args) { Test test = new Test(); Object value = test.convert(new Double(50)); } } eclipse generates the wrong byte code for that: 5: aload_2 6: invokevirtual #21; //Method java/lang/Double.doubleValue:()D 9: ldc2_w #22; //double 100.0d 12: ddiv 13: invokevirtual #21; //Method java/lang/Double.doubleValue:()D 16: astore_2 javac: 5: aload_2 6: invokevirtual #3; //Method java/lang/Double.doubleValue:()D 9: ldc2_w #4; //double 100.0d 12: ddiv 13: invokestatic #6; //Method java/lang/Double.valueOf:(D)Ljava/lang/Double; 16: astore_2 and that is logical because the double must be converted to a Double again and that shouldn't be done with a doubleValue() method (that a double doesn't have)
this does work: d /= 100; instead of d = d/100;
Reproduced
We should indeed box the result of #doubleValue()->double into Double. I am wondering where the #doubleValue()->Double is defined; javac uses it but it isn't defined in Number/Double.
Oops, ignore my previous comment. We simply misgenerate the boxing conversion.
Added AutoboxingTest#test092. Problem comes from optimization for converting d=d/100 into d/=100, passing along wrong implicitConversion value; and thus losing need for boxing conversion. Fixed
Verified in I20050214