Package edu.umd.cs.findbugs.ba

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


    }

    @Override
    public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock) throws DataflowAnalysisException {
        // Record what Location we are analyzing
        this.location = new Location(handle, basicBlock);

        final Instruction ins = handle.getInstruction();
        final ResourceValueFrame frame = getFrame();

        int status = -1;
        boolean created = false;

        // Is a resource created, opened, or closed by this instruction?
        Location creationPoint = stream.getLocation();
        if (handle == creationPoint.getHandle() && basicBlock == creationPoint.getBasicBlock()) {
            // Resource creation
            if (stream.isOpenOnCreation()) {
                status = ResourceValueFrame.OPEN;
                stream.setOpenLocation(location);
                resourceTracker.addStreamOpenLocation(location, stream);
View Full Code Here


        TypeDataflow typeDataflow = classContext.getTypeDataflow(method);

        String sourceFileName = javaClass.getSourceFileName();

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();

            InstructionHandle handle = location.getHandle();
            Instruction ins = handle.getInstruction();

            if (ins instanceof InvokeInstruction) {
                InvokeInstruction invoke = (InvokeInstruction) ins;
                String className = invoke.getClassName(cpg);
View Full Code Here

        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        MethodGen methodGen = classContext.getMethodGen(method);
        String sourceFile = classContext.getJavaClass().getSourceFileName();

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();

            Instruction ins = location.getHandle().getInstruction();
            switch (ins.getOpcode()) {
            case INVOKEVIRTUAL:
            case INVOKEINTERFACE:
                InvokeInstruction iins = (InvokeInstruction) ins;
                String invoking = iins.getName(cpg);
                if ( comparatorMethod(invoking) || booleanComparisonMethod(invoking) ) {
                    if (methodGen.getName().toLowerCase().indexOf("test") >= 0) {
                        break;
                    }
                    if (methodGen.getClassName().toLowerCase().indexOf("test") >= 0) {
                        break;
                    }
                    if (classContext.getJavaClass().getSuperclassName().toLowerCase().indexOf("test") >= 0) {
                        break;
                    }
                    if (location.getHandle().getNext().getInstruction().getOpcode() == POP) {
                        break;
                    }
                    String sig = iins.getSignature(cpg);

                    SignatureParser parser = new SignatureParser(sig);
View Full Code Here

            if (DEBUG) {
                System.out.println(item.getPC() + " null guarantees " + nullGuaranteesBranch + " branch");
            }
            try {
                CFG cfg = getClassContext().getCFG(getMethod());
                Location produced = findLocation(cfg, item.getPC());
                Location branch = findLocation(cfg, getPC() + 1);
                if (produced == null || branch == null) {
                    return;
                }

                IfInstruction branchInstruction = (IfInstruction) branch.getHandle().getInstruction();

                IsNullValueDataflow isNullValueDataflow = getClassContext().getIsNullValueDataflow(getMethod());
                ValueNumberDataflow valueNumberDataflow = getClassContext().getValueNumberDataflow(getMethod());
                UnconditionalValueDerefDataflow unconditionalValueDerefDataflow = getClassContext()
                        .getUnconditionalValueDerefDataflow(getMethod());
                ValueNumberFrame valueNumberFact = valueNumberDataflow.getFactAtLocation(produced);
                IsNullValueFrame isNullFact = isNullValueDataflow.getFactAtLocation(produced);
                ValueNumber value = valueNumberFact.getTopValue();
                if (isNullFact.getTopValue().isDefinitelyNotNull()) {
                    return;
                }
                if (DEBUG) {
                    System.out.println("Produced: " + produced);
                    System.out.println(valueNumberFact);
                    System.out.println(isNullFact);
                    System.out.println("value: " + value);
                    System.out.println("branch: " + branch);
                    System.out.println("instruction: " + branchInstruction);
                    System.out.println("target: " + branchInstruction.getTarget());
                    System.out.println("next: " + branch.getHandle().getNext());
                }
                Location guaranteed = findLocation(cfg, nullGuaranteesBranch ? branchInstruction.getTarget() : branch.getHandle()
                        .getNext());
                if (guaranteed == null) {
                    return;
                }
View Full Code Here

    }

    @CheckForNull
    Location findLocation(CFG cfg, int pc) {
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location loc = i.next();
            if (loc.getHandle().getPosition() == pc) {
                return loc;
            }
        }
        return null;
    }
View Full Code Here

    }

    @CheckForNull
    Location findLocation(CFG cfg, InstructionHandle handle) {
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location loc = i.next();
            if (loc.getHandle() == handle) {
                return loc;
            }
        }
        return null;
    }
View Full Code Here

                continue;
            }

            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

        // Scan method for
        // - dead stores
        // - stores to parameters that are dead upon entry to the method
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();

            BugInstance pendingBugReportAboutOverwrittenParameter = null;
            try {
                WarningPropertySet<WarningProperty> propertySet = new WarningPropertySet<WarningProperty>();
                // Skip any instruction which is not a store
                if (!isStore(location)) {
                    continue;
                }

                // Heuristic: exception handler blocks often contain
                // dead stores generated by the compiler.
                if (location.getBasicBlock().isExceptionHandler()) {
                    propertySet.addProperty(DeadLocalStoreProperty.EXCEPTION_HANDLER);
                }
                InstructionHandle handle = location.getHandle();
                int pc = handle.getPosition();
                IndexedInstruction ins = (IndexedInstruction) location.getHandle().getInstruction();

                int local = ins.getIndex();

                // Get live stores at this instruction.
                // Note that the analysis also computes which stores were
                // killed by a subsequent unconditional store.
                BitSet liveStoreSet = llsaDataflow.getAnalysis().getFactAtLocation(location);

                // Is store alive?
                boolean storeLive = llsaDataflow.getAnalysis().isStoreAlive(liveStoreSet, local);

                LocalVariableAnnotation lvAnnotation = LocalVariableAnnotation.getLocalVariableAnnotation(method, location, ins);

                String sourceFileName = javaClass.getSourceFileName();
                if (lvAnnotation.getName().equals("?")) {
                    if (sourceFileName.endsWith(".groovy")) {
                        continue;
                    }
                    if (method.getCode().getLocalVariableTable() != null) {
                        continue;
                    }
                }

                SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
                        sourceFileName, location.getHandle());

                if (DEBUG) {
                    System.out.println("    Store at " + sourceLineAnnotation.getStartLine() + "@"
                            + location.getHandle().getPosition() + " is " + (storeLive ? "live" : "dead"));
                    System.out.println("Previous is: " + location.getHandle().getPrev());
                }

                // Note source lines of live stores.
                if (storeLive && sourceLineAnnotation.getStartLine() > 0) {
                    liveStoreSourceLineSet.set(sourceLineAnnotation.getStartLine());
                }

                String lvName = lvAnnotation.getName();
                if (lvName.charAt(0) == '$' || lvName.charAt(0) == '_') {
                    propertySet.addProperty(DeadLocalStoreProperty.SYNTHETIC_NAME);
                }
                if (EXCLUDED_LOCALS.contains(lvName)) {
                    continue;
                }
                propertySet.setProperty(DeadLocalStoreProperty.LOCAL_NAME, lvName);

                boolean isParameter = local < localsThatAreParameters;
                if (isParameter) {
                    propertySet.addProperty(DeadLocalStoreProperty.IS_PARAMETER);
                }

                Field shadowedField = null;

                for (Field f : javaClass.getFields()) {
                    if (f.getName().equals(lvName) && f.isStatic() == method.isStatic()) {
                        shadowedField = f;
                        propertySet.addProperty(DeadLocalStoreProperty.SHADOWS_FIELD);
                        break;
                    }
                }

                // Is this a store to a parameter which was dead on entry to the
                // method?
                boolean parameterThatIsDeadAtEntry = isParameter
                        && !llsaDataflow.getAnalysis().isStoreAlive(liveStoreSetAtEntry, local);
                if (parameterThatIsDeadAtEntry && !complainedAbout.get(local)) {

                    int priority = storeLive ? LOW_PRIORITY : NORMAL_PRIORITY;
                    if (shadowedField != null) {
                        priority--;
                    }
                    pendingBugReportAboutOverwrittenParameter = new BugInstance(this, "IP_PARAMETER_IS_DEAD_BUT_OVERWRITTEN",
                            priority).addClassAndMethod(methodGen, sourceFileName).add(lvAnnotation);

                    if (shadowedField != null) {
                        pendingBugReportAboutOverwrittenParameter.addField(
                                FieldAnnotation.fromBCELField(classContext.getJavaClass(), shadowedField)).describe(
                                        FieldAnnotation.DID_YOU_MEAN_ROLE);
                    }

                    pendingBugReportAboutOverwrittenParameter.addSourceLine(classContext, methodGen, sourceFileName,
                            location.getHandle());
                    complainedAbout.set(local);
                }

                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) {
                    Instruction prevIns = prevInsHandle.getInstruction();
                    boolean foundDeadClassInitialization = false;
                    String initializationOf = null;
                    if (prevIns instanceof ConstantPushInstruction) {
                        continue; // not an interesting dead store
                    } else if (prevIns instanceof GETSTATIC) {
                        GETSTATIC getStatic = (GETSTATIC) prevIns;
                        ConstantPoolGen cpg = methodGen.getConstantPool();
                        foundDeadClassInitialization = getStatic.getFieldName(cpg).startsWith("class$")
                                && getStatic.getSignature(cpg).equals("Ljava/lang/Class;");
                        for (Iterator<Location> j = cfg.locationIterator(); j.hasNext();) {
                            Location location2 = j.next();
                            if (location2.getHandle().getPosition() + 15 == location.getHandle().getPosition()) {
                                Instruction instruction2 = location2.getHandle().getInstruction();
                                if (instruction2 instanceof LDC) {
                                    Object value = ((LDC) instruction2).getValue(methodGen.getConstantPool());
                                    if (value instanceof String) {
                                        String n = (String) value;
                                        if (n.length() > 0) {
View Full Code Here

     *            control flow graph (CFG) of method
     */
    private void countLocalStoresLoadsAndIncrements(int[] localStoreCount, int[] localLoadCount, int[] localIncrementCount,
            CFG cfg) {
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();

            if (location.getBasicBlock().isExceptionHandler()) {
                continue;
            }

            boolean isStore = isStore(location);
            boolean isLoad = isLoad(location);
            if (!isStore && !isLoad) {
                continue;
            }

            IndexedInstruction ins = (IndexedInstruction) location.getHandle().getInstruction();
            int local = ins.getIndex();
            if (ins instanceof IINC) {
                localStoreCount[local]++;
                localLoadCount[local]++;
                localIncrementCount[local]++;
View Full Code Here

        if (sig.indexOf("java/lang/String") >= 0) {
            stringAppendState.setSawInitialTaint();
        }
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();
            InstructionHandle handle = location.getHandle();
            Instruction ins = handle.getInstruction();
            if (isConstantStringLoad(location, cpg)) {
                stringAppendState = updateStringAppendState(location, cpg, stringAppendState);
            } else if (isStringAppend(ins, cpg)) {
                stringAppendState.setSawAppend(handle);

                Location prevLocation = getPreviousLocation(cfg, location, true);
                if (prevLocation != null && !isSafeValue(prevLocation, cpg)) {
                    stringAppendState.setSawUnsafeAppend(handle);
                }

            } else if (ins instanceof InvokeInstruction) {
View Full Code Here

TOP

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

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.