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


Java SourceLineAnnotation.fromVisitedInstruction方法代码示例

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


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

示例1: sawOpcode

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
@Override
public void sawOpcode(int seen) {

    switch (seen) {
    case ACONST_NULL:
        nullOnTOS = true;
        return;
    case ARETURN:
        if (nullOnTOS) {
            SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this,
                    getPC());
            if (sourceLineAnnotation != null)
                found.add(sourceLineAnnotation);
        }

        break;
    }
    nullOnTOS = false;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:20,代码来源:PreferZeroLengthArrays.java

示例2: visit

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
@Override
public void visit(LocalVariable obj) {
    if (isReservedName(obj.getName())) {
        LocalVariableAnnotation var = new LocalVariableAnnotation(obj.getName(), obj.getIndex(), obj.getStartPC());
        SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, obj.getStartPC());
        BugInstance bug = new BugInstance(this, "NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER", NORMAL_PRIORITY)
                .addClassAndMethod(this).add(var).add(source);
        bugReporter.reportBug(bug);
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:11,代码来源:DontUseEnum.java

示例3: sawOpcode

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
@Override
public void sawOpcode(int seen) {

    if (DEBUG)
        System.out.println("Saw opcode " + OPCODE_NAMES[seen] + " " + pendingIdivCastToDivBugLocation);

    if ((prevOpCode == I2D || prevOpCode == L2D) && seen == INVOKESTATIC && ClassName.isMathClass(getClassConstantOperand())
            && getNameConstantOperand().equals("ceil")) {
        bugAccumulator
                .accumulateBug(new BugInstance(this, "ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL", HIGH_PRIORITY)
                        .addClassAndMethod(this), this);
        pendingIdivCastToDivBugLocation = null;
    } else if ((prevOpCode == I2F || prevOpCode == L2F) && seen == INVOKESTATIC
            && ClassName.isMathClass(getClassConstantOperand()) && getNameConstantOperand().equals("round")) {
        bugAccumulator.accumulateBug(
                new BugInstance(this, "ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND", NORMAL_PRIORITY).addClassAndMethod(this),
                this);
        pendingIdivCastToDivBugLocation = null;
    } else if (pendingIdivCastToDivBugLocation != null) {
        bugAccumulator.accumulateBug(
                new BugInstance(this, "ICAST_IDIV_CAST_TO_DOUBLE", NORMAL_PRIORITY).addClassAndMethod(this),
                pendingIdivCastToDivBugLocation);
        pendingIdivCastToDivBugLocation = null;
    }

    if (prevOpCode == IDIV && (seen == I2D || seen == I2F) || prevOpCode == LDIV && (seen == L2D || seen == L2F))
        pendingIdivCastToDivBugLocation = SourceLineAnnotation.fromVisitedInstruction(this);
    prevOpCode = seen;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:30,代码来源:IDivResultCastToDouble.java

示例4: handleSuspiciousRefComparison

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
private void handleSuspiciousRefComparison(JavaClass jclass, Method method, MethodGen methodGen,
        List<WarningWithProperties> refComparisonList, Location location, String lhs, ReferenceType lhsType,
        ReferenceType rhsType) {
    XField xf = null;
    if (lhsType instanceof FinalConstant)
        xf = ((FinalConstant) lhsType).getXField();
    else if (rhsType instanceof FinalConstant)
        xf = ((FinalConstant) rhsType).getXField();
    String sourceFile = jclass.getSourceFileName();
    String bugPattern = "RC_REF_COMPARISON";
    int priority = Priorities.HIGH_PRIORITY;
    if (lhs.equals("java.lang.Boolean")) {
        bugPattern = "RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN";
        priority = Priorities.NORMAL_PRIORITY;
    } else if (xf != null && xf.isStatic() && xf.isFinal()) {
        bugPattern = "RC_REF_COMPARISON_BAD_PRACTICE";
        if (xf.isPublic() || !methodGen.isPublic())
            priority = Priorities.NORMAL_PRIORITY;
    }
    BugInstance instance = new BugInstance(this, bugPattern, priority).addClassAndMethod(methodGen, sourceFile)
            .addType("L" + lhs.replace('.', '/') + ";").describe(TypeAnnotation.FOUND_ROLE);
    if (xf != null)
        instance.addField(xf).describe(FieldAnnotation.LOADED_FROM_ROLE);
    else
        instance.addSomeSourceForTopTwoStackValues(classContext, method, location);
    SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
            sourceFile, location.getHandle());
    if (sourceLineAnnotation != null)
        refComparisonList.add(new WarningWithProperties(instance, new WarningPropertySet<WarningProperty>(),
                sourceLineAnnotation, location));
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:32,代码来源:FindRefComparison.java

示例5: checkForSelfOperation

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
/**
 * @param classContext
 *            TODO
 * @param location
 * @param method
 *            TODO
 * @param methodGen
 *            TODO
 * @param sourceFile
 *            TODO
 * @param string
 * @throws DataflowAnalysisException
 */
private void checkForSelfOperation(ClassContext classContext, Location location, ValueNumberDataflow valueNumberDataflow,
        String op, Method method, MethodGen methodGen, String sourceFile) throws DataflowAnalysisException {
    ValueNumberFrame frame = valueNumberDataflow.getFactAtLocation(location);
    if (!frame.isValid())
        return;
    Instruction ins = location.getHandle().getInstruction();
    int opcode = ins.getOpcode();
    int offset = 1;
    if (opcode == LCMP || opcode == LXOR || opcode == LAND || opcode == LOR || opcode == LSUB)
        offset = 2;
    ValueNumber v0 = frame.getStackValue(0);
    ValueNumber v1 = frame.getStackValue(offset);
    if (!v1.equals(v0))
        return;
    if (v0.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT) || v0.hasFlag(ValueNumber.CONSTANT_VALUE))
        return;

    int priority = HIGH_PRIORITY;
    if (opcode == ISUB || opcode == LSUB || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL)
        priority = NORMAL_PRIORITY;
    XField field = ValueNumberSourceInfo.findXFieldFromValueNumber(method, location, v0, frame);
    BugAnnotation annotation;
    String prefix;
    if (field != null) {
        if (field.isVolatile())
            return;
        if (true)
            return; // don't report these; too many false positives
        annotation = FieldAnnotation.fromXField(field);
        prefix = "SA_FIELD_SELF_";
    } else {
        annotation = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method, location, v0, frame);
        prefix = "SA_LOCAL_SELF_";
        if (opcode == ISUB)
            return; // only report this if simple detector reports it
    }
    if (annotation == null)
        return;
    SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile,
            location.getHandle());
    int line = sourceLine.getStartLine();
    BitSet occursMultipleTimes = classContext.linesMentionedMultipleTimes(method);
    if (line > 0 && occursMultipleTimes.get(line))
        return;
    BugInstance bug = new BugInstance(this, prefix + op, priority).addClassAndMethod(methodGen, sourceFile).add(annotation)
            .addSourceLine(classContext, methodGen, sourceFile, location.getHandle());
    bugReporter.reportBug(bug);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:62,代码来源:FindSelfComparison2.java

