1 19 20 package edu.umd.cs.findbugs.detect; 21 22 import org.apache.bcel.Constants; 23 import org.apache.bcel.generic.ConstantPoolGen; 24 import org.apache.bcel.generic.Instruction; 25 import org.apache.bcel.generic.ObjectType; 26 27 import edu.umd.cs.findbugs.ba.Hierarchy; 28 import edu.umd.cs.findbugs.ba.Location; 29 import edu.umd.cs.findbugs.ba.ObjectTypeFactory; 30 import edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback; 31 32 36 public class IOStreamFactory implements StreamFactory { 37 private ObjectType baseClassType; 38 private ObjectType[] uninterestingSubclassTypeList; 39 private String bugType; 40 41 public IOStreamFactory(String baseClass, String [] uninterestingSubclassList, String bugType) { 42 this.baseClassType = ObjectTypeFactory.getInstance(baseClass); 43 this.uninterestingSubclassTypeList = new ObjectType[uninterestingSubclassList.length]; 44 for (int i = 0; i < uninterestingSubclassList.length; ++i) { 45 this.uninterestingSubclassTypeList[i] = ObjectTypeFactory.getInstance(uninterestingSubclassList[i]); 46 } 47 this.bugType = bugType; 48 } 49 50 public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, 51 RepositoryLookupFailureCallback lookupFailureCallback) { 52 53 try { 54 Instruction ins = location.getHandle().getInstruction(); 55 56 if (ins.getOpcode() != Constants.NEW) 57 return null; 58 59 if (Hierarchy.isSubtype(type, baseClassType)) { 60 boolean isUninteresting = false; 61 for (ObjectType aUninterestingSubclassTypeList : uninterestingSubclassTypeList) { 62 if (Hierarchy.isSubtype(type, aUninterestingSubclassTypeList)) { 63 isUninteresting = true; 64 break; 65 } 66 } 67 Stream result = new Stream(location, type.getClassName(), baseClassType.getClassName()) 68 .setIgnoreImplicitExceptions(true); 69 if (!isUninteresting) 70 result.setInteresting(bugType); 71 return result; 72 } 73 } catch (ClassNotFoundException e) { 74 lookupFailureCallback.reportMissingClass(e); 75 } 76 77 return null; 78 } 79 } 80 81 | Popular Tags |