Package edu.umd.cs.findbugs.ba

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


        return c.size();
    }

    private JumpInfo getJumpInfo() {
        IAnalysisCache analysisCache = Global.getAnalysisCache();
        XMethod xMethod = XFactory.createXMethod(v.getThisClass(), v.getMethod());
        if (xMethod instanceof MethodInfo) {
            MethodInfo mi = (MethodInfo) xMethod;
            if (!mi.hasBackBranch()) {
                return null;
            }
        }
        try {
            return analysisCache.getMethodAnalysis(JumpInfo.class, xMethod.getMethodDescriptor());
        } catch (CheckedAnalysisException e) {
            AnalysisContext.logError("Error getting jump information", e);
            return null;
        }
    }
View Full Code Here


        return findImplementor(getXClass(superclassDescriptor), name, signature, isStatic);
    }

    public static XClass findImplementor(XClass clazz, String name, String signature, boolean isStatic)
            throws CheckedAnalysisException {
        XMethod m = clazz.findMethod(name, signature, isStatic);
        if (m != null) {
            return clazz;
        }
        return findSuperImplementor(clazz, name, signature, isStatic);
    }
View Full Code Here

        }
    }

    private void analyzeMethod(ClassContext classContext, Method method) {
        JavaClass jclass = classContext.getJavaClass();
        XMethod xmethod = XFactory.createXMethod(jclass, method);
        try {
            CFG cfg = classContext.getCFG(method);

            ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
            UnconditionalValueDerefDataflow dataflow = classContext.getUnconditionalValueDerefDataflow(method);

            SignatureParser parser = new SignatureParser(method.getSignature());
            int paramLocalOffset = method.isStatic() ? 0 : 1;

            // Build BitSet of params that are unconditionally dereferenced
            BitSet unconditionalDerefSet = new BitSet();
            UnconditionalValueDerefSet entryFact = dataflow.getResultFact(cfg.getEntry());
            Iterator<String> paramIterator = parser.parameterSignatureIterator();
            int i = 0;
            while (paramIterator.hasNext()) {
                String paramSig = paramIterator.next();

                ValueNumber paramVN = vnaDataflow.getAnalysis().getEntryValue(paramLocalOffset);

                handleParameter: if (entryFact.isUnconditionallyDereferenced(paramVN)) {
                    TypeQualifierAnnotation directTypeQualifierAnnotation = TypeQualifierApplications
                            .getDirectTypeQualifierAnnotation(xmethod, i, nonnullTypeQualifierValue);
                    TypeQualifierAnnotation typeQualifierAnnotation = TypeQualifierApplications
                            .getEffectiveTypeQualifierAnnotation(xmethod, i, nonnullTypeQualifierValue);
                    boolean implicitNullCheckForEquals = false;
                    if (directTypeQualifierAnnotation == null && method.getName().equals("equals")
                            && method.getSignature().equals("(Ljava/lang/Object;)Z") && !method.isStatic()) {
                        implicitNullCheckForEquals = true;
                        Code code = method.getCode();
                        ConstantPool cp = jclass.getConstantPool();
                        byte codeBytes[] = code.getCode();
                        for (CodeException e : code.getExceptionTable()) {
                            ConstantClass cl = (ConstantClass) cp.getConstant(e.getCatchType());
                            int endPC = e.getEndPC();
                            int startPC = e.getStartPC();
                            int handlerPC = e.getHandlerPC();
                            if (startPC == 0 && endPC + 1 == handlerPC && handlerPC == codeBytes.length - 3
                                    && (codeBytes[handlerPC + 1] & 0xff) == Constants.ICONST_0
                                    && (codeBytes[handlerPC + 2] & 0xff) == Constants.IRETURN
                                    && FindNullDeref.catchTypesForNull.contains(cl.getBytes(cp))) {
                                // equals method body contained in try clause
                                return;
                            }
                        }
                        typeQualifierAnnotation = TypeQualifierAnnotation.getValue(nonnullTypeQualifierValue, When.MAYBE);
                    }

                    if (typeQualifierAnnotation != null && typeQualifierAnnotation.when == When.ALWAYS) {
                        unconditionalDerefSet.set(i);
                    } else if (isCaught(classContext, method, entryFact, paramVN)) {
                        // ignore
                    } else if (typeQualifierAnnotation == null) {
                        unconditionalDerefSet.set(i);
                    } else {
                        int paramLocal = xmethod.isStatic() ? i : i + 1;
                        int priority = Priorities.NORMAL_PRIORITY;
                        if (typeQualifierAnnotation.when != When.UNKNOWN) {
                            priority--;
                        }
                        if (xmethod.isStatic() || xmethod.isFinal() || xmethod.isPrivate() || xmethod.getName().equals("<init>")
                                || jclass.isFinal()) {
                            priority--;
                        }
                        if (directTypeQualifierAnnotation == null) {
                            priority++;
                        }
                        String bugPattern = implicitNullCheckForEquals ? "NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT"
                                : "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE";
                        reportBug(new BugInstance(this, bugPattern, priority).addClassAndMethod(jclass, method).add(
                                LocalVariableAnnotation.getParameterLocalVariableAnnotation(method, paramLocal)));
                    }
                }
                i++;
                if (paramSig.equals("D") || paramSig.equals("J")) {
                    paramLocalOffset += 2;
                } else {
                    paramLocalOffset += 1;
                }
            }

            // No need to add properties if there are no unconditionally
            // dereferenced params
            if (unconditionalDerefSet.isEmpty()) {
                if (VERBOSE_DEBUG) {
                    System.out.println("\tResult is empty");
                }
                return;
            }

            if (VERBOSE_DEBUG) {
                ClassContext.dumpDataflowInformation(method, cfg, vnaDataflow, classContext.getIsNullValueDataflow(method),
                        dataflow, classContext.getTypeDataflow(method));
            }
            ParameterProperty property = new ParameterProperty();
            property.setParamsWithProperty(unconditionalDerefSet);

            AnalysisContext.currentAnalysisContext().getUnconditionalDerefParamDatabase()
            .setProperty(xmethod.getMethodDescriptor(), property);
            if (DEBUG) {
                System.out.println("Unconditional deref: " + xmethod + "=" + property);
            }
        } catch (CheckedAnalysisException e) {
            AnalysisContext.currentAnalysisContext().getLookupFailureCallback()
View Full Code Here

                    break;
                }

            }

            XMethod xmethod = XFactory.createXMethod(classContext.getJavaClass(), method);
            if (guaranteedNonNull) {
                returnsNonNull++;
                AnalysisContext.currentAnalysisContext().getReturnValueNullnessPropertyDatabase()
                .setProperty(xmethod.getMethodDescriptor(), guaranteedNonNull);
                if (DEBUG) {
                    System.out.println("Unconditional deref: " + xmethod + "=" + guaranteedNonNull);
                }

            }

        } catch (CFGBuilderException e) {
            XMethod xmethod = XFactory.createXMethod(classContext.getJavaClass(), method);

            AnalysisContext.currentAnalysisContext().getLookupFailureCallback()
            .logError("Error analyzing " + xmethod + " for unconditional deref training", e);
        } catch (DataflowAnalysisException e) {
            XMethod xmethod = XFactory.createXMethod(classContext.getJavaClass(), method);
            AnalysisContext.currentAnalysisContext().getLookupFailureCallback()
            .logError("Error analyzing " + xmethod + " for unconditional deref training", e);
        }
    }
