Java 类org.apache.bcel.generic.MethodGen 实例源码

项目:parabuild-ci    文件:BCPDoubleCheck.java   
public void reportMatch(ClassContext classContext, Method method, ByteCodePatternMatch match) {
    MethodGen methodGen = classContext.getMethodGen(method);
    JavaClass javaClass = classContext.getJavaClass();

    BindingSet bindingSet = match.getBindingSet();

    // Note that the lookup of "h" cannot fail, and
    // it is guaranteed to be bound to a FieldVariable.
    Binding binding = bindingSet.lookup("h");
    FieldVariable field = (FieldVariable) binding.getVariable();

    // Ignore fields generated for accesses to Foo.class
    if (field.getFieldName().startsWith("class$"))
        return;

    // Find start and end instructions (for reporting source lines)
    InstructionHandle start = match.getLabeledInstruction("startDC");
    InstructionHandle end = match.getLabeledInstruction("endDC");

    String sourceFile = javaClass.getSourceFileName();
    bugReporter.reportBug(new BugInstance(this, "BCPDC_DOUBLECHECK", NORMAL_PRIORITY)
            .addClassAndMethod(methodGen, sourceFile)
            .addField(field).describe("FIELD_ON")
            .addSourceLine(methodGen, sourceFile, start, end));
}
项目:parabuild-ci    文件:ResourceTrackingDetector.java   
public void analyzeMethod(ClassContext classContext, Method method,
                          ResourceTrackerType resourceTracker, ResourceCollection<Resource> resourceCollection)
        throws CFGBuilderException, DataflowAnalysisException {

    MethodGen methodGen = classContext.getMethodGen(method);
    CFG cfg = classContext.getCFG(method);
    DepthFirstSearch dfs = classContext.getDepthFirstSearch(method);

    if (DEBUG) System.out.println(SignatureConverter.convertMethodSignature(methodGen));

    for (Iterator<Resource> i = resourceCollection.resourceIterator(); i.hasNext();) {
        Resource resource = i.next();

        ResourceValueAnalysis<Resource> analysis =
                new ResourceValueAnalysis<Resource>(methodGen, cfg, dfs, resourceTracker, resource);
        Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>> dataflow =
                new Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>>(cfg, analysis);

        dataflow.execute();
        inspectResult(classContext.getJavaClass(), methodGen, cfg, dataflow, resource);
    }
}
项目:Android_Code_Arbiter    文件:UnsafeJacksonDeserializationDetector.java   
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {
    MethodGen methodGen = classContext.getMethodGen(m);
    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    CFG cfg = classContext.getCFG(m);

    if (methodGen == null || methodGen.getInstructionList() == null) {
        return; //No instruction .. nothing to do
    }
    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
        Location location = i.next();
        Instruction inst = location.getHandle().getInstruction();
        if (inst instanceof InvokeInstruction) {
            InvokeInstruction invoke = (InvokeInstruction) inst;
            String methodName = invoke.getMethodName(cpg);
            if ("enableDefaultTyping".equals(methodName)) {
                JavaClass clz = classContext.getJavaClass();
                bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY)
                        .addClass(clz)
                        .addMethod(clz, m)
                        .addCalledMethod(cpg, invoke)
                        .addSourceLine(classContext, m, location)
                );
            }
        }
    }
}
项目:cashmere    文件:MethodTable.java   
SpawnTableEntry(SpawnTableEntry orig, MethodGen mg, MethodGen origM) {
    isLocalUsed = new boolean[origM.getMaxLocals()];

    hasInlet = orig.hasInlet;
    if (hasInlet) {
    /* copy and rewite exception table */
    CodeExceptionGen origE[] = origM.getExceptionHandlers();
    CodeExceptionGen newE[] = mg.getExceptionHandlers();

    catchBlocks = new ArrayList<CodeExceptionGen>();

    for (int i = 0; i < orig.catchBlocks.size(); i++) {
        CodeExceptionGen origCatch = orig.catchBlocks.get(i);
        for (int j = 0; j < origE.length; j++) {
        if (origCatch == origE[j]) {
            catchBlocks.add(newE[j]);
            break;
        }
        }
    }
    }
}
项目:cashmere    文件:MethodTable.java   
MethodTableEntry(MethodTableEntry orig, MethodGen mg) {
    this.mg = mg;
    containsInlet = orig.containsInlet;
    clone = null;
    nrSpawns = orig.nrSpawns;
    isClone = true;
    typesOfParams = orig.typesOfParams;
    typesOfParamsNoThis = orig.typesOfParamsNoThis;

    startLocalAlloc = orig.startLocalAlloc;

    spawnTable = new SpawnTableEntry[orig.spawnTable.length];
    for (int i = 0; i < spawnTable.length; i++) {
    spawnTable[i] = new SpawnTableEntry(orig.spawnTable[i], mg,
        orig.mg);
    }
}
项目:cashmere    文件:MethodTable.java   
private int calcNrSpawns(MethodGen mg) {
InstructionList il = mg.getInstructionList();
if (il == null) {
    return 0;
}

InstructionHandle[] ins = il.getInstructionHandles();
int count = 0;

for (int i = 0; i < ins.length; i++) {
    if (ins[i].getInstruction() instanceof INVOKEVIRTUAL) {
    Method target = self.findMethod((INVOKEVIRTUAL) (ins[i]
        .getInstruction()));
    JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins[i]
        .getInstruction()));
    if (isSpawnable(target, cl)) {
        count++;
    }
    }
}

