Examples of INullnessAnnotationDatabase


Examples of edu.umd.cs.findbugs.ba.INullnessAnnotationDatabase

            return;
        }

        XMethod m = XFactory.createXMethod(invokeInstruction, cpg);

        INullnessAnnotationDatabase db = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();
        SignatureParser sigParser = new SignatureParser(invokeInstruction.getSignature(cpg));
        for (int i = nullArgSet.nextSetBit(0); i >= 0; i = nullArgSet.nextSetBit(i + 1)) {

            if (db.parameterMustBeNonNull(m, i)) {
                boolean definitelyNull = definitelyNullArgSet.get(i);
                if (DEBUG_NULLARG) {
                    System.out.println("Checking " + m);
                    System.out.println("QQQ2: " + i + " -- " + i + " is null");
                    System.out.println("QQQ nullArgSet: " + nullArgSet);
View Full Code Here

Examples of edu.umd.cs.findbugs.ba.INullnessAnnotationDatabase

            int numLocals = methodGen.getMaxLocals();
            boolean instanceMethod = !methodGen.isStatic();
            XMethod xm = XFactory.createXMethod(methodGen.getClassName(), methodGen.getName(), methodGen.getSignature(),
                    methodGen.isStatic());
            INullnessAnnotationDatabase db = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();
            int paramShift = instanceMethod ? 1 : 0;
            Type[] argumentTypes = methodGen.getArgumentTypes();
            for (int i = 0; i < numLocals; ++i) {
                cachedEntryFact.setValue(i, IsNullValue.nonReportingNotNullValue());
            }
            if (paramShift == 1) {
                cachedEntryFact.setValue(0, IsNullValue.nonNullValue());
            }

            int slot = paramShift;
            for (int paramIndex = 0; paramIndex < argumentTypes.length; paramIndex++) {
                IsNullValue value;

                XMethodParameter methodParameter = new XMethodParameter(xm, paramIndex);
                NullnessAnnotation n = db.getResolvedAnnotation(methodParameter, false);
                if (n == NullnessAnnotation.CHECK_FOR_NULL) {
                    // Parameter declared @CheckForNull
                    value = IsNullValue.parameterMarkedAsMightBeNull(methodParameter);
                } else if (n == NullnessAnnotation.NONNULL) {
                    // Parameter declared @NonNull
View Full Code Here

Examples of edu.umd.cs.findbugs.ba.INullnessAnnotationDatabase

            CFG cfg = classContext.getCFG(method);

            ValueNumberDataflow vna = classContext.getValueNumberDataflow(method);
            TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
            INullnessAnnotationDatabase db = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();

            ParameterNullnessPropertyDatabase unconditionalDerefParamDatabase = AnalysisContext.currentAnalysisContext()
                    .getUnconditionalDerefParamDatabase();
            Iterator<BasicBlock> bbIter = cfg.blockIterator();
            ConstantPoolGen cpg = classContext.getConstantPoolGen();
            ValueNumber valueNumberForThis = null;
            if (!method.isStatic()) {
                ValueNumberFrame frameAtEntry = vna.getStartFact(cfg.getEntry());
                valueNumberForThis = frameAtEntry.getValue(0);
            }

            NullnessAnnotation methodAnnotation = getMethodNullnessAnnotation(classContext, method);

            while (bbIter.hasNext()) {
                BasicBlock basicBlock = bbIter.next();

                if (basicBlock.isNullCheck()) {
                    InstructionHandle exceptionThrowerHandle = basicBlock.getExceptionThrower();
                    Instruction exceptionThrower = exceptionThrowerHandle.getInstruction();
                    ValueNumberFrame vnaFrame = vna.getStartFact(basicBlock);
                    if (!vnaFrame.isValid()) {
                        continue;
                    }
                    ValueNumber valueNumber = vnaFrame.getInstance(exceptionThrower, cpg);

                    Location location = new Location(exceptionThrowerHandle, basicBlock);
                    if (valueNumberForThis != valueNumber) {
                        derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getPointerDereference());
                    }

                }
            }

            for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
                Location location = i.next();
                InstructionHandle handle = location.getHandle();
                Instruction ins = handle.getInstruction();
                ValueNumberFrame valueNumberFrame = vna.getFactAtLocation(location);
                TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
                if (ins instanceof InvokeInstruction) {
                    InvokeInstruction inv = (InvokeInstruction) ins;
                    XMethod m = XFactory.createXMethod(inv, cpg);
                    SignatureParser sigParser = new SignatureParser(m.getSignature());
                    int numParams = sigParser.getNumParameters();

                    // Check nonnull annotations

                    for (int j = 0; j < numParams; j++) {
                        if (db.parameterMustBeNonNull(m, j)) {
                            int slot = sigParser.getSlotsFromTopOfStackForParameter(j);
                            ValueNumber valueNumber = valueNumberFrame.getStackValue(slot);
                            if (valueNumberForThis != valueNumber) {
                                derefs.add(location, valueNumber,
                                        PointerUsageRequiringNonNullValue.getPassedAsNonNullParameter(m, j));
View Full Code Here

Examples of edu.umd.cs.findbugs.ba.INullnessAnnotationDatabase

     *
     * @throws DataflowAnalysisException
     */
    private void checkNonNullReturnValue(XMethod thisMethod, Location location, ValueNumberFrame vnaFrame,
            UnconditionalValueDerefSet fact) throws DataflowAnalysisException {
        INullnessAnnotationDatabase database = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();

        if (database.getResolvedAnnotation(thisMethod, true) != NullnessAnnotation.NONNULL) {
            return;
        }
        if (reportPotentialDereference(location, invDataflow.getFactAtLocation(location))) {
            ValueNumber vn = vnaFrame.getTopValue();
            fact.addDeref(vn, location);
View Full Code Here

Examples of edu.umd.cs.findbugs.ba.INullnessAnnotationDatabase

     *            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;
            }
View Full Code Here

Examples of edu.umd.cs.findbugs.ba.INullnessAnnotationDatabase

            @CheckForNull Method method, @CheckForNull IsNullValueFrame invFrame) throws DataflowAnalysisException {

        if (invFrame != null && !invFrame.isValid()) {
            return Collections.emptySet();
        }
        INullnessAnnotationDatabase database = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();

        InvokeInstruction inv = (InvokeInstruction) location.getHandle().getInstruction();
        XMethod called = XFactory.createXMethod(inv, constantPool);
        SignatureParser sigParser = new SignatureParser(called.getSignature());
        int numParams = sigParser.getNumParameters();

        Set<ValueNumber> result = new HashSet<ValueNumber>();
        Iterator<String> parameterIterator = sigParser.parameterSignatureIterator();
        for (int i = 0; i < numParams; i++) {
            String parameterSignature = parameterIterator.next();
            char firstChar = parameterSignature.charAt(0);
            if (firstChar != 'L' && firstChar != '[') {
                continue;
            }
            int offset = sigParser.getSlotsFromTopOfStackForParameter(i);
            if (invFrame != null) {
                int slot = invFrame.getStackLocation(offset);
                if (!reportDereference(invFrame, slot)) {
                    continue;
                }
            }
            if (database.parameterMustBeNonNull(called, i)) {
                int catchSizeNPE = Util.getSizeOfSurroundingTryBlock(method, "java/lang/NullPointerException", location
                        .getHandle().getPosition());
                int catchSizeNFE = Util.getSizeOfSurroundingTryBlock(method, "java/lang/NumberFormatException", location
                        .getHandle().getPosition());
                if (catchSizeNPE == Integer.MAX_VALUE
View Full Code Here

Examples of edu.umd.cs.findbugs.ba.INullnessAnnotationDatabase

        bugAccumulator.reportAccumulatedBugs();
    }

    private boolean isExplicitlyNullable() {
        AnalysisContext analysisContext = AnalysisContext.currentAnalysisContext();
        INullnessAnnotationDatabase nullnessAnnotationDatabase = analysisContext.getNullnessAnnotationDatabase();
        XMethod xMethod = getXMethod();
        NullnessAnnotation na = nullnessAnnotationDatabase.getResolvedAnnotation(xMethod, true);
        return na != null && na != NullnessAnnotation.NONNULL;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.