package edu.umd.cs.findbugs;
import java.util.*;
import java.io.PrintStream;
import org.apache.bcel.classfile.*;
import java.util.zip.*;
import java.io.*;
import edu.umd.cs.pugh.visitclass.Constants2;

public class FindDoubleCheck extends BytecodeScanningDetector implements   Constants2 {
    int stage = 0;
    int startPC;
    int count;
    boolean sawMonitorEnter;
    HashSet<FieldAnnotation> fields = new HashSet<FieldAnnotation>();
    HashSet<FieldAnnotation> twice = new HashSet<FieldAnnotation>();
    private BugReporter bugReporter;

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

    public void visit(Method obj) {
        super.visit(obj);
	fields.clear();
	twice.clear();
	stage = 0;
	count = 0;
	sawMonitorEnter = false;
	}

    public void sawOpcode(int seen) {

	if (seen == MONITORENTER) sawMonitorEnter = true;
	if (seen == GETFIELD || seen == GETSTATIC)  {
		FieldAnnotation f = FieldAnnotation.fromReferencedField(this);
		if (!sawMonitorEnter) {
			fields.add(f);
			startPC = PC;
			}
		else if(fields.contains(f))
			twice.add(f);
		}
	switch (stage) {
	 case 0:
		if (seen == IFNULL || seen == IFNONNULL) stage++;
		count = 0;
		break;
	 case 1:
		if (seen == MONITORENTER)  stage++;
		else { 
			count++;
			if (count > 10) stage = 0;
			}
		break;
	 case 2:
		if (seen == IFNULL || seen == IFNONNULL) {
			stage++;
			}
		else { 
			count++;
			if (count > 10) stage = 0;
			}
		break;
	 case 3:
		if (seen == PUTFIELD || seen == PUTSTATIC) {
			FieldAnnotation f = FieldAnnotation.fromReferencedField(this);
			if (fields.contains(f) && !nameConstant.startsWith("class$")) {
				bugReporter.reportBug(new BugInstance("DC_DOUBLECHECK", NORMAL_PRIORITY)
					.addClassAndMethod(this)
					.addField(f).describe("FIELD_ON")
					.addSourceLine(this, startPC));
				stage++;
				}
			}
		break;
	default:
	}
	}
}

@@ -317,16 +317,23 @@
  startPC
+, endPC
 ;%0A    in
@@ -1377,16 +1377,31 @@
 NULL) %7B%0A
+%09%09%09endPC = PC;%0A
 %09%09%09stage
@@ -1830,16 +1830,21 @@
 urceLine
+Range
 (this, s
@@ -1849,16 +1849,23 @@
  startPC
+, endPC
 ));%0A%09%09%09%09

Use full range of PC values when reporting the source annotation for the bug instance.