Package edu.umd.cs.findbugs.ba

Examples of edu.umd.cs.findbugs.ba.SignatureParser$ParameterSignatureIterator


    @Override
    public void visit(Code code) {

        methodsSeen.add(getXMethod());
        String signature = getMethodSig();
        SignatureParser parser = new SignatureParser(signature);

        String returnType = parser.getReturnTypeSignature();
        @SlashedClassName
        String r = ClassName.fromFieldSignature(returnType);
        if (r == null || !r.equals(getClassName())) {
            return;
        }
        // System.out.println("Checking " + getFullyQualifiedMethodName());
        boolean funky = false;
        for (int i = 0; i < parser.getNumParameters(); i++) {
            String p = ClassName.fromFieldSignature(parser.getParameter(i));
            if (getClassName().equals(p)) {
                funky = true;
            }

        }
View Full Code Here


                // returning a newly constructed value
                boolean voidConstructor;
                if (!isInnerClass) {
                    voidConstructor = sig.equals("()V");
                } else {
                    SignatureParser parser = new SignatureParser(sig);
                    voidConstructor = parser.getNumParameters()  <= 1;
                }
                if (voidConstructor) {
                    returnSelf++;
                } else {
                    returnOther++;
View Full Code Here

        String methodName = obj.getMethodName(cpg);
        String signature = obj.getSignature(cpg);
        String className = obj.getClassName(cpg);

        String returnValueSignature = new SignatureParser(signature).getReturnTypeSignature();
        if (returnValueSignature.equals("V")) {
            consumeStack(obj);
            return;
        }

        if (methodName.equals("isInstance")) {
            if (className.equals("java.lang.Class") && valueNumberDataflow != null) {
                // Record the value number of the value checked by this
                // instruction,
                // and the type the value was compared to.
                try {
                    ValueNumberFrame vnaFrame = valueNumberDataflow.getFactAtLocation(getLocation());
                    if (vnaFrame.isValid()) {
                        ValueNumber stackValue = vnaFrame.getStackValue(1);
                        if (stackValue.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT)) {
                            String c = valueNumberDataflow.getClassName(stackValue);
                            if (c != null) {
                                if (c.charAt(0) != '[' && !c.endsWith(";")) {
                                    c = "L" + c.replace('.', '/') + ";";
                                }
                                Type type = Type.getType(c);
                                if (type instanceof ReferenceType) {
                                    instanceOfValueNumber = vnaFrame.getTopValue();
                                    instanceOfType = (ReferenceType) type;
                                    sawEffectiveInstanceOf = true;
                                }
                            }
                        }

                    }
                } catch (DataflowAnalysisException e) {
                    // Ignore
                }
            }
        }

        Type returnTypeOfMethod = obj.getType(cpg);
        if (!(returnTypeOfMethod instanceof ReferenceType)) {
            consumeStack(obj);
            pushReturnType(obj);
            return;
        }

        if (methodName.equals("cast") && className.equals("java.lang.Class")) {
            try {
                Type resultType = frame.popValue();
                frame.popValue();
                frame.pushValue(resultType);
            } catch (DataflowAnalysisException e) {
                AnalysisContext.logError("oops", e);
            }

            return;
        }

        mapGetCheck: if (methodName.equals("get") && signature.equals("(Ljava/lang/Object;)Ljava/lang/Object;")
                && className.endsWith("Map") && Subtypes2.instanceOf(className, "java.util.Map")
                && frame.getStackDepth() >= 2) {
            try {
                Type mapType = frame.getStackValue(1);
                if (mapType instanceof GenericObjectType) {
                    GenericObjectType genericMapType = (GenericObjectType) mapType;
                    List<? extends ReferenceType> parameters = genericMapType.getParameters();
                    if (parameters == null || parameters.size() != 2) {
                        break mapGetCheck;
                    }

                    ClassDescriptor c = DescriptorFactory.getClassDescriptor(genericMapType);
                    if (!Subtypes2.instanceOf(c, Map.class)) {
                        break mapGetCheck;
                    }
                    if (!isStraightGenericMap(c)) {
                        break mapGetCheck;
                    }

                    ReferenceType valueType = parameters.get(1);
                    consumeStack(obj);
                    frame.pushValue(valueType);
                    return;

                }
            } catch (DataflowAnalysisException e) {
                AnalysisContext.logError("oops", e);
            }

        }

        if (className.equals("java.util.Map$Entry")) {
            if (methodName.equals("getKey") && getResultTypeFromGenericType(frame, 0, 2) || methodName.equals("getValue")
                    && getResultTypeFromGenericType(frame, 1, 2)) {
                return;
            }
        }

        if (methodName.equals("entrySet") && signature.equals("()Ljava/util/Set;") && className.startsWith("java.util")
                && className.endsWith("Map")) {
            Type argType;
            try {
                argType = frame.popValue();
            } catch (DataflowAnalysisException e) {
                AnalysisContext.logError("oops", e);
                return;
            }
            ObjectType mapType = (ObjectType) Type.getType("Ljava/util/Map$Entry;");

            if (argType instanceof GenericObjectType) {
                GenericObjectType genericArgType = (GenericObjectType) argType;
                List<? extends ReferenceType> parameters = genericArgType.getParameters();
                if (parameters != null && parameters.size() == 2) {
                    mapType = GenericUtilities.getType("java.util.Map$Entry", parameters);
                }
            }
            GenericObjectType entrySetType = GenericUtilities.getType("java.util.Set", Collections.singletonList(mapType));
            frame.pushValue(entrySetType);
            return;

        }
        if (className.startsWith("java.util") && className.endsWith("Map")) {
            if (methodName.equals("keySet") && signature.equals("()Ljava/util/Set;")
                    && handleGetMapView(frame, "java.util.Set", 0, 2) || methodName.equals("values")
                    && signature.equals("()Ljava/util/Collection;") && handleGetMapView(frame, "java.util.Collection", 1, 2)) {
                return;
            }
        }

        if (methodName.equals("iterator") && signature.equals("()Ljava/util/Iterator;") && className.startsWith("java.util")
                && handleGetMapView(frame, "java.util.Iterator", 0, 1)) {
            return;
        }
        if (className.equals("java.util.Iterator") && methodName.equals("next") && signature.equals("()Ljava/lang/Object;")
                && getResultTypeFromGenericType(frame, 0, 1)) {
            return;
        }

        if (methodName.equals("initCause") && signature.equals("(Ljava/lang/Throwable;)Ljava/lang/Throwable;")
                && (className.endsWith("Exception")
                        || className.endsWith("Error"))) {
            try {

                frame.popValue();
                return;
            } catch (DataflowAnalysisException e) {
                AnalysisContext.logError("Ooops", e);
            }
        }
        if (handleToArray(obj)) {
            return;
        }
        Type result = TopType.instance();
        try {
            Set<XMethod> targets = Hierarchy2.resolveMethodCallTargets(obj, frame, cpg);
            if (DEBUG) {
                System.out.println(" For call to " + className + "." + methodName + signature);
                System.out.println("   for " + targets.size() + " targets: " + targets);
            }
            for (XMethod m : targets) {
                m = m.resolveAccessMethodForMethod();
                String sourceSignature = m.getSourceSignature();
                if (DEBUG) {
                    System.out.println(" Call target: " + m);
                    if (sourceSignature != null) {
                        System.out.println("  source signature: " + sourceSignature);
                    }
                }
                boolean foundSomething = false;
                XMethod m2 = m.bridgeTo();
                if (m2 != null) {
                    m = m2;
                }
                if (sourceSignature != null && !sourceSignature.equals(m.getSignature())) {
                    GenericSignatureParser p = new GenericSignatureParser(sourceSignature);
                    String rv = p.getReturnTypeSignature();
                    if (rv.charAt(0) != 'T') {
                        try {
                            Type t = GenericUtilities.getType(rv);
                            if (t != null) {
                                assert t.getType() != T_VOID;
                                result = merge(result, t);
                                foundSomething = true;
                            }
                        } catch (RuntimeException e) {
                            AnalysisContext.logError("Problem analyzing call to " + m + " with source signature"
                                    + sourceSignature, e);
                            break;
                        }
                    }
                }

                if (m == m2) {
                    SignatureParser p = new SignatureParser(m.getSignature());
                    String rv = p.getReturnTypeSignature();

                    Type t = Type.getType(rv);
                    result = merge(result, t);
                    foundSomething = true;
View Full Code Here

            String name = getNameConstantOperand();

            boolean booleanComparisonMethod = FindSelfComparison2.booleanComparisonMethod(name);
            if (booleanComparisonMethod || FindSelfComparison2.comparatorMethod(name)) {
                String sig = getSigConstantOperand();
                SignatureParser parser = new SignatureParser(sig);
                int numParameters = parser.getNumParameters();
                if ((numParameters == 1 ||  seen == INVOKESTATIC && numParameters  == 2)
                        && (booleanComparisonMethod && sig.endsWith(";)Z")
                                ||  FindSelfComparison2.comparatorMethod(name) && sig.endsWith(";)I"))) {
                    checkForSelfOperation(seen, "COMPARISON");
                }
View Full Code Here

        } catch (CFGBuilderException e) {
            AnalysisContext.logError("error", e);
        }

        InvokeInstruction instruction = (InvokeInstruction) location.getHandle().getInstruction();
        SignatureParser sigParser = new SignatureParser(instruction.getSignature(classContext.getConstantPoolGen()));

        for (int i = violatedParamSet.nextSetBit(0); i >= 0; i = violatedParamSet.nextSetBit(i + 1)) {
            boolean definitelyNull = definitelyNullArgSet.get(i);

            if (definitelyNull) {
View Full Code Here

        }

        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) {
View Full Code Here

                accumulator.accumulateBug(bug, this);
            }
        }
        if ((seen == INVOKESTATIC || seen == INVOKEVIRTUAL || seen == INVOKESPECIAL || seen == INVOKEINTERFACE)
                && getSigConstantOperand().indexOf("Ljava/lang/Runnable;") >= 0) {
            SignatureParser parser = new SignatureParser(getSigConstantOperand());
            int count = 0;
            for (Iterator<String> i = parser.parameterSignatureIterator(); i.hasNext(); count++) {
                String parameter = i.next();
                if (parameter.equals("Ljava/lang/Runnable;")) {
                    OpcodeStack.Item item = stack.getStackItem(parser.getNumParameters() - 1 - count);
                    if ("Ljava/lang/Thread;".equals(item.getSignature())) {
                        accumulator.accumulateBug(new BugInstance(this, "DMI_THREAD_PASSED_WHERE_RUNNABLE_EXPECTED",
                                NORMAL_PRIORITY).addClassAndMethod(this).addCalledMethod(this), this);
                    }
View Full Code Here

                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));
                            }
                        }
                    }

                    // Check actual targets
                    try {
                        Set<JavaClassAndMethod> targetMethodSet = Hierarchy.resolveMethodCallTargets(inv, typeFrame, cpg);
                        BitSet unconditionallyDereferencedNullArgSet = null;
                        for (JavaClassAndMethod targetMethod : targetMethodSet) {

                            ParameterProperty property = unconditionalDerefParamDatabase.getProperty(targetMethod
                                    .toMethodDescriptor());
                            if (property == null) {
                                unconditionallyDereferencedNullArgSet = null;
                                break;
                            }
                            BitSet foo = property.getAsBitSet();
                            if (unconditionallyDereferencedNullArgSet == null) {
                                unconditionallyDereferencedNullArgSet = foo;
                            } else {
                                unconditionallyDereferencedNullArgSet.intersects(foo);
                            }
                            if (unconditionallyDereferencedNullArgSet.isEmpty()) {
                                break;
                            }
                        }

                        if (unconditionallyDereferencedNullArgSet != null && !unconditionallyDereferencedNullArgSet.isEmpty()
                                && valueNumberFrame.isValid()) {
                            for (int j = unconditionallyDereferencedNullArgSet.nextSetBit(0); j >= 0; j = unconditionallyDereferencedNullArgSet
                                    .nextSetBit(j + 1)) {
                                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

                    if (actionList.isEmpty()) {

                        try {
                            TypeFrame factAtLocation = null;
                            SignatureParser sigParser = new SignatureParser(signature);
                            //                        int startIndex = 0;
                            //                        if (!xmethod.isStatic())
                            //                            startIndex = 1;
                            Iterator<String> signatureIterator = sigParser.parameterSignatureIterator();
                            int parameters = sigParser.getNumParameters();
                            for (int i = 0; i < parameters; i++) {
                                String sig = signatureIterator.next();
                                Collection<ClassDescriptor> annotations = invokedMethod.getParameterAnnotationDescriptors(i);
                                if (annotations.contains(WILL_CLOSE) || sig.equals("Ljava/io/Closeable;") || methodName.startsWith("close")) {
                                    // closing this value
View Full Code Here

     * edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs
     * .classfile.IAnalysisCache, java.lang.Object)
     */
    @Override
    public String[] analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        SignatureParser parser = new SignatureParser(descriptor.getSignature());
        ArrayList<String> resultList = new ArrayList<String>();
        for (Iterator<String> i = parser.parameterSignatureIterator(); i.hasNext();) {
            resultList.add(i.next());
        }
        return resultList.toArray(new String[resultList.size()]);
    }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.SignatureParser$ParameterSignatureIterator

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.