1 19 20 package edu.umd.cs.findbugs.detect; 21 22 23 import edu.umd.cs.findbugs.*; 24 import org.apache.bcel.classfile.Method; 25 26 33 34 public class FindUnconditionalWait extends BytecodeScanningDetector implements StatelessDetector { 35 int stage = 0; 36 private BugReporter bugReporter; 37 38 public FindUnconditionalWait(BugReporter bugReporter) { 39 this.bugReporter = bugReporter; 40 } 41 42 43 44 @Override 45 public void visit(Method obj) { 46 stage = 0; 47 } 48 49 @Override 50 public void sawOffset(int offset) { 51 if (stage == 1) stage = 0; 52 } 53 54 @Override 55 public void sawOpcode(int seen) { 56 switch (stage) { 57 case 0: 58 if (seen == MONITORENTER) 59 stage = 1; 60 break; 61 case 1: 62 if (seen == INVOKEVIRTUAL && getNameConstantOperand().equals("wait")) { 63 bugReporter.reportBug(new BugInstance(this, "UW_UNCOND_WAIT", 64 getSigConstantOperand().equals("()V") ? NORMAL_PRIORITY : LOW_PRIORITY) 65 .addClassAndMethod(this) 66 .addSourceLine(this)); 67 stage = 2; 68 } 69 break; 70 } 71 } 72 } 73 | Popular Tags |