return count;
   }
项目:cashmere    文件:MethodTable.java   
final LocalVariableGen getLocal(MethodGen m, LocalVariableInstruction curr,
    int pos) {
int localNr = curr.getIndex();
LocalVariableGen[] lt = getLocalTable(m);

for (int i = 0; i < lt.length; i++) {
    // Watch out. The first initialization seems not to be included in
    // the range given in the local variable table!

    if (localNr == lt[i].getIndex()) {
    // System.err.println("Looking for local " + localNr
    // + " on position " + pos);
    // System.err.println("found one with range "
    // + lt[i].getStart().getPrev().getPosition() + ", "
    // + lt[i].getEnd().getPosition());

    if (pos >= lt[i].getStart().getPrev().getPosition()
        && pos < (lt[i].getEnd().getPosition())) {
        return lt[i];
    }
    }
}

return null;
   }
项目:cashmere    文件:MethodTable.java   
boolean containsSpawnedCall(MethodGen m) {
InstructionList code = m.getInstructionList();

if (code == null) {
    return false;
}

InstructionHandle ih[] = code.getInstructionHandles();

for (int i = 0; i < ih.length; i++) {
    Instruction ins = ih[i].getInstruction();
    if (ins instanceof INVOKEVIRTUAL) {
    Method target = self.findMethod((INVOKEVIRTUAL) (ins));
    JavaClass cl = self.findMethodClass((INVOKEVIRTUAL) (ins));
    if (isSpawnable(target, cl)) {
        return true;
    }
    }
}

return false;
   }
