/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003,2004 University of Maryland
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs.detect;
import edu.umd.cs.findbugs.*;
import org.apache.bcel.classfile.Method;
import edu.umd.cs.findbugs.visitclass.Constants2;

public class FindNonShortCircuit extends BytecodeScanningDetector implements   Constants2 {

    int stage1 = 0;
    int stage2 = 0;
    int distance = 0;
    int distance2 = 0;
    private BugReporter bugReporter;

    public FindNonShortCircuit(BugReporter bugReporter) {
	this.bugReporter = bugReporter;
	}

    public void visit(Method obj) {
	stage1 = 0;
	stage2 = 0;
	distance = 1000000;
	distance2 = 1000000;
	}

    public void sawOpcode(int seen) {
	/* prototype for short-circuit bug */
	distance++;
	switch (seen) {
		case ICONST_1: 
			stage1 = 1;
			break;
		case GOTO:
			if (stage1 == 1) stage1 = 2;
			else stage1 = 0;
			break;
		case ICONST_0:
			if (stage1 == 2)  {
				distance = 0;
				// System.out.println("saw 1; goto X; 0");
				}
			stage1 = 0;
		default:
			stage1 = 0;
		}
	switch (seen) {
		case IAND: 
		case IOR: 
			// System.out.println("Saw IOR or IAND at distance " + distance);
			
			if (distance < 4)  {
				distance2 = distance;
				stage2 = 1;
				}
			else stage2 = 0;
			break;
		case IFEQ: 
		case IFNE: 
		case PUTFIELD: 
		case PUTSTATIC: 
		case IRETURN: 
			if (stage2 == 1)   {
				// System.out.println("Found nsc");
                                bugReporter.reportBug(
				new BugInstance("NS_NON_SHORT_CIRCUIT", 
						NORMAL_PRIORITY)
                                        .addClassAndMethod(this)
					.addSourceLine(this, PC));
				}
			stage2 = 0;
			break;
		default:
			stage2 = 0;
			break;
		};



		}
}

@@ -1166,24 +1166,42 @@
 tance2 = 0;%0A
+    int operator;%0A
     private 
@@ -1948,24 +1948,45 @@
 nce %3C 4)  %7B%0A
+%09%09%09%09operator = seen;%0A
 %09%09%09%09distance
@@ -1999,16 +1999,16 @@
 stance;%0A
-
 %09%09%09%09stag
@@ -2079,16 +2079,331 @@
  IFNE: %0A
+%09%09%09if (stage2 == 1)   %7B%0A%09%09%09%09// System.out.println(%22Found nsc%22);%0A                                bugReporter.reportBug(%0A%09%09%09%09new BugInstance(%22NS_NON_SHORT_CIRCUIT%22, %0A%09%09%09%09%09%09NORMAL_PRIORITY)%0A                                        .addClassAndMethod(this)%0A%09%09%09%09%09.addSourceLine(this, PC));%0A%09%09%09%09%7D%0A%09%09%09stage2 = 0;%0A%09%09%09break;%0A
 %09%09case P
@@ -2447,32 +2447,52 @@
 RETURN: %0A%09%09%09if (
+operator == IAND && 
 stage2 == 1)   %7B
@@ -2630,38 +2630,35 @@
 IRCUIT%22, %0A%09%09%09%09%09%09
-NORMAL
+LOW
 _PRIORITY)%0A     

Fixed some false positives