当前位置: 首页>>代码示例>>Java>>正文


Java ClassContext.getTypeDataflow方法代码示例

本文整理汇总了Java中edu.umd.cs.findbugs.ba.ClassContext.getTypeDataflow方法的典型用法代码示例。如果您正苦于以下问题:Java ClassContext.getTypeDataflow方法的具体用法?Java ClassContext.getTypeDataflow怎么用?Java ClassContext.getTypeDataflow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.umd.cs.findbugs.ba.ClassContext的用法示例。


在下文中一共展示了ClassContext.getTypeDataflow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: analyzeMethod

import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
    MethodGen methodGen = classContext.getMethodGen(method);
    if (methodGen == null)
        return;
    BitSet bytecodeSet = classContext.getBytecodeSet(method);
    if (bytecodeSet == null)
        return;
    // We don't adequately model instanceof interfaces yet
    if (bytecodeSet.get(Constants.INSTANCEOF) || bytecodeSet.get(Constants.CHECKCAST))
        return;
    CFG cfg = classContext.getCFG(method);
    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
    ConstantPoolGen cpg = classContext.getConstantPoolGen();

    String sourceFile = classContext.getJavaClass().getSourceFileName();
    if (DEBUG) {
        String methodName = methodGen.getClassName() + "." + methodGen.getName();
        System.out.println("Checking " + methodName);
    }

    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
        Location location = i.next();
        InstructionHandle handle = location.getHandle();
        Instruction ins = handle.getInstruction();

        if (!(ins instanceof INVOKEINTERFACE))
            continue;

        INVOKEINTERFACE invoke = (INVOKEINTERFACE) ins;
        String mName = invoke.getMethodName(cpg);
        if (!mName.equals("setAttribute"))
            continue;
        String cName = invoke.getClassName(cpg);
        if (!cName.equals("javax.servlet.http.HttpSession"))
            continue;

        TypeFrame frame = typeDataflow.getFactAtLocation(location);
        if (!frame.isValid()) {
            // This basic block is probably dead
            continue;
        }
        Type operandType = frame.getTopValue();

        if (operandType.equals(TopType.instance())) {
            // unreachable
            continue;
        }
        if (!(operandType instanceof ReferenceType)) {
            // Shouldn't happen - illegal bytecode
            continue;
        }
        ReferenceType refType = (ReferenceType) operandType;

        if (refType.equals(NullType.instance())) {
            continue;
        }

        try {

            double isSerializable = DeepSubtypeAnalysis.isDeepSerializable(refType);

            if (isSerializable < 0.9) {
                SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext,
                        methodGen, sourceFile, handle);
                ReferenceType problem = DeepSubtypeAnalysis.getLeastSerializableTypeComponent(refType);

                bugAccumulator.accumulateBug(new BugInstance(this, "J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION",
                        isSerializable < 0.15 ? HIGH_PRIORITY : isSerializable > 0.5 ? LOW_PRIORITY : NORMAL_PRIORITY)
                        .addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE),
                        sourceLineAnnotation);

            }
        } catch (ClassNotFoundException e) {
            // ignore
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:78,代码来源:FindNonSerializableStoreIntoSession.java

示例2: analyzeMethod

import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
    if (method.isSynthetic() || (method.getAccessFlags() & Constants.ACC_BRIDGE) == Constants.ACC_BRIDGE)
        return;
    CFG cfg = classContext.getCFG(method);

    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);

    for (Iterator<BasicBlock> i = cfg.blockIterator(); i.hasNext();) {
        BasicBlock basicBlock = i.next();

        // Check if it's a method invocation.
        if (!basicBlock.isExceptionThrower())
            continue;
        InstructionHandle thrower = basicBlock.getExceptionThrower();
        Instruction ins = thrower.getInstruction();
        if (!(ins instanceof InvokeInstruction))
            continue;

        InvokeInstruction inv = (InvokeInstruction) ins;
        boolean foundThrower = false;
        boolean foundNonThrower = false;

        if (inv instanceof INVOKEINTERFACE)
            continue;

        String className = inv.getClassName(cpg);

        Location loc = new Location(thrower, basicBlock);
        TypeFrame typeFrame = typeDataflow.getFactAtLocation(loc);
        XMethod primaryXMethod = XFactory.createXMethod(inv, cpg);
        // if (primaryXMethod.isAbstract()) continue;
        Set<XMethod> targetSet = null;
        try {

            if (className.startsWith("["))
                continue;
            String methodSig = inv.getSignature(cpg);
            if (!methodSig.endsWith("V"))
                continue;

            targetSet = Hierarchy2.resolveMethodCallTargets(inv, typeFrame, cpg);

            for (XMethod xMethod : targetSet) {
                if (DEBUG)
                    System.out.println("\tFound " + xMethod);

                boolean isUnconditionalThrower = xMethod.isUnconditionalThrower() && !xMethod.isUnsupported()
                        && !xMethod.isSynthetic();
                if (isUnconditionalThrower) {
                    foundThrower = true;
                    if (DEBUG)
                        System.out.println("Found thrower");
                } else {
                    foundNonThrower = true;
                    if (DEBUG)
                        System.out.println("Found non thrower");
                }

            }
        } catch (ClassNotFoundException e) {
            analysisContext.getLookupFailureCallback().reportMissingClass(e);
        }
        boolean newResult = foundThrower && !foundNonThrower;
        if (newResult)
            bugReporter.reportBug(new BugInstance(this, "TESTING", Priorities.NORMAL_PRIORITY)
                    .addClassAndMethod(classContext.getJavaClass(), method)
                    .addString("Call to method that always throws Exception").addMethod(primaryXMethod)
                    .describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, loc));

    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:74,代码来源:CallToUnconditionalThrower.java