项目:cashmere    文件:Cashmerec.java   
CodeExceptionGen getExceptionHandler(MethodGen m, InstructionHandle self) {
    CodeExceptionGen exc[] = m.getExceptionHandlers();

    for (int j = 0; j < exc.length; j++) {
        InstructionHandle h = exc[j].getStartPC();
        InstructionHandle h2 = exc[j].getEndPC();
        do {
            if (h == self) {
                return exc[j];
            }
            h = h.getNext();
        } while (h != h2);
        if (h == self) {
            return exc[j];
        }
    }

    return null;
}
项目:cashmere    文件:Cashmerec.java   
InstructionHandle rewriteStore(MethodGen m, InstructionList il,
    InstructionHandle i, int maxLocals, String localClassName) {
    LocalVariableInstruction curr = (LocalVariableInstruction) (i
        .getInstruction());
    Type type = mtab.getLocalType(m, curr, i.getPosition());
    if (type == null) {
        return i;
    }
    String name = mtab.getLocalName(m, curr, i.getPosition());
    String fieldName = MethodTable.generatedLocalName(type, name);

    i.setInstruction(new ALOAD(maxLocals));
    i = i.getNext();

    if (type.equals(Type.LONG) || type.equals(Type.DOUBLE)) {
        il.insert(i, new DUP_X2());
        il.insert(i, new POP());
    } else {
        il.insert(i, new SWAP());
    }

    i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
        type, Constants.PUTFIELD));
    return i;
}
项目:cashmere    文件:Cashmerec.java   
InstructionHandle rewriteLoad(MethodGen m, InstructionList il,
    InstructionHandle i, int maxLocals, String localClassName) {
    LocalVariableInstruction curr = (LocalVariableInstruction) (i
        .getInstruction());
    Type type = mtab.getLocalType(m, curr, i.getPosition());
    if (type == null) {
        return i;
    }
    String name = mtab.getLocalName(m, curr, i.getPosition());
    String fieldName = MethodTable.generatedLocalName(type, name);

    i.setInstruction(new ALOAD(maxLocals));
    i = i.getNext();
    i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
        type, Constants.GETFIELD));

    return i;
}
项目:cashmere    文件:ClassViewer.java   
void showClass(PrintStream out, JavaClass javaClass) {
print(out, 0, "constantpool:\n");
out.println(javaClass.getConstantPool());
ConstantPoolGen cp = new ConstantPoolGen(javaClass.getConstantPool());

Method[] methods = javaClass.getMethods();

for (Method method : methods) {
    MethodGen methodGen = new MethodGen(method, javaClass.getClassName(), cp);
    print(out, 0, "%s (with stack consumption)\n", method);
    showMethod(out, methodGen, javaClass.getConstantPool());
    out.println();

    print(out, 0, "%s\n", method);
    if (method.getCode() != null) out.println((method.getCode()).toString(true));
    out.println();
}
   }
项目:FindMoreBugs    文件:CommandInjectionVulnerabilityDetector.java   
public void visitClassContext(ClassContext cc) {
    JavaClass jc = cc.getJavaClass();

    Method[] methods = jc.getMethods();

    for (Method m : methods) {
        MethodGen mg = cc.getMethodGen(m);

        if (mg == null) {
            continue;
        }

        try {
            analyzeMethod(cc, m);
        } catch (Exception e) {
            // There was a problem,
            // report it. Probably
            // isn't going to
            // be a big deal.
            e.printStackTrace();
        }
    }
}
项目:JRemoting    文件:BcelStubGenerator.java   
/**
 * Creates a method class$(String) which is used
 * during SomeClass.class instruction
 *
 * @param generatedClassName the instance class name
 */
protected void createHelperMethodForDotClassCalls(String generatedClassName) {
    InstructionList il = new InstructionList();
    MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool);
    InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC));
    InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT));
    InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1));
    il.append(factory.createNew("java.lang.NoClassDefFoundError"));
    il.append(InstructionConstants.DUP);
    il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
    il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
    il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ATHROW);
    method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException"));
    method.setMaxStack();
    method.setMaxLocals();
    classGen.addMethod(method.getMethod());
    il.dispose();
}
项目:JRemoting    文件:BcelStubGenerator.java   
private void generateEqualsMethod(String generatedClassName) {

        /* public boolean equals(Object o) {
         *   return stubHelper.isEquals(this,o);
         * }
         */

        InstructionList il = new InstructionList();
        MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.BOOLEAN, new Type[]{Type.OBJECT}, new String[]{"arg0"}, "equals", generatedClassName, il, constantsPool);

        il.append(InstructionFactory.createLoad(Type.OBJECT, 0));

        il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD));
        il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
        il.append(InstructionFactory.createLoad(Type.OBJECT, 1));

        il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "isEquals", Type.BOOLEAN, new Type[]{Type.OBJECT, Type.OBJECT}, Constants.INVOKEINTERFACE));
        il.append(InstructionFactory.createReturn(Type.INT));
        method.setMaxStack();
        method.setMaxLocals();
        classGen.addMethod(method.getMethod());
        il.dispose();
    }
