Bug 50574 quick fix for removing local variable that is never read changes side effects
You'll need to set the "Local variable is never read" option in Window>Preferences>Java>Compiler>Unused Code to something other than "Ignore" to reproduce this. The quick fix "Remove variable <variable name> and assignments without possible side effects" that is offered if a local variable is never read makes two types of mistakes: 1. Some side effects are not recognized, e.g. "fixing" int k = 3; int n; n = k++; System.out.println (k); yields int k = 3; System.out.println (k); 2. The variable definition is removed even if it has side effects, e.g. int n = System.in.read (); is removed, whereas if a later assignment has side effects, it is left unchanged, including the now undefined reference to the local variable, e.g. int n; n = System.in.read (); becomes n = System.in.read (); What I think *should* happen is that the initializing assignment and later assignments should be treated alike; the left-hand side referring to the local variable should *always* be removed, and the right-hand side should be removed if and only if it has no side effects. This may result in invalid code if the right-hand side expression has side effects but does not form a statement; a deluxe version might extract the parts that have side effects and insert them as statements in the correct order, but even without this there would be a significant improvement over the current behaviour, which changes side effects and leaves references to undefined variables around.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/RemoveDeclarationCorrectionProposal.java
return CorrectionMessages.getFormattedString("RemoveDeclarationCorrectionProposal.removeunusedconstructor.description", name); 
				} else {
					return CorrectionMessages.getFormattedString("RemoveDeclarationCorrectionProposal.removeunusedmethod.description", name); 
				}
			case IBinding.VARIABLE:
				if (((IVariableBinding) binding).isField()) {
					return CorrectionMessages.getFormattedString("RemoveDeclarationCorrectionProposal.removeunusedfield.description", name); 
				} else {
					return CorrectionMessages.getFormattedString("RemoveDeclarationCorrectionProposal.removeunusedvar.description", name); 
				}
			default:
				return super.getDisplayString();		
		}
	}
	/*(non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.ASTRewriteCorrectionProposal#getRewrite()
	 */
	protected ASTRewrite getRewrite() {
		IBinding binding= fName.resolveBinding();
		CompilationUnit root= (CompilationUnit) fName.getRoot();
		ASTRewrite rewrite;
		if (binding.getKind() != IBinding.VARIABLE) {
			ASTNode declaration= root.findDeclaringNode(binding);
			rewrite= new ASTRewrite(declaration.getParent());
			rewrite.markAsRemoved(declaration);
		} else { 
			
			CompilationUnit completeRoot= AST.parseCompilationUnit(getCompilationUnit(), true, null, null);
			SimpleName nameNode= (SimpleName) NodeFinder.perform(completeRoot, fName.getStartPosition(), fName.getLength());
			rewrite= new ASTRewrite(completeRoot);