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


Java IsNullValue类代码示例

本文整理汇总了Java中edu.umd.cs.findbugs.ba.npe.IsNullValue的典型用法代码示例。如果您正苦于以下问题:Java IsNullValue类的具体用法?Java IsNullValue怎么用?Java IsNullValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IsNullValue类属于edu.umd.cs.findbugs.ba.npe包,在下文中一共展示了IsNullValue类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkNonNullPutField

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
/**
 * If this is a putfield or putstatic instruction, check to see if the field
 * is @NonNull, and treat it as dereferences.
 *
 * @param location
 *            the Location of the instruction
 * @param vnaFrame
 *            the ValueNumberFrame at the Location of the instruction
 * @param fact
 *            the dataflow value to modify
 * @throws DataflowAnalysisException
 */
private void checkNonNullPutField(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
        throws DataflowAnalysisException {
    INullnessAnnotationDatabase database = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();
    if (database == null) {
        return;
    }

    FieldInstruction fieldIns = (FieldInstruction) location.getHandle().getInstruction();

    XField field = XFactory.createXField(fieldIns, methodGen.getConstantPool());
    char firstChar = field.getSignature().charAt(0);
    if (firstChar != 'L' && firstChar != '[')
        return;
    NullnessAnnotation resolvedAnnotation = database.getResolvedAnnotation(field, true);
    if (resolvedAnnotation == NullnessAnnotation.NONNULL) {
        IsNullValueFrame invFrame = invDataflow.getFactAtLocation(location);
        if (!invFrame.isValid())
            return;
        IsNullValue value = invFrame.getTopValue();
        if (reportDereference(value)) {
            ValueNumber vn = vnaFrame.getTopValue();
            fact.addDeref(vn, location);
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:38,代码来源:UnconditionalValueDerefAnalysis.java

示例2: findValueKnownNonnullOnBranch

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
/**
 * Clear deref sets of values if this edge is the non-null branch of an if
 * comparison.
 *
 * @param fact
 *            a datflow fact
 * @param edge
 *            edge to check
 * @return possibly-modified dataflow fact
 */
private @CheckForNull
ValueNumber findValueKnownNonnullOnBranch(UnconditionalValueDerefSet fact, Edge edge) {

    IsNullValueFrame invFrame = invDataflow.getResultFact(edge.getSource());
    if (!invFrame.isValid()) {
        return null;
    }
    IsNullConditionDecision decision = invFrame.getDecision();
    if (decision == null) {
        return null;
    }

    IsNullValue inv = decision.getDecision(edge.getType());
    if (inv == null || !inv.isDefinitelyNotNull()) {
        return null;
    }
    ValueNumber value = decision.getValue();
    if (DEBUG) {
        System.out.println("Value number " + value + " is known nonnull on " + edge);
    }

    return value;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:34,代码来源:UnconditionalValueDerefAnalysis.java

示例3: checkNonNullPutField

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
/**
 * If this is a putfield or putstatic instruction, check to see if the field
 * is @NonNull, and treat it as dereferences.
 *
 * @param location
 *            the Location of the instruction
 * @param vnaFrame
 *            the ValueNumberFrame at the Location of the instruction
 * @param fact
 *            the dataflow value to modify
 * @throws DataflowAnalysisException
 */
private void checkNonNullPutField(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
        throws DataflowAnalysisException {
    INullnessAnnotationDatabase database = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();

    FieldInstruction fieldIns = (FieldInstruction) location.getHandle().getInstruction();

    XField field = XFactory.createXField(fieldIns, methodGen.getConstantPool());
    char firstChar = field.getSignature().charAt(0);
    if (firstChar != 'L' && firstChar != '[')
        return;
    NullnessAnnotation resolvedAnnotation = database.getResolvedAnnotation(field, true);
    if (resolvedAnnotation == NullnessAnnotation.NONNULL) {
        IsNullValueFrame invFrame = invDataflow.getFactAtLocation(location);
        if (!invFrame.isValid())
            return;
        IsNullValue value = invFrame.getTopValue();
        if (reportDereference(value)) {
            ValueNumber vn = vnaFrame.getTopValue();
            fact.addDeref(vn, location);
        }
    }
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:35,代码来源:UnconditionalValueDerefAnalysis.java

示例4: examineReturnInstruction

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
private void examineReturnInstruction(Location location) throws DataflowAnalysisException, CFGBuilderException {
    if (DEBUG_NULLRETURN) {
        System.out.println("Checking null return at " + location);
    }

    IsNullValueDataflow invDataflow = classContext.getIsNullValueDataflow(method);
    IsNullValueFrame frame = invDataflow.getFactAtLocation(location);
    ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location);
    if (!vnaFrame.isValid())
        return;
    ValueNumber valueNumber = vnaFrame.getTopValue();
    if (!frame.isValid())
        return;
    IsNullValue tos = frame.getTopValue();
    if (tos.isDefinitelyNull()) {
        BugAnnotation variable = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber, vnaFrame,
                "VALUE_OF");

        String bugPattern = "NP_NONNULL_RETURN_VIOLATION";
        int priority = NORMAL_PRIORITY;
        if (tos.isDefinitelyNull() && !tos.isException())
            priority = HIGH_PRIORITY;
        String methodName = method.getName();
        if (methodName.equals("clone")) {
            bugPattern = "NP_CLONE_COULD_RETURN_NULL";
            priority = NORMAL_PRIORITY;
        } else if (methodName.equals("toString")) {
            bugPattern = "NP_TOSTRING_COULD_RETURN_NULL";
            priority = NORMAL_PRIORITY;
        }
        BugInstance warning = new BugInstance(this, bugPattern, priority).addClassAndMethod(classContext.getJavaClass(),
                method).addOptionalAnnotation(variable);
        bugAccumulator.accumulateBug(warning, SourceLineAnnotation.fromVisitedInstruction(classContext, method, location));
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:36,代码来源:FindNullDeref.java

示例5: reportPotentialDereference

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
public static boolean reportPotentialDereference(Location location, IsNullValueFrame invFrame)
        throws DataflowAnalysisException {
    if (!invFrame.isValid())
        return false;
    IsNullValue value = invFrame.getTopValue();
    if (value.isDefinitelyNotNull())
        return false;
    if (value.isDefinitelyNull())
        return false;
    return true;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:12,代码来源:UnconditionalValueDerefAnalysis.java

示例6: reportDereference

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
private static boolean reportDereference(IsNullValue value) {
    if (value.isDefinitelyNotNull())
        return false;
    if (value.isDefinitelyNull())
        return false;
    if (IGNORE_DEREF_OF_NCP && value.isNullOnComplicatedPath())
        return false;
    return true;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:10,代码来源:UnconditionalValueDerefAnalysis.java

示例7: ignoreExceptionEdge

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
public boolean ignoreExceptionEdge(Edge edge, Lock resource, ConstantPoolGen cpg) {

            try {
                Location location = cfg.getExceptionThrowerLocation(edge);
                if (DEBUG) {
                    System.out.println("Exception thrower location: " + location);
                }
                Instruction ins = location.getHandle().getInstruction();

                if (ins instanceof GETFIELD) {
                    GETFIELD insGetfield = (GETFIELD) ins;
                    String fieldName = insGetfield.getFieldName(cpg);
                    if (DEBUG) {
                        System.out.println("Inspecting GETFIELD of " + fieldName + " at " + location);
                    }
                    // Ignore exceptions from getfield instructions where the
                    // object reference is known not to be null
                    if (fieldName.equals("lock"))
                        return true;
                    IsNullValueFrame frame = isNullDataflow.getFactAtLocation(location);
                    if (!frame.isValid())
                        return false;
                    IsNullValue receiver = frame.getInstance(ins, cpg);
                    boolean notNull = receiver.isDefinitelyNotNull();
                    if (DEBUG && notNull) {
                        System.out.println("Ignoring exception from non-null GETFIELD");
                    }
                    return notNull;
                } else if (ins instanceof InvokeInstruction) {
                    InvokeInstruction iins = (InvokeInstruction) ins;
                    String methodName = iins.getMethodName(cpg);
                    // System.out.println("Method " + methodName);
                    if (methodName.startsWith("access$"))
                        return true;
                    if (methodName.equals("readLock") || methodName.equals("writeLock"))
                        return true;
                    if (methodName.equals("lock") || methodName.equals("unlock"))
                        return true;
                }
                if (DEBUG) {
                    System.out.println("FOUND Exception thrower at: " + location);
                }
            } catch (DataflowAnalysisException e) {
                AnalysisContext.logError("Error while looking for exception edge", e);
            }

            return false;
        }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:49,代码来源:FindUnreleasedLock.java

示例8: foundNullDeref

import edu.umd.cs.findbugs.ba.npe.IsNullValue; //导入依赖的package包/类
/**
 * @deprecated Use
 *             {@link #foundNullDeref(Location,ValueNumber,IsNullValue,ValueNumberFrame,boolean)}
 *             instead
 */
@Deprecated
public void foundNullDeref(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame) {
    foundNullDeref(location, valueNumber, refValue, vnaFrame, true);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:10,代码来源:NoiseNullDeref.java


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