项目:SIF    文件:SuspectMethodFinder.java   
private MethodGen load_mthd(String cname, String msig) {
    JavaClass jcls = null;

    String cls_fn = Config.INPUT_DIR + cname.replace(".", "/") + ".class";
    // Util.log(cls_fn);
    String[] arr = msig.split(":");

    try {
        jcls = new ClassParser(cls_fn).parse();
    } catch (IOException e) {
        e.printStackTrace();
    }

    assert (jcls != null) : "JavaClass is NULL";

    ClassGen cgen = new ClassGen(jcls);
    Method mthd = cgen.containsMethod(arr[0], arr[1]);

    assert (mthd != null) : "Method " + msig + " not in ClassGen";

    MethodGen mgen = new MethodGen(mthd, cname, cgen.getConstantPool());

    return mgen;
}
项目:findbugs-all-the-bugs    文件:FindTwoLockWait.java   
public boolean preScreen(MethodGen mg) {
    ConstantPoolGen cpg = mg.getConstantPool();

    int lockCount = mg.isSynchronized() ? 1 : 0;
    boolean sawWaitOrNotify = false;

    InstructionHandle handle = mg.getInstructionList().getStart();
    while (handle != null && !(lockCount >= 2 && sawWaitOrNotify)) {
        Instruction ins = handle.getInstruction();
        if (ins instanceof MONITORENTER)
            ++lockCount;
        else if (ins instanceof INVOKEVIRTUAL) {
            INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins;
            String methodName = inv.getMethodName(cpg);
            if (methodName.equals("wait") || methodName.startsWith("notify"))
                sawWaitOrNotify = true;
        }

        handle = handle.getNext();
    }

    return lockCount >= 2 && sawWaitOrNotify;
}
项目:findbugs-all-the-bugs    文件:BugInstance.java   
/**
 * Add a source line annotation describing a range of instructions.
 *
 * @param classContext
 *            the ClassContext
 * @param methodGen
 *            the method
 * @param sourceFile
 *            source file the method is defined in
 * @param start
 *            the start instruction in the range
 * @param end
 *            the end instruction in the range (inclusive)
 * @return this object
 */
@Nonnull
public BugInstance addSourceLine(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start,
        InstructionHandle end) {
    // Make sure start and end are really in the right order.
    if (start.getPosition() > end.getPosition()) {
        InstructionHandle tmp = start;
        start = end;
        end = tmp;
    }
    SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstructionRange(classContext, methodGen,
            sourceFile, start, end);
    if (sourceLineAnnotation != null)
        add(sourceLineAnnotation);
    return this;
}
项目:FindBug-for-Domino-Designer    文件:IsNullValueAnalysis.java   
public IsNullValueAnalysis(MethodDescriptor descriptor, MethodGen methodGen, CFG cfg, ValueNumberDataflow vnaDataflow,
        TypeDataflow typeDataflow, DepthFirstSearch dfs, AssertionMethods assertionMethods) {
    super(dfs);

    this.trackValueNumbers = AnalysisContext.currentAnalysisContext().getBoolProperty(
            AnalysisFeatures.TRACK_VALUE_NUMBERS_IN_NULL_POINTER_ANALYSIS);

    this.methodGen = methodGen;
    this.visitor = new IsNullValueFrameModelingVisitor(methodGen.getConstantPool(), assertionMethods, vnaDataflow,
            typeDataflow, trackValueNumbers);
    this.vnaDataflow = vnaDataflow;
    this.cfg = cfg;
    this.locationWhereValueBecomesNullSet = new HashSet<LocationWhereValueBecomesNull>();
    this.pointerEqualityCheck = getForPointerEqualityCheck(cfg, vnaDataflow);

    if (DEBUG) {
        System.out.println("IsNullValueAnalysis for " + methodGen.getClassName() + "." + methodGen.getName() + " : "
                + methodGen.getSignature());
    }
}
项目:findbugs-all-the-bugs    文件:TypeAnalysis.java   
/**
 * Constructor.
 * 
 * @param method
 *            TODO
 * @param methodGen
 *            the MethodGen whose CFG we'll be analyzing
 * @param cfg
 *            the control flow graph
 * @param dfs
 *            DepthFirstSearch of the method
 * @param typeMerger
 *            object to merge types
 * @param visitor
 *            a TypeFrameModelingVisitor to use to model the effect of
 *            instructions
 * @param lookupFailureCallback
 *            lookup failure callback
 * @param exceptionSetFactory
 *            factory for creating ExceptionSet objects
 */
