Community
Participate
Working Groups
Build id: M20090807-0800 In the following code, the cast to Integer is useless and there is no warning for that: import java.util.Vector; public class UselessCastWarning { void test() { Vector<Integer> v= new Vector<Integer>(1); if (((Integer) v.get(0))==1) // <= here System.out.println(); } }
Created attachment 147852 [details] proposed fix v0.5 + regression test The inconsistent behaviour was observed in cases where autoboxing took place. Added a check for that in org.eclipse.jdt.internal.compiler.ast.CastExpression#checkNeedForArgumentCasts. Added regression test org.eclipse.jdt.core.tests.compiler.regression.CastTest#test047
Why add the 2 local variables : unnecessaryLeftCast & unnecessaryRightCast ? They are only read in one place each. But if you want to add them to make the code cleaner, then why not add each one in the local scope where its used ? Also its confusing to define a local boolean as : boolean unnecessaryLeftCast = (left.bits & ASTNode.UnnecessaryCast) != 0; and then negate it : if (!unnecessaryLeftCast && ...
> Also its confusing to define a local boolean as : > > boolean unnecessaryLeftCast = (left.bits & ASTNode.UnnecessaryCast) != 0; > > and then negate it : > > if (!unnecessaryLeftCast && ... My intention was indeed to have a cleaner code, but yes i admit that it seems confusing. Will correct it. Are you ok with the fix otherwise?
yes - its fine
Created attachment 148029 [details] proposed fix v1.0 + regression test
Released in HEAD for 3.6M3
Verified for 3.6M3 using build I20091025-2000