1 19 20 package edu.umd.cs.findbugs.detect; 21 22 import java.util.BitSet ; 23 24 import org.apache.bcel.Constants; 25 import org.apache.bcel.generic.ConstantPoolGen; 26 import org.apache.bcel.generic.Instruction; 27 import org.apache.bcel.generic.InvokeInstruction; 28 import org.apache.bcel.generic.ObjectType; 29 import org.apache.bcel.generic.ReferenceType; 30 31 import edu.umd.cs.findbugs.ba.Hierarchy; 32 import edu.umd.cs.findbugs.ba.Location; 33 import edu.umd.cs.findbugs.ba.ObjectTypeFactory; 34 import edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback; 35 36 40 public class MethodReturnValueStreamFactory implements StreamFactory { 41 private static final BitSet invokeOpcodeSet = new BitSet (); 42 43 static { 44 invokeOpcodeSet.set(Constants.INVOKEINTERFACE); 45 invokeOpcodeSet.set(Constants.INVOKESPECIAL); 46 invokeOpcodeSet.set(Constants.INVOKESTATIC); 47 invokeOpcodeSet.set(Constants.INVOKEVIRTUAL); 48 } 49 50 private ObjectType baseClassType; 51 private String methodName; 52 private String methodSig; 53 private boolean isUninteresting; 54 private String bugType; 55 56 65 public MethodReturnValueStreamFactory(String baseClass, String methodName, String methodSig) { 66 this.baseClassType = ObjectTypeFactory.getInstance(baseClass); 67 this.methodName = methodName; 68 this.methodSig = methodSig; 69 this.isUninteresting = true; 70 } 71 72 83 public MethodReturnValueStreamFactory(String baseClass, String methodName, String methodSig, 84 String bugType) { 85 this.baseClassType = ObjectTypeFactory.getInstance(baseClass); 86 this.methodName = methodName; 87 this.methodSig = methodSig; 88 this.isUninteresting = false; 89 this.bugType = bugType; 90 } 91 92 public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, 93 RepositoryLookupFailureCallback lookupFailureCallback) { 94 95 try { 96 Instruction ins = location.getHandle().getInstruction(); 97 98 short opcode = ins.getOpcode(); 100 if (!invokeOpcodeSet.get(opcode)) 101 return null; 102 103 InvokeInstruction inv = (InvokeInstruction) ins; 106 ReferenceType classType = inv.getReferenceType(cpg); 107 if (!Hierarchy.isSubtype(classType, baseClassType)) 108 return null; 109 110 String methodName = inv.getMethodName(cpg); 112 String methodSig = inv.getSignature(cpg); 113 if (!this.methodName.equals(methodName) || !this.methodSig.equals(methodSig)) 114 return null; 115 116 String streamClass = type.getClassName(); 117 Stream result = new Stream(location, streamClass, streamClass) 118 .setIgnoreImplicitExceptions(true) 119 .setIsOpenOnCreation(true); 120 if (!isUninteresting) 121 result.setInteresting(bugType); 122 return result; 123 } catch (ClassNotFoundException e) { 124 lookupFailureCallback.reportMissingClass(e); 125 } 126 127 return null; 128 } 129 } 130 131 | Popular Tags |