public TypeAnalysis(Method method, MethodGen methodGen, CFG cfg, DepthFirstSearch dfs, TypeMerger typeMerger,
        TypeFrameModelingVisitor visitor, RepositoryLookupFailureCallback lookupFailureCallback,
        ExceptionSetFactory exceptionSetFactory) {
    super(dfs);
    this.method = method;
    Code code = method.getCode();
    if (code == null)
        throw new IllegalArgumentException(method.getName() + " has no code");
    for (Attribute a : code.getAttributes()) {
        if (a instanceof LocalVariableTypeTable) 
            visitor.setLocalTypeTable((LocalVariableTypeTable) a);
    }
    this.methodGen = methodGen;
    this.cfg = cfg;
    this.typeMerger = typeMerger;
    this.visitor = visitor;
    this.thrownExceptionSetMap = new HashMap<BasicBlock, CachedExceptionSet>();
    this.lookupFailureCallback = lookupFailureCallback;
    this.exceptionSetFactory = exceptionSetFactory;
    this.instanceOfCheckMap = new HashMap<BasicBlock, InstanceOfCheck>();
    if (DEBUG) {
        System.out.println("\n\nAnalyzing " + methodGen);
    }
}
项目:FindBug-for-Domino-Designer    文件:BugInstance.java   
/**
 * Add a source line annotation describing a range of instructions.
 *
 * @param classContext
 *            the ClassContext
 * @param methodGen
 *            the method
 * @param sourceFile
 *            source file the method is defined in
 * @param start
 *            the start instruction in the range
 * @param end
 *            the end instruction in the range (inclusive)
 * @return this object
 */
@Nonnull
public BugInstance addSourceLine(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start,
        InstructionHandle end) {
    // Make sure start and end are really in the right order.
    if (start.getPosition() > end.getPosition()) {
        InstructionHandle tmp = start;
        start = end;
        end = tmp;
    }
    SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstructionRange(classContext, methodGen,
            sourceFile, start, end);
    if (sourceLineAnnotation != null)
        add(sourceLineAnnotation);
    return this;
}
项目:commons-sandbox    文件:BCEL_289.java   
public static void main1(String[] args) throws Throwable {
    ClassParser cp = new ClassParser("/home/kinow/Development/java/apache/tests-for-commons/target/classes/br/eti/kinoshita/commons/bcel/Test.class");
    ClassGen cg = new ClassGen(cp.parse());
    MethodGen mg = new MethodGen(cg.getMethodAt(0), cg.getClassName(), cg.getConstantPool());
    mg.getAnnotationsOnParameter(0);
    System.out.println("OK!");
}
项目:commons-sandbox    文件:BCEL_289.java   
public static void main(String[] args) throws Throwable {
    ClassParser cp = new ClassParser("/home/kinow/Development/java/apache/tests-for-commons/target/classes/br/eti/kinoshita/commons/bcel/Test$Inner.class");
    ClassGen cg = new ClassGen(cp.parse());
    MethodGen mg = new MethodGen(cg.getMethodAt(0), cg.getClassName(), cg.getConstantPool());
    // here..args.
    System.out.println(mg.getAnnotationsOnParameter(0));
    System.out.println("OK!");
}
项目:parabuild-ci    文件:SourceLineAnnotation.java   
/**
 * Factory method for creating a source line annotation describing
 * an entire method.
 *
 * @param methodGen the method being visited
 * @return the SourceLineAnnotation, or null if we do not have line number information
 *         for the method
 */
public static SourceLineAnnotation fromVisitedMethod(MethodGen methodGen, String sourceFile) {
    LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool());
    String className = methodGen.getClassName();
    int codeSize = methodGen.getInstructionList().getLength();
    if (lineNumberTable == null)
        return createUnknown(className, sourceFile, 0, codeSize - 1);
    return forEntireMethod(className, sourceFile, lineNumberTable, codeSize);
}
项目:parabuild-ci    文件:SourceLineAnnotation.java   
/**
 * Factory method for creating a source line annotation describing the
 * source line number for a visited instruction.
 *
 * @param methodGen the MethodGen object representing the method
 * @param handle    the InstructionHandle containing the visited instruction
 * @return the SourceLineAnnotation, or null if we do not have line number information
 *         for the instruction
 */
