Bug 68311 "Quick Fix" sometimes gets the type wrong [quick fix]
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?
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/NewVariableCompletionProposal.java
ASTNode parent= fOriginalNode.getParent();	
			if (parent instanceof QualifiedName) {
				IBinding qualifierBinding= ((QualifiedName)parent).getQualifier().resolveBinding();
				if (qualifierBinding instanceof ITypeBinding) {
					modifiers |= Modifier.STATIC;
				}			
			} else if (ASTResolving.isInStaticContext(fOriginalNode)) {
				modifiers |= Modifier.STATIC;
			}
		}
		ASTNode node= ASTResolving.findParentType(fOriginalNode);
		if (newTypeDecl.equals(node)) {
			modifiers |= Modifier.PRIVATE;
		} else if (node instanceof AnonymousClassDeclaration) {
			modifiers |= Modifier.PROTECTED;
		} else {
			modifiers |= Modifier.PUBLIC;
		}
		
		return modifiers;
	}	
	/**
	 * Returns the variable kind.
	 * @return int
	 */
	public int getVariableKind() {
		return fVariableKind;
	}
}