Package edu.umd.cs.findbugs.ba.type

Examples of edu.umd.cs.findbugs.ba.type.TypeFrame


                System.out.println("no database!");
            }
            return Collections.emptySet();
        }

        TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
        if (!typeFrame.isValid()) {
            if (DEBUG_CHECK_CALLS) {
                System.out.println("invalid type frame!");
            }
            return Collections.emptySet();
        }
View Full Code Here


                String methodSig = iv.getSignature(cpg);
                if (methodName.equals("wait")
                        && (methodSig.equals("()V") || methodSig.equals("(J)V") || methodSig.equals("(JI)V"))
                        || (methodName.equals("notify") || methodName.equals("notifyAll")) && methodSig.equals("()V")) {
                    try {
                        TypeFrame frame = typeDataflow.getFactAtLocation(location);
                        if (!frame.isValid()) {
                            continue;
                        }
                        Type type = frame.getInstance(ins, cpg);
                        if (!(type instanceof ReferenceType)) {
                            // Something is deeply wrong if a non-reference type
                            // is used for a method invocation. But, that's
                            // really a
                            // verification problem.
                            continue;
                        }
                        ClassDescriptor classDescriptor = DescriptorFactory.createClassDescriptorFromSignature(type
                                .getSignature());
                        if (classDescriptor.equals(classContext.getClassDescriptor())) {
                            continue;
                        }
                        if (!classDescriptor.getClassName().startsWith("java/util/concurrent")) {
                            continue;
                        }
                        XClass c = Lookup.getXClass(classDescriptor);
                        XMethod m;
                        int priority = NORMAL_PRIORITY;
                        if (methodName.equals("wait")) {
                            m = c.findMethod("await", "()V", false);
                            priority = HIGH_PRIORITY;
                        } else if (methodName.equals("notify")) {
                            m = c.findMethod("signal", "()V", false);
                            if (m == null) {
                                m = c.findMethod("countDown", "()V", false);
                            }
                        } else if (methodName.equals("notifyAll")) {
                            m = c.findMethod("signalAll", "()V", false);
                            if (m == null) {
                                m = c.findMethod("countDown", "()V", false);
                            }
                        } else {
                            throw new IllegalStateException("Unexpected methodName: " + methodName);
                        }

                        if (m != null && m.isPublic() && c.isPublic()) {
                            bugReporter.reportBug(new BugInstance(this, "JML_JSR166_CALLING_WAIT_RATHER_THAN_AWAIT", priority)
                            .addClassAndMethod(classContext.getJavaClass(), method).addCalledMethod(cpg, iv).addMethod(m)
                            .describe(MethodAnnotation.METHOD_ALTERNATIVE_TARGET).addType(classDescriptor)
                            .describe(TypeAnnotation.FOUND_ROLE).addSourceLine(classContext, method, location));
                        }

                    } catch (CheckedAnalysisException e) {
                        AnalysisContext.logError("Coult not get Type dataflow", e);
                        continue;
                    }

                }

            }

            if (ins.getOpcode() != Constants.MONITORENTER) {
                continue;
            }
            Type type;
            try {
                TypeFrame frame = typeDataflow.getFactAtLocation(location);
                if (!frame.isValid()) {
                    continue;
                }
                type = frame.getInstance(ins, cpg);
            } catch (CheckedAnalysisException e) {
                AnalysisContext.logError("Coult not get Type dataflow", e);
                continue;
            }
