Project: JDT
Bug 68311 "Quick Fix" sometimes gets the type wrong [quick fix]
Reported: 2004-06-23 11:22:28 | Status: resolved fixed

I had the following code: PaymentRoute[] routes = ... PaymentRoute test = null; for (int i=0; i<routes.length; i++) { if (METHOD.equals(routes[i].getMethod())) test = routes[i]; } The error was that METHOD was undefined, I wanted a new constant for it. PaymentRoute.getMethod() returns String, therefore I'd have expected it to create public static final String METHOD = null; up the top, but for whatever reason, it created the type as "Date", not "String". It had managed to get this right on an earlier occasion though! Maybe a coincidence, but my very first import up the top was import java.util.Date; and it was warning me that this was unused. Having removed that unused import and also removed the public static final Date METHOD = null; then tried the quick fix again, it now plumps for type "Object" which I guess is OK, though a bit of a cop-out! I think there's a bug lurking there somewhere, it's trying do the most work for the least effort by fixing the unused import as well as the missing variable all at once, even though the import was just a warning and I didn't go anywhere near it?

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/NewVariableCompletionProposal.java