public static SourceLineAnnotation fromVisitedInstruction(MethodGen methodGen, String sourceFile, InstructionHandle handle) {
    LineNumberTable table = methodGen.getLineNumberTable(methodGen.getConstantPool());
    String className = methodGen.getClassName();

    int bytecodeOffset = handle.getPosition();

    if (table == null)
        return createUnknown(className, sourceFile, bytecodeOffset, bytecodeOffset);

    int lineNumber = table.getSourceLine(handle.getPosition());
    return new SourceLineAnnotation(className, sourceFile, lineNumber, lineNumber, bytecodeOffset, bytecodeOffset);
}
项目:parabuild-ci    文件:SourceLineAnnotation.java   
/**
 * Factory method for creating a source line annotation describing
 * the source line numbers for a range of instruction in a method.
 *
 * @param methodGen the method
 * @param start     the start instruction
 * @param end       the end instruction (inclusive)
 */
public static SourceLineAnnotation fromVisitedInstructionRange(MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) {
    LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool());
    String className = methodGen.getClassName();

    if (lineNumberTable == null)
        return createUnknown(className, sourceFile, start.getPosition(), end.getPosition());

    int startLine = lineNumberTable.getSourceLine(start.getPosition());
    int endLine = lineNumberTable.getSourceLine(end.getPosition());
    return new SourceLineAnnotation(className, sourceFile, startLine, endLine, start.getPosition(), end.getPosition());
}
项目:parabuild-ci    文件:FindOpenStream.java   
public void inspectResult(JavaClass javaClass, MethodGen methodGen, CFG cfg,
                          Dataflow<ResourceValueFrame, ResourceValueAnalysis<Stream>> dataflow, Stream stream) {

    ResourceValueFrame exitFrame = dataflow.getResultFact(cfg.getExit());

    int exitStatus = exitFrame.getStatus();
    if (exitStatus == ResourceValueFrame.OPEN
            || exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) {

        // FIXME: Stream object should be queried for the
        // priority.

        String bugType = stream.getBugType();
        int priority = NORMAL_PRIORITY;
        if (exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) {
            bugType += "_EXCEPTION_PATH";
            priority = LOW_PRIORITY;
        }

        potentialOpenStreamList.add(new PotentialOpenStream(bugType, priority, stream));
    } else if (exitStatus == ResourceValueFrame.CLOSED) {
        // Remember that this stream was closed on all paths.
        // Later, we will mark all of the streams in its equivalence class
        // as having been closed.
        stream.setClosed();
    }
}
项目:parabuild-ci    文件:FindNullDeref.java   
private void reportNullDeref(ClassContext classContext, Method method, InstructionHandle exceptionThrowerHandle,
                             String type, int priority) {
    MethodGen methodGen = classContext.getMethodGen(method);
    String sourceFile = classContext.getJavaClass().getSourceFileName();

    BugInstance bugInstance = new BugInstance(this, type, priority)
            .addClassAndMethod(methodGen, sourceFile)
            .addSourceLine(methodGen, sourceFile, exceptionThrowerHandle);

    if (DEBUG)
        bugInstance.addInt(exceptionThrowerHandle.getPosition()).describe("INT_BYTECODE_OFFSET");

    bugReporter.reportBug(bugInstance);
}
项目:parabuild-ci    文件:FindNullDeref.java   
private void reportRedundantNullCheck(ClassContext classContext, Method method, InstructionHandle handle,
                                      RedundantBranch redundantBranch) {
    String sourceFile = classContext.getJavaClass().getSourceFileName();
    MethodGen methodGen = classContext.getMethodGen(method);

    boolean redundantNullCheck = redundantBranch.redundantNullCheck;
    String type = redundantNullCheck
            ? "RCN_REDUNDANT_CHECKED_NULL_COMPARISION"
            : "RCN_REDUNDANT_COMPARISON_TO_NULL";
    int priority = redundantNullCheck ? LOW_PRIORITY : NORMAL_PRIORITY;

    bugReporter.reportBug(new BugInstance(this, type, priority)
            .addClassAndMethod(methodGen, sourceFile)
            .addSourceLine(methodGen, sourceFile, handle));
}
项目:parabuild-ci    文件:BugInstance.java   
/**
 * Add a method annotation for the method which is called by given
 * instruction.
 *
 * @param methodGen the method containing the call
 * @param inv       the InvokeInstruction
 * @return this object
 */