View Full Code Here

                        //
                        // A value is being assigned to a field or returned from
                        // the method.
                        //
                        Location loc = new Location(handle, curBlock);
                        TypeFrame typeFrame = typeDataflow.getFactAtLocation(loc);
                        if (!typeFrame.isValid()) {
                            // dead code?
                            couldNotAnalyze = true;
                        }
                        Type tosType = typeFrame.getTopValue();
                        if (tosType instanceof ObjectType
                                && isPossibleInstanceOfObligationType(subtypes2, (ObjectType) tosType,
                                        possiblyLeakedObligation.getType())) {
                            // Remove one obligation of this type
                            adjustedLeakCount--;
View Full Code Here

                    lhsPos = sigParser.getTotalArgumentSize();
                }

                int stackPos = sigParser.getSlotsFromTopOfStackForParameter(pos);

                TypeFrame frame = typeDataflow.getFactAtLocation(location);
                if (!frame.isValid()) {
                    // This basic block is probably dead
                    continue;
                }


                Type operandType = frame.getStackValue(stackPos);
                if (operandType.equals(TopType.instance())) {
                    // unreachable
                    continue;
                }

                if (operandType.equals(NullType.instance())) {
                    // ignore
                    continue;
                }

                ValueNumberFrame vnFrame = vnDataflow.getFactAtLocation(location);

                if (!vnFrame.isValid()) {
                    AnalysisContext.logError("Invalid value number frame in " + xmethod);
                    continue;
                }

                ValueNumber objectVN = vnFrame.getStackValue(lhsPos);
                ValueNumber argVN = vnFrame.getStackValue(stackPos);

                if (objectVN.equals(argVN)) {
                    String bugPattern = "DMI_COLLECTIONS_SHOULD_NOT_CONTAIN_THEMSELVES";
                    int priority = HIGH_PRIORITY;
                    if (invokedMethodName.equals("removeAll")) {
                        bugPattern = "DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION";
                        priority = NORMAL_PRIORITY;
                    } else if (invokedMethodName.endsWith("All")) {
                        bugPattern = "DMI_VACUOUS_SELF_COLLECTION_CALL";
                        priority = NORMAL_PRIORITY;
                    }
                    if (invokedMethodName.startsWith("contains")) {
                        InstructionHandle next = handle.getNext();
                        if (next != null) {
                            Instruction nextIns = next.getInstruction();

                            if (nextIns instanceof InvokeInstruction) {
                                XMethod nextMethod = XFactory.createXMethod((InvokeInstruction) nextIns, cpg);
                                if (nextMethod.getName().equals("assertFalse")) {
                                    continue;
                                }
                            }
                        }
                    }
                    accumulator.accumulateBug(
                            new BugInstance(this, bugPattern, priority)
                            .addClassAndMethod(methodGen, sourceFile)
                            .addCalledMethod(methodGen, (InvokeInstruction) ins)
                            .addOptionalAnnotation(
                                    ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, objectVN,
                                            vnFrame, "INVOKED_ON")), SourceLineAnnotation.fromVisitedInstruction(
                                                    classContext, methodGen, sourceFile, handle));
                }

                // Only consider generic...
                Type objectType = frame.getStackValue(lhsPos);
                if (!(objectType instanceof GenericObjectType)) {
                    continue;
                }

                GenericObjectType operand = (GenericObjectType) objectType;

                int expectedTypeParameters = 1;
                String simpleName = info.interfaceForCall.getSimpleName();
                if ( simpleName.toLowerCase().endsWith("map") || simpleName.equals("Hashtable")) {
                    expectedTypeParameters = 2;
                } else if (simpleName.equals("Table")) {
                    expectedTypeParameters = 3;
                }

                // ... containers
                if (!operand.hasParameters()) {
                    continue;
                }
                if (operand.getNumParameters() != expectedTypeParameters) {
                    continue;
                }
                ClassDescriptor operandClass = DescriptorFactory.getClassDescriptor(operand);
                if (!isGenericCollection(operandClass)) {
                    continue;
                }

                if (expectedTypeParameters == 2 &&
                        Subtypes2.instanceOf(operandClass, Map.class)
                        && !TypeFrameModelingVisitor.isStraightGenericMap(operandClass)) {
                    continue;
                }
                Type expectedType;
                if (allMethod) {
                    expectedType = operand;
                } else {
                    expectedType = operand.getParameterAt(typeArgument);
                }
                Type actualType = frame.getStackValue(stackPos);
                Type equalsType = actualType;
                if (allMethod) {
                    if (!(actualType instanceof GenericObjectType)) {
                        continue;
                    }
View Full Code Here

            if (ins instanceof INVOKEINTERFACE) {
                continue;
            }

            InvokeInstruction inv = (InvokeInstruction) ins;
            TypeFrame frame = typeDataflow.getFactAtLocation(location);

            String methodName = inv.getMethodName(constantPoolGen);
            if (methodName.toLowerCase().indexOf("unsupported") >= 0) {
                continue;
            }
View Full Code Here

                // threadsafe class is extended by a subclass that
                // doesn't care about thread safety.
                if (ADJUST_SUBCLASS_ACCESSES) {
                    // Find the type of the object instance
                    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
                    TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
                    if (!typeFrame.isValid()) {
                        continue;
                    }
                    Type instanceType = typeFrame.getInstance(handle.getInstruction(), cpg);
                    if (instanceType instanceof TopType) {
                        if (DEBUG) {
                            System.out.println("Freaky: typeFrame is " + typeFrame);
                        }
                        continue;
View Full Code Here

            }

            String className = inv.getClassName(cpg);

            Location loc = new Location(thrower, basicBlock);
            TypeFrame typeFrame = typeDataflow.getFactAtLocation(loc);
            XMethod primaryXMethod = XFactory.createXMethod(inv, cpg);
            // if (primaryXMethod.isAbstract()) continue;
            Set<XMethod> targetSet = null;
            try {
View Full Code Here

                if (storeLive) {
                    continue;
                }

                TypeFrame typeFrame = typeDataflow.getAnalysis().getFactAtLocation(location);
                Type typeOfValue = null;
                if (typeFrame.isValid() && typeFrame.getStackDepth() > 0) {
                    typeOfValue = typeFrame.getTopValue();
                }

                boolean storeOfNull = false;
                InstructionHandle prevInsHandle = location.getHandle().getPrev();
                if (prevInsHandle != null) {
View Full Code Here

                    String className = inv.getClassName(cpg);
                    if (methodName.equals("valueOf") && className.equals("java.lang.String")
                            && sig1.equals("(Ljava/lang/Object;)Ljava/lang/String;")) {
                        try {
                            TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
                            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;
                            }
                            String sig3 = operandType.getSignature();
View Full Code Here

            Use use = getUse(cpg, ins);
            if (use == null) {
                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;
            }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.type.TypeFrame

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.