Community
Participate
Working Groups
3.3M7 The following code could report an unnecessary cast. import java.awt.Container; import java.util.Collection; public class X { private <T extends Container> Collection<T> foo() { return null; } private void showProblem() { Collection<?> result = (Collection<Container>)foo(); // unnecessary cast } }
Problem comes from the fact the MethodBinding.inferredReturnType is incorrectly set when there is no explicit expected type (as in this case, where Cast context is not providing any - as per JLS), and a default one is supplied (Object). Need to record a flag indicating this fact. Stored the data on inferenceContext directly, instead of passing it around as an argument.
Created attachment 66146 [details] Proposed patch
Olivier - pls review
I could not apply the patch for the regression tests. The patch could be successfully applied for the changes in the org.eclipse.jdt.core project. I'll review the changes in org.eclipse.jdt.core for now. Could you please resubmit the patch for the regression tests' update? Thanks.
I didn't get the latest version of GenericTypeTest before applying the patch. The patch can be applied successfully now.
Patch looks good. I'll update the patch with a new regression test for the test case below.
Created attachment 66164 [details] Same patch + new regression tests and other tests cleanup
Released for 3.3RC1. Fixed
Regression test was comprised in GenericTypeTest#test1137 already (just some tweaking for extra warning... basically this is how I noticed this very bug). Please apply your other cleanup in the tests.
Verified for 3.3 RC1 using I20070515-0010