示例6: analyzeMethod

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的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

示例7: sawOpcode

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
@Override
public void sawOpcode(int seen) {
    switch (seen) {
    case FCMPG:
    case FCMPL:
    case DCMPG:
    case DCMPL:
        if (stack.getStackDepth() >= 2) {
            OpcodeStack.Item first = stack.getStackItem(0);
            OpcodeStack.Item second = stack.getStackItem(1);      
                
            if (first.getRegisterNumber() == second.getRegisterNumber() && first.getRegisterNumber() != -1)
                break;
            if (first.isInitialParameter() && second.isInitialParameter())
                break;
            if (sameField(first, second))
                break;
        
            Number n1 = (Number) first.getConstant();
            Number n2 = (Number) second.getConstant();
            if (n1 != null && Double.isNaN(n1.doubleValue()) || n2 != null && Double.isNaN(n2.doubleValue())) {
                BugInstance bug = new BugInstance(this, "FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER", HIGH_PRIORITY)
                        .addClassAndMethod(this);
                bugAccumulator.accumulateBug(bug, this);
                state = SAW_NOTHING;
                break;
            }
            if (first.getSpecialKind() == OpcodeStack.Item.NASTY_FLOAT_MATH && !isZero(n2)
                    || second.getSpecialKind() == OpcodeStack.Item.NASTY_FLOAT_MATH && !isZero(n1)
                    || first.getSpecialKind() == OpcodeStack.Item.FLOAT_MATH && !okValueToCompareAgainst(n2)
                    || second.getSpecialKind() == OpcodeStack.Item.FLOAT_MATH && !okValueToCompareAgainst(n1)) {
                if (priority != HIGH_PRIORITY)
                    found.clear();
                priority = HIGH_PRIORITY;
                state = SAW_COMP;
                break;
            }
            if (priority == HIGH_PRIORITY)
                break;
            // if (first.isInitialParameter() && n2 != null) break;
            // if (second.isInitialParameter() && n1 != null) break;
              if (n1 != null && n2 != null)
                break;

            if (okValueToCompareAgainst(n1) || okValueToCompareAgainst(n2))
                break;
            if (n1 != null && !second.isInitialParameter() || n2 != null && !first.isInitialParameter()) {
                if (priority == LOW_PRIORITY)
                    found.clear();
                priority = NORMAL_PRIORITY;

            } else if (priority == NORMAL_PRIORITY)
                break;
            state = SAW_COMP;
        }
        break;

    case IFEQ:
    case IFNE:
        if (state == SAW_COMP) {
            SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this,
                    getPC());
            if (sourceLineAnnotation != null) {
                found.add(sourceLineAnnotation);
            }
        }
        state = SAW_NOTHING;
        break;

    default:
        state = SAW_NOTHING;
        break;
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:75,代码来源:FindFloatEquality.java

示例8: sawOpcode

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
@Override
public void sawOpcode(int seen) {
    // System.out.println("saw\t" + OPCODE_NAMES[seen] + "\t" + zeroOnTOS);
    switch (seen) {
    case GETSTATIC:
    case PUTSTATIC:

        XField xField = getXFieldOperand();
        if (xField == null) {
            break;
        }
        if (!interesting(xField)) {
            break;
        }

        boolean samePackage = packageName.equals(extractPackage(getClassConstantOperand()));
        boolean initOnly = seen == GETSTATIC || getClassName().equals(getClassConstantOperand()) && inStaticInitializer;
        boolean safeValue = seen == GETSTATIC || emptyArrayOnTOS
                || AnalysisContext.currentXFactory().isEmptyArrayField(xField) || !mutableSignature(getSigConstantOperand());

        if (seen == GETSTATIC) {
            readAnywhere.add(xField);
        }
        if (seen == PUTSTATIC) {
            if (!writtenInMethod.add(xField))
                writtenTwiceInMethod.add(xField);
        }

        if (!samePackage) {
            outsidePackage.add(xField);
        }

        if (!initOnly) {
            notFinal.add(xField);
        }

        if (!safeValue) {
            unsafeValue.add(xField);
        }

        // Remove inStaticInitializer check to report all source lines of
        // first use
        // doing so, however adds quite a bit of memory bloat.
        if (inStaticInitializer && !firstFieldUse.containsKey(xField)) {
            SourceLineAnnotation sla = SourceLineAnnotation.fromVisitedInstruction(this);
            firstFieldUse.put(xField, sla);
        }
        break;
    case ANEWARRAY:
    case NEWARRAY:
        if (zeroOnTOS) {
            emptyArrayOnTOS = true;
        }
        zeroOnTOS = false;
        return;
    case ICONST_0:
        zeroOnTOS = true;
        emptyArrayOnTOS = false;
        return;
    }
    zeroOnTOS = false;
    emptyArrayOnTOS = false;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:64,代码来源:MutableStaticFields.java

示例9: handleStringComparison

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
private void handleStringComparison(JavaClass jclass, Method method, MethodGen methodGen,
        RefComparisonTypeFrameModelingVisitor visitor, List<WarningWithProperties> stringComparisonList, Location location,
        Type lhsType, Type rhsType) {
    if (DEBUG) {
        System.out.println("String/String comparison at " + location.getHandle());
    }

    // Compute the priority:
    // - two static strings => do not report
    // - dynamic string and anything => high
    // - static string and unknown => medium
    // - all other cases => low
    // System.out.println("Compare " + lhsType + " == " + rhsType);
    byte type1 = lhsType.getType();
    byte type2 = rhsType.getType();

    String bugPattern = "ES_COMPARING_STRINGS_WITH_EQ";
    // T1 T2 result
    // S S no-op
    // D ? high
    // ? D high
    // S ? normal
    // ? S normal
    WarningPropertySet<WarningProperty> propertySet = new WarningPropertySet<WarningProperty>();
    if (type1 == T_STATIC_STRING && type2 == T_STATIC_STRING) {
        propertySet.addProperty(RefComparisonWarningProperty.COMPARE_STATIC_STRINGS);
    } else if (type1 == T_DYNAMIC_STRING || type2 == T_DYNAMIC_STRING) {
        propertySet.addProperty(RefComparisonWarningProperty.DYNAMIC_AND_UNKNOWN);
    } else if (type2 == T_PARAMETER_STRING || type1 == T_PARAMETER_STRING) {
        bugPattern = "ES_COMPARING_PARAMETER_STRING_WITH_EQ";
        if (methodGen.isPublic() || methodGen.isProtected()) {
            propertySet.addProperty(RefComparisonWarningProperty.STRING_PARAMETER_IN_PUBLIC_METHOD);
        } else {
            propertySet.addProperty(RefComparisonWarningProperty.STRING_PARAMETER);
        }
    } else if (type1 == T_STATIC_STRING || type2 == T_STATIC_STRING) {
        if (lhsType instanceof EmptyStringType || rhsType instanceof EmptyStringType)
            propertySet.addProperty(RefComparisonWarningProperty.EMPTY_AND_UNKNOWN);
        else
            propertySet.addProperty(RefComparisonWarningProperty.STATIC_AND_UNKNOWN);
    } else if (visitor.sawStringIntern()) {
        propertySet.addProperty(RefComparisonWarningProperty.SAW_INTERN);
    }

    String sourceFile = jclass.getSourceFileName();
    BugInstance instance = new BugInstance(this, bugPattern, BASE_ES_PRIORITY).addClassAndMethod(methodGen, sourceFile)
            .addType("Ljava/lang/String;").describe(TypeAnnotation.FOUND_ROLE).addSomeSourceForTopTwoStackValues(classContext, method, location);
    SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
            sourceFile, location.getHandle());
    if (sourceLineAnnotation != null) {
        WarningWithProperties warn = new WarningWithProperties(instance, propertySet, sourceLineAnnotation, location);
        stringComparisonList.add(warn);
    }

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

示例10: asSourceLineAnnotation

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
SourceLineAnnotation asSourceLineAnnotation() {
    return SourceLineAnnotation.fromVisitedInstruction(methodDescriptor, position);
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:4,代码来源:FindInconsistentSync2.java

示例11: emitDataflowWarning

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
private void emitDataflowWarning(XMethod xMethod, TypeQualifierValue typeQualifierValue,
        TypeQualifierValueSet forwardsFact, TypeQualifierValueSet backwardsFact, ValueNumber vn, FlowValue forward,
        FlowValue backward, Location locationToReport, @CheckForNull Location locationWhereDoomedValueIsObserved, ValueNumberFrame vnaFrame)
        throws CheckedAnalysisException {
    String bugType;
    if (typeQualifierValue.isStrictQualifier() && forward == FlowValue.UNKNOWN)
        bugType = "TQ_UNKNOWN_VALUE_USED_WHERE_ALWAYS_STRICTLY_REQUIRED";
    else if (backward == FlowValue.NEVER)
        bugType = "TQ_ALWAYS_VALUE_USED_WHERE_NEVER_REQUIRED";
    else
        bugType = "TQ_NEVER_VALUE_USED_WHERE_ALWAYS_REQUIRED";

    // Issue warning
    BugInstance warning = new BugInstance(this, bugType, Priorities.NORMAL_PRIORITY).addClassAndMethod(xMethod);
    annotateWarningWithTypeQualifier(warning, typeQualifierValue);

    Set<? extends SourceSinkInfo> sourceSet = (forward == FlowValue.ALWAYS) ? forwardsFact.getWhereAlways(vn) : forwardsFact
            .getWhereNever(vn);
    for (SourceSinkInfo source : sourceSet) {
        annotateWarningWithSourceSinkInfo(warning, xMethod, vn, source);
    }
    Set<? extends SourceSinkInfo> sinkSet = (backward == FlowValue.ALWAYS) ? backwardsFact.getWhereAlways(vn) : backwardsFact
            .getWhereNever(vn);

    Location sinkLocation = getSinkLocation(sinkSet);
    if (sinkLocation == null) {
        AnalysisContext.logError("Unable to compute sink location for " + xMethod);
        return;
    }

    // Hopefully we can find the conflicted value in a local variable
    if (locationWhereDoomedValueIsObserved != null) {
        Method method = Global.getAnalysisCache().getMethodAnalysis(Method.class, xMethod.getMethodDescriptor());

        LocalVariableAnnotation localVariable = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method,
                locationWhereDoomedValueIsObserved, vn, vnaFrame);
        if (localVariable != null && !localVariable.equals(warning.getPrimaryLocalVariableAnnotation())) {
            localVariable.setDescription(localVariable.isSignificant() ? "LOCAL_VARIABLE_VALUE_DOOMED_NAMED"
                    : "LOCAL_VARIABLE_VALUE_DOOMED");
            warning.add(localVariable);

        }
        if (!sinkLocation.equals(locationToReport)) {
            // Report where we observed the value.
            // Note that for conflicts detected on control edges,
            // we REPORT the edge source location
            // rather than the target location, even though it is the
            // target location where the conflict is detected.
            // The only reason to use a different reporting location
            // is to produce a more informative report for the user,
            // since the edge source is where the branch is found.
            SourceLineAnnotation observedLocation = SourceLineAnnotation.fromVisitedInstruction(xMethod.getMethodDescriptor(),
                    locationToReport);
            observedLocation.setDescription("SOURCE_LINE_VALUE_DOOMED");
            warning.add(observedLocation);
        }
    }

    // Add value sinks
    for (SourceSinkInfo sink : sinkSet) {
        annotateWarningWithSourceSinkInfo(warning, xMethod, vn, sink);
    }

    bugReporter.reportBug(warning);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:66,代码来源:CheckTypeQualifiers.java

示例12: checkForSelfOperation

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
/**
 * @param classContext
 *            TODO
 * @param location
 * @param method
 *            TODO
 * @param methodGen
 *            TODO
 * @param sourceFile
 *            TODO
 * @param string
 * @throws DataflowAnalysisException
 */
private void checkForSelfOperation(ClassContext classContext, Location location, ValueNumberDataflow valueNumberDataflow,
        String op, Method method, MethodGen methodGen, String sourceFile) throws DataflowAnalysisException {
    ValueNumberFrame frame = valueNumberDataflow.getFactAtLocation(location);
    if (!frame.isValid())
        return;
    Instruction ins = location.getHandle().getInstruction();
    int opcode = ins.getOpcode();
    int offset = 1;
    if (opcode == LCMP || opcode == LXOR || opcode == LAND || opcode == LOR || opcode == LSUB)
        offset = 2;
    ValueNumber v0 = frame.getStackValue(0);
    ValueNumber v1 = frame.getStackValue(offset);
    if (!v1.equals(v0))
        return;
    if (v0.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT) || v0.hasFlag(ValueNumber.CONSTANT_VALUE))
        return;

    int priority = HIGH_PRIORITY;
    if (opcode == ISUB || opcode == LSUB || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL)
        priority = NORMAL_PRIORITY;
    XField field = ValueNumberSourceInfo.findXFieldFromValueNumber(method, location, v0, frame);
    BugAnnotation annotation;
    String prefix;
    if (field != null) {
        if (field.isVolatile())
            return;
        if (true)
            return; // don't report these; too many false positives
        annotation = FieldAnnotation.fromXField(field);
        prefix = "SA_FIELD_SELF_";
    } else {
        annotation = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method, location, v0, frame);
        prefix = "SA_LOCAL_SELF_";
        if (opcode == ISUB)
            return; // only report this if simple detector reports it
    }
    if (annotation == null)
        return;
    SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile,
            location.getHandle());
    int line = sourceLine.getStartLine();
    BitSet occursMultipleTimes = classContext.linesMentionedMultipleTimes(method);
    if (line > 0 && occursMultipleTimes.get(line))
        return;
    BugInstance bug = new BugInstance(this, prefix + op, priority).addClassAndMethod(methodGen, sourceFile);
    if (ins instanceof InvokeInstruction)
        bug.addCalledMethod(classContext.getConstantPoolGen(), (InvokeInstruction) ins);

    bug.add(annotation)
            .addSourceLine(classContext, methodGen, sourceFile, location.getHandle());
    bugReporter.reportBug(bug);
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:66,代码来源:FindSelfComparison2.java


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