View Full Code Here

    }

    @Override
    public void sawOpcode(int seen) {
        if (seen == INVOKESPECIAL) {
            XMethod m = getXMethodOperand();
            if (m == null) {
                return;
            }
            XClass c = getXClass();
            int nameDistance = EditDistance.editDistance(m.getName(), getMethodName());
            if (nameDistance < 4 && c.findMatchingMethod(m.getMethodDescriptor()) == null && !m.isFinal()) {
                potentialSuperCall = m;
            }
        }
    }
View Full Code Here

            return true;
        }
        if (methodName.length() < 2 || methodName.indexOf('$') >= 0) {
            return true;
        }
        XMethod m = getXMethod();
        for (ClassDescriptor c : m.getAnnotationDescriptors()) {
            if (c.getClassName().indexOf("inject") >= 0) {
                return true;
            }
        }
        return false;
View Full Code Here

                }
                pendingBug.addClass(superclassName).describe(role);
                try {
                    XClass from = Global.getAnalysisCache().getClassAnalysis(XClass.class,
                            DescriptorFactory.createClassDescriptorFromDottedClassName(superclassName));
                    XMethod  potentialMatch = null;
                    for(XMethod m : from.getXMethods()) {
                        if (!m.isStatic() && !m.isPrivate() && m.getName().toLowerCase().equals(obj.getName().toLowerCase())) {
                            if (potentialMatch == null) {
                                potentialMatch = m;
                            } else {
View Full Code Here

            if (skip(obj)) {
                return;
            }

            JavaClass clazz = getThisClass();
            XMethod xmethod = XFactory.createXMethod(clazz, obj);
            XFactory factory = AnalysisContext.currentXFactory();
            String key = obj.getName() + ":" + obj.getSignature();
            if (!factory.isCalled(xmethod) && (obj.isStatic() || !definedInSuperClassOrInterface(clazz, key))) {
                int priority = NORMAL_PRIORITY;
                JavaClass superClass = clazz.getSuperClass();
View Full Code Here

            priority++;
            nullCheckedFields.add(f);
        }

        for (ProgramPoint p : calledFrom) {
            XMethod upcall = getConstructorThatCallsSuperConstructor(p.method);
            if (upcall == null) {
                continue;
            }
            Method upcallMethod = null;
            for (Method m : getThisClass().getMethods()) {
                if (m.getName().equals(upcall.getName()) && m.getSignature().equals(upcall.getSignature())) {
                    upcallMethod = m;
                    break;
                }
            }
            if (upcallMethod == null) {
View Full Code Here

    private @CheckForNull
    XMethod getConstructorThatCallsSuperConstructor(XMethod superConstructor) {
        FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary();

        XMethod lookfor = superConstructor.getSignature().equals("()V") ? null : superConstructor;
        for (XMethod m : getXClass().getXMethods()) {
            if (m.getName().equals("<init>")) {
                if (fieldSummary.getSuperCall(m) == lookfor) {
                    return m;
                }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.XMethod

Copyright © 2018 www.massapicom. 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.