public BugInstance addCalledMethod(MethodGen methodGen, InvokeInstruction inv) {
    ConstantPoolGen cpg = methodGen.getConstantPool();
    String className = inv.getClassName(cpg);
    String methodName = inv.getMethodName(cpg);
    String methodSig = inv.getSignature(cpg);
    addMethod(className, methodName, methodSig);
    describe("METHOD_CALLED");
    return this;
}
项目:parabuild-ci    文件:BugInstance.java   
/**
 * Add a source line annotation describing a range of instructions.
 *
 * @param methodGen  the method
 * @param sourceFile source file the method is defined in
 * @param start      the start instruction in the range
 * @param end        the end instruction in the range (inclusive)
 * @return this object
 */
public BugInstance addSourceLine(MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) {
    // Make sure start and end are really in the right order.
    if (start.getPosition() > end.getPosition()) {
        InstructionHandle tmp = start;
        start = end;
        end = tmp;
    }
    SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstructionRange(methodGen, sourceFile, start, end);
    if (sourceLineAnnotation != null)
        add(sourceLineAnnotation);
    return this;
}
项目:parabuild-ci    文件:OtherLockCountAnalysis.java   
public static void main(String[] argv) {
    try {
        if (argv.length != 1) {
            System.out.println("edu.umd.cs.findbugs.ba.OtherLockCountAnalysis <filename>");
            System.exit(1);
        }

        DataflowTestDriver<LockCount, LockCountAnalysis> driver = new DataflowTestDriver<LockCount, LockCountAnalysis>() {
            public Dataflow<LockCount, LockCountAnalysis> createDataflow(ClassContext classContext, Method method)
                    throws CFGBuilderException, DataflowAnalysisException {

                MethodGen methodGen = classContext.getMethodGen(method);
                CFG cfg = classContext.getCFG(method);
                DepthFirstSearch dfs = classContext.getDepthFirstSearch(method);
                ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);

                LockCountAnalysis analysis = new OtherLockCountAnalysis(methodGen, vnaDataflow, dfs);
                Dataflow<LockCount, LockCountAnalysis> dataflow = new Dataflow<LockCount, LockCountAnalysis>(cfg, analysis);
                dataflow.execute();
                return dataflow;
            }
        };

        driver.execute(argv[0]);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:parabuild-ci    文件:ClassContext.java   
protected ValueNumberDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {
    MethodGen methodGen = getMethodGen(method);
    DepthFirstSearch dfs = getDepthFirstSearch(method);
    LoadedFieldSet loadedFieldSet = getLoadedFieldSet(method);
    ValueNumberAnalysis analysis = new ValueNumberAnalysis(methodGen, dfs, loadedFieldSet,
getLookupFailureCallback());
    CFG cfg = getCFG(method);
    ValueNumberDataflow vnaDataflow = new ValueNumberDataflow(cfg, analysis);
    vnaDataflow.execute();
    return vnaDataflow;
   }
项目:parabuild-ci    文件:ClassContext.java   
protected IsNullValueDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {
 MethodGen methodGen = getMethodGen(method);
 CFG cfg = getCFG(method);
 ValueNumberDataflow vnaDataflow = getValueNumberDataflow(method);
 DepthFirstSearch dfs = getDepthFirstSearch(method);
 AssertionMethods assertionMethods = getAssertionMethods();

 IsNullValueAnalysis invAnalysis = new IsNullValueAnalysis(methodGen, cfg, vnaDataflow, dfs, assertionMethods);
 IsNullValueDataflow invDataflow = new IsNullValueDataflow(cfg, invAnalysis);
 invDataflow.execute();
 return invDataflow;
}
项目:parabuild-ci    文件:ClassContext.java   
protected TypeDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {
 MethodGen methodGen = getMethodGen(method);
 CFG cfg = getRawCFG(method);
 DepthFirstSearch dfs = getDepthFirstSearch(method);
 ExceptionSetFactory exceptionSetFactory = getExceptionSetFactory(method);

 TypeAnalysis typeAnalysis =
         new TypeAnalysis(methodGen, cfg, dfs, getLookupFailureCallback(), exceptionSetFactory);
 TypeDataflow typeDataflow = new TypeDataflow(cfg, typeAnalysis);
 typeDataflow.execute();

 return typeDataflow;
}
项目:parabuild-ci    文件:ClassContext.java   
protected LockDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {
 MethodGen methodGen = getMethodGen(method);
 ValueNumberDataflow vnaDataflow = getValueNumberDataflow(method);
 DepthFirstSearch dfs = getDepthFirstSearch(method);
 CFG cfg = getCFG(method);

 LockAnalysis analysis = new LockAnalysis(methodGen, vnaDataflow, dfs);
 LockDataflow dataflow = new LockDataflow(cfg, analysis);
 dataflow.execute();
 return dataflow;
}
项目:parabuild-ci    文件:ClassContext.java   
protected LiveLocalStoreDataflow analyze(Method method)
    throws DataflowAnalysisException, CFGBuilderException {
        CFG cfg = getCFG(method);
        MethodGen methodGen = getMethodGen(method);
        ReverseDepthFirstSearch rdfs = getReverseDepthFirstSearch(method);

        LiveLocalStoreAnalysis analysis = new LiveLocalStoreAnalysis(methodGen, rdfs);
        LiveLocalStoreDataflow dataflow = new LiveLocalStoreDataflow(cfg, analysis);

        dataflow.execute();

        return dataflow;
}
项目:parabuild-ci    文件:ValueNumberAnalysis.java   
public ValueNumberAnalysis(MethodGen methodGen, DepthFirstSearch dfs,
                           LoadedFieldSet loadedFieldSet,
                           RepositoryLookupFailureCallback lookupFailureCallback) {

    super(dfs);
    this.methodGen = methodGen;
    this.factory = new ValueNumberFactory();
    this.cache = new ValueNumberCache();
    this.visitor = new ValueNumberFrameModelingVisitor(methodGen, factory, cache,
            loadedFieldSet,
            lookupFailureCallback);

    int numLocals = methodGen.getMaxLocals();
    this.entryLocalValueList = new ValueNumber[numLocals];
    for (int i = 0; i < numLocals; ++i)
        this.entryLocalValueList[i] = factory.createFreshValue();

    this.exceptionHandlerValueNumberMap = new IdentityHashMap<BasicBlock, ValueNumber>();

    // For non-static methods, keep track of which value represents the
    // "this" reference
    if (!methodGen.isStatic())
        this.thisValue = entryLocalValueList[0];

    this.factAtLocationMap = new HashMap<Location, ValueNumberFrame>();
    this.factAfterLocationMap = new HashMap<Location, ValueNumberFrame>();
}
项目:parabuild-ci    文件:DataflowTestDriver.java   
/**
 * Execute the analysis on a single class.
 *
 * @param filename the name of the class file
 */
public void execute(String filename) throws DataflowAnalysisException, CFGBuilderException, IOException {
    JavaClass jclass = new RepositoryClassParser(filename).parse();

    final RepositoryLookupFailureCallback lookupFailureCallback = new RepositoryLookupFailureCallback() {
        public void reportMissingClass(ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }
    };

    AnalysisContext analysisContext = new AnalysisContext(lookupFailureCallback);

    ClassContext classContext = analysisContext.getClassContext(jclass);
    String methodName = System.getProperty("dataflow.method");

    Method[] methods = jclass.getMethods();
    for (int i = 0; i < methods.length; ++i) {
        Method method = methods[i];
        if (methodName != null && !method.getName().equals(methodName))
            continue;

        MethodGen methodGen = classContext.getMethodGen(method);
        if (methodGen == null)
            continue;

        System.out.println("-----------------------------------------------------------------");
        System.out.println("Method: " + SignatureConverter.convertMethodSignature(methodGen));
        System.out.println("-----------------------------------------------------------------");

        execute(classContext, method);
    }
}
项目:parabuild-ci    文件:PruneUnconditionalExceptionThrowerEdges.java   
public PruneUnconditionalExceptionThrowerEdges(MethodGen methodGen, CFG cfg, ConstantPoolGen cpg,
                                               AnalysisContext analysisContext) {
    this.methodGen = methodGen;
    this.cfg = cfg;
    this.cpg = cpg;
    this.analysisContext = analysisContext;
}