示例3: analyzeMethod

import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
    if (BCELUtil.isSynthetic(method) || (method.getAccessFlags() & Constants.ACC_BRIDGE) == Constants.ACC_BRIDGE)
        return;
    CFG cfg = classContext.getCFG(method);

    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);

    for (Iterator<BasicBlock> i = cfg.blockIterator(); i.hasNext();) {
        BasicBlock basicBlock = i.next();

        // Check if it's a method invocation.
        if (!basicBlock.isExceptionThrower())
            continue;
        InstructionHandle thrower = basicBlock.getExceptionThrower();
        Instruction ins = thrower.getInstruction();
        if (!(ins instanceof InvokeInstruction))
            continue;

        InvokeInstruction inv = (InvokeInstruction) ins;
        boolean foundThrower = false;
        boolean foundNonThrower = false;

        if (inv instanceof INVOKEINTERFACE)
            continue;

        String className = inv.getClassName(cpg);

        Location loc = new Location(thrower, basicBlock);
        TypeFrame typeFrame = typeDataflow.getFactAtLocation(loc);
        XMethod primaryXMethod = XFactory.createXMethod(inv, cpg);
        // if (primaryXMethod.isAbstract()) continue;
        Set<XMethod> targetSet = null;
        try {

            if (className.startsWith("["))
                continue;
            String methodSig = inv.getSignature(cpg);
            if (!methodSig.endsWith("V"))
                continue;

            targetSet = Hierarchy2.resolveMethodCallTargets(inv, typeFrame, cpg);

            for (XMethod xMethod : targetSet) {
                if (DEBUG)
                    System.out.println("\tFound " + xMethod);

                boolean isUnconditionalThrower = xMethod.isUnconditionalThrower() && !xMethod.isUnsupported()
                        && !xMethod.isSynthetic();
                if (isUnconditionalThrower) {
                    foundThrower = true;
                    if (DEBUG)
                        System.out.println("Found thrower");
                } else {
                    foundNonThrower = true;
                    if (DEBUG)
                        System.out.println("Found non thrower");
                }

            }
        } catch (ClassNotFoundException e) {
            analysisContext.getLookupFailureCallback().reportMissingClass(e);
        }
        boolean newResult = foundThrower && !foundNonThrower;
        if (newResult)
            bugReporter.reportBug(new BugInstance(this, "TESTING", Priorities.NORMAL_PRIORITY)
                    .addClassAndMethod(classContext.getJavaClass(), method)
                    .addString("Call to method that always throws Exception").addMethod(primaryXMethod)
                    .describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, loc));

    }

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:74,代码来源:CallToUnconditionalThrower.java


注:本文中的edu.umd.cs.findbugs.ba.ClassContext.getTypeDataflow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。