@@ -0,0 +1,2370 @@
+/*%0A * FindBugs - Find bugs in Java programs%0A * Copyright (C) 2003, University of Maryland%0A * %0A * This library is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU Lesser General Public%0A * License as published by the Free Software Foundation; either%0A * version 2.1 of the License, or (at your option) any later version.%0A * %0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Lesser General Public License for more details.%0A * %0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this library; if not, write to the Free Software%0A * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA%0A */%0A%0Apackage edu.umd.cs.findbugs.detect;%0Aimport edu.umd.cs.findbugs.*;%0Aimport java.util.*;%0Aimport java.io.PrintStream;%0Aimport org.apache.bcel.classfile.*;%0Aimport java.util.zip.*;%0Aimport java.io.*;%0A%0Aimport edu.umd.cs.pugh.visitclass.DismantleBytecode;%0Aimport edu.umd.cs.pugh.visitclass.Constants2;%0A%0Apublic class FindFieldSelfAssignment extends BytecodeScanningDetector implements   Constants2 %7B%0A    private BugReporter bugReporter;%0A    int state;%0A%0A%0A  public FindFieldSelfAssignment(BugReporter bugReporter) %7B%0A%09this.bugReporter = bugReporter;%0A  %7D%0A%0A   JavaClass jClass;%0A   public void visit(JavaClass obj) %7B%0A%09jClass = obj;%0A%09%7D%0A   public void visit(Code obj) %7B%0A%09state = 0;%0A%09super.visit(obj);%0A%09%7D%0A%0A%0A    String f;%0A    public void sawOpcode(int seen) %7B%0A%0A%09switch (state) %7B%0A%09case 0:%0A%09%09if (seen == ALOAD_0)%0A%09%09%09state = 1;%0A%09%09break;%0A%09case 1:%0A%09%09if (seen == ALOAD_0)%0A%09%09%09state = 2;%0A%09%09else%0A%09%09%09state = 0;%0A%09%09break;%0A%09case 2:%0A%09%09if (seen == GETFIELD) %7B%0A%09%09%09state = 3;%0A%09%09%09f = refConstant;%0A%09%09%09%7D%0A%09%09else%0A%09%09%09state = 0;%0A%09%09break;%0A%09case 3:%0A%09%09if (seen == PUTFIELD && refConstant.equals(f)) %7B%0A%0A                                bugReporter.reportBug(new BugInstance(%22SA_FIELD_SELF_ASSIGNMENT%22, NORMAL_PRIORITY)%0A                                        .addClass(className)%0A                                        .addMethod(className, methodName, methodSig)%0A                                        .addField(betterClassConstant, nameConstant, %0A%09%09%09%09%09%09betterSigConstant, false)%0A                                        .addSourceLine(this)%0A%0A%09%09%09%09%09);%0A%09%09%09%7D%0A%09%09state = 0;%0A%09%09%7D%0A%09%7D%0A%09%09%0A%7D%0A

Check for self assignment of fields