Java Code Examples for org.apache.bcel.Const#INVOKEVIRTUAL

The following examples show how to use org.apache.bcel.Const#INVOKEVIRTUAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindUnconditionalWait.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    switch (stage) {
    case 0:
        if (seen == Const.MONITORENTER) {
            stage = 1;
        }
        break;
    case 1:
        if (seen == Const.INVOKEVIRTUAL && "wait".equals(getNameConstantOperand())) {
            bugReporter.reportBug(new BugInstance(this, "UW_UNCOND_WAIT",
                    "()V".equals(getSigConstantOperand()) ? NORMAL_PRIORITY : LOW_PRIORITY).addClassAndMethod(this)
                            .addSourceLine(this));
            stage = 2;
        }
        break;
    default:
        break;
    }
}
 
Example 2
Source File: StartInConstructor.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Const.INVOKEVIRTUAL && "start".equals(getNameConstantOperand()) && "()V".equals(getSigConstantOperand())) {
        try {
            if (Hierarchy.isSubtype(getDottedClassConstantOperand(), "java.lang.Thread")) {
                int priority = Priorities.NORMAL_PRIORITY;
                if (getPC() + 4 >= getCode().getCode().length) {
                    priority = Priorities.LOW_PRIORITY;
                }
                BugInstance bug = new BugInstance(this, "SC_START_IN_CTOR", priority).addClassAndMethod(this)
                        .addCalledMethod(this);
                Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
                Set<ClassDescriptor> directSubtypes = subtypes2.getDirectSubtypes(getClassDescriptor());
                if (!directSubtypes.isEmpty()) {
                    for (ClassDescriptor sub : directSubtypes) {
                        bug.addClass(sub).describe(ClassAnnotation.SUBCLASS_ROLE);
                    }
                    bug.setPriority(Priorities.HIGH_PRIORITY);
                }
                bugAccumulator.accumulateBug(bug, this);
            }
        } catch (ClassNotFoundException e) {
            bugReporter.reportMissingClass(e);
        }
    }
}
 
Example 3
Source File: FindRunInvocations.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (alreadySawStart) {
        return;
    }
    if ((seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE) && "()V".equals(getSigConstantOperand())
            && isThread(getDottedClassConstantOperand())) {
        if ("start".equals(getNameConstantOperand())) {
            alreadySawStart = true;
        } else {
            boolean isJustThread = !"java.lang.Thread".equals(getDottedClassConstantOperand());
            if (amVisitingMainMethod() && getPC() == getCode().getLength() - 4 && isJustThread) {
                return;
            } else if ("run".equals(getNameConstantOperand())) {
                bugAccumulator.accumulateBug(new BugInstance(this, "RU_INVOKE_RUN", isJustThread ? HIGH_PRIORITY
                        : NORMAL_PRIORITY).addClassAndMethod(this), this);
            }
        }
    }
}
 
Example 4
Source File: EmptyZipFileEntry.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Const.INVOKEVIRTUAL && "putNextEntry".equals(getNameConstantOperand())) {
        streamType = getClassConstantOperand();
        if ("java/util/zip/ZipOutputStream".equals(streamType) || "java/util/jar/JarOutputStream".equals(streamType)) {
            sawPutEntry = getPC();
        } else {
            streamType = "";
        }
    } else {
        if (getPC() - sawPutEntry <= 7 && seen == Const.INVOKEVIRTUAL && "closeEntry".equals(getNameConstantOperand())
                && getClassConstantOperand().equals(streamType)) {
            bugReporter
                    .reportBug(new BugInstance(this,
                            "java/util/zip/ZipOutputStream".equals(streamType) ? "AM_CREATES_EMPTY_ZIP_FILE_ENTRY"
                                    : "AM_CREATES_EMPTY_JAR_FILE_ENTRY", NORMAL_PRIORITY).addClassAndMethod(this)
                                            .addSourceLine(this));
        }

    }

}
 
Example 5
Source File: OverridingEqualsNotSymmetrical.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean callToInvoke(int seen) {
    if (seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE || seen == Const.INVOKESPECIAL) {
        return invokesMethodWithEqualLikeName() && EQUALS_SIGNATURE.equals(getSigConstantOperand());
    }
    if (seen == Const.INVOKESTATIC) {
        String sig = getSigConstantOperand();
        return invokesMethodWithEqualLikeName() && sig.endsWith("Ljava/lang/Object;)Z");
    }

    return false;

}
 
Example 6
Source File: DismantleBytecode.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isMethodCall() {
    switch (opcode) {
    default:
        return false;
    case Const.INVOKEINTERFACE:
    case Const.INVOKESPECIAL:
    case Const.INVOKEVIRTUAL:
    case Const.INVOKESTATIC:
        return true;

    }
}
 
Example 7
Source File: IteratorIdioms.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Const.NEW && "java/util/NoSuchElementException".equals(getClassConstantOperand())) {
        sawNoSuchElement = true;
    } else if (seen == Const.INVOKESPECIAL || seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE) {
        sawCall = true;
        String name = getNameConstantOperand().toLowerCase();
        if (name.indexOf("next") >= 0
                || name.indexOf("previous") >= 0) {
            sawNoSuchElement = true;
        }
    }
}
 
Example 8
Source File: DumbMethods.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return index of stack entry that must be nonnegative.
 *
 * Return -1 if no stack entry is required to be nonnegative.
 */
private int stackEntryThatMustBeNonnegative(int seen) {
    switch (seen) {
    case Const.INVOKEINTERFACE:
        if ("java/util/List".equals(getClassConstantOperand())) {
            return getStackEntryOfListCallThatMustBeNonnegative();
        }
        break;
    case Const.INVOKEVIRTUAL:
        if ("java/util/LinkedList".equals(getClassConstantOperand())
                || "java/util/ArrayList".equals(getClassConstantOperand())) {
            return getStackEntryOfListCallThatMustBeNonnegative();
        }
        break;

    case Const.IALOAD:
    case Const.AALOAD:
    case Const.SALOAD:
    case Const.CALOAD:
    case Const.BALOAD:
    case Const.LALOAD:
    case Const.DALOAD:
    case Const.FALOAD:
        return 0;
    case Const.IASTORE:
    case Const.AASTORE:
    case Const.SASTORE:
    case Const.CASTORE:
    case Const.BASTORE:
    case Const.LASTORE:
    case Const.DASTORE:
    case Const.FASTORE:
        return 1;
    }
    return -1;
}
 
Example 9
Source File: DumbMethods.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Const.INVOKEVIRTUAL && "java/util/Random".equals(getClassConstantOperand())
            && (freshRandomOnTos || freshRandomOneBelowTos)) {
        accumulator.accumulateBug(new BugInstance(DumbMethods.this, "DMI_RANDOM_USED_ONLY_ONCE", HIGH_PRIORITY)
                .addClassAndMethod(DumbMethods.this).addCalledMethod(DumbMethods.this), DumbMethods.this);

    }
    freshRandomOneBelowTos = freshRandomOnTos && isRegisterLoad();
    freshRandomOnTos = seen == Const.INVOKESPECIAL && "java/util/Random".equals(getClassConstantOperand())
            && Const.CONSTRUCTOR_NAME.equals(getNameConstantOperand());
}
 
Example 10
Source File: FindUnreleasedLock.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private InvokeInstruction toInvokeInstruction(Instruction ins) {
    short opcode = ins.getOpcode();
    if (opcode != Const.INVOKEVIRTUAL && opcode != Const.INVOKEINTERFACE) {
        return null;
    }
    return (InvokeInstruction) ins;
}
 
Example 11
Source File: DumbMethods.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Const.INVOKEVIRTUAL && "java/util/concurrent/ScheduledThreadPoolExecutor".equals(getClassConstantOperand())
            && "setMaximumPoolSize".equals(getNameConstantOperand())) {
        accumulator.accumulateBug(new BugInstance(DumbMethods.this,
                "DMI_FUTILE_ATTEMPT_TO_CHANGE_MAXPOOL_SIZE_OF_SCHEDULED_THREAD_POOL_EXECUTOR", HIGH_PRIORITY)
                        .addClassAndMethod(DumbMethods.this), DumbMethods.this);
    }
}
 
Example 12
Source File: FieldSetAnalysis.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void handleInstruction(InstructionHandle handle, BasicBlock basicBlock, FieldSet fact) {
    Instruction ins = handle.getInstruction();
    short opcode = ins.getOpcode();
    XField field;

    switch (opcode) {
    case Const.GETFIELD:
    case Const.GETSTATIC:
        field = lookupField(handle, (FieldInstruction) ins);
        if (field != null) {
            sawLoad(fact, field);
        }
        break;

    case Const.PUTFIELD:
    case Const.PUTSTATIC:
        field = lookupField(handle, (FieldInstruction) ins);
        if (field != null) {
            sawStore(fact, field);
        }
        break;

    case Const.INVOKEINTERFACE:
    case Const.INVOKESPECIAL:
    case Const.INVOKESTATIC:
    case Const.INVOKEVIRTUAL:
        // Assume that the called method assigns loads and stores all
        // possible fields
        fact.setBottom();
        break;
    default:
        break;
    }
}
 
Example 13
Source File: BadSyntaxForRegularExpression.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (seen == Const.INVOKESTATIC && "java/util/regex/Pattern".equals(getClassConstantOperand())
            && "compile".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("(Ljava/lang/String;I)")) {
        sawRegExPattern(1, getIntValue(0, 0));
    } else if (seen == Const.INVOKESTATIC && "java/util/regex/Pattern".equals(getClassConstantOperand())
            && "compile".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) {
        sawRegExPattern(0);
    } else if (seen == Const.INVOKESTATIC && "java/util/regex/Pattern".equals(getClassConstantOperand())
            && "matches".equals(getNameConstantOperand())) {
        sawRegExPattern(1);
    } else if (seen == Const.INVOKEVIRTUAL && "java/lang/String".equals(getClassConstantOperand())
            && "replaceAll".equals(getNameConstantOperand())) {
        sawRegExPattern(1);
        singleDotPatternWouldBeSilly(1, true);
    } else if (seen == Const.INVOKEVIRTUAL && "java/lang/String".equals(getClassConstantOperand())
            && "replaceFirst".equals(getNameConstantOperand())) {
        sawRegExPattern(1);
        singleDotPatternWouldBeSilly(1, false);
    } else if (seen == Const.INVOKEVIRTUAL && "java/lang/String".equals(getClassConstantOperand())
            && "matches".equals(getNameConstantOperand())) {
        sawRegExPattern(0);
        singleDotPatternWouldBeSilly(0, false);
    } else if (seen == Const.INVOKEVIRTUAL && "java/lang/String".equals(getClassConstantOperand())
            && "split".equals(getNameConstantOperand())) {
        sawRegExPattern(0);
        singleDotPatternWouldBeSilly(0, false);
    }

}
 
Example 14
Source File: FindUninitializedGet.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (!inConstructor) {
        return;
    }
    if (uninitializedFieldReadAndCheckedForNonnull != null) {
        if (seen == Const.NEW && getClassConstantOperand().endsWith("Exception")) {
            uninitializedFieldReadAndCheckedForNonnull.raisePriority();
        }
        uninitializedFieldReadAndCheckedForNonnull = null;
    }

    if (seen == Const.ALOAD_0) {
        thisOnTOS = true;
        return;
    }

    if (seen == Const.PUTFIELD && getClassConstantOperand().equals(getClassName())) {
        initializedFields.add(FieldAnnotation.fromReferencedField(this));
    } else if (thisOnTOS && seen == Const.GETFIELD && getClassConstantOperand().equals(getClassName())) {
        UnreadFieldsData unreadFields = AnalysisContext.currentAnalysisContext().getUnreadFieldsData();
        XField xField = XFactory.createReferencedXField(this);
        FieldAnnotation f = FieldAnnotation.fromReferencedField(this);
        int nextOpcode = 0xff & codeBytes[getPC() + 3];
        if (nextOpcode != Const.POP && !initializedFields.contains(f) && declaredFields.contains(f) && !containerFields.contains(f)
                && !unreadFields.isContainerField(xField)) {
            // System.out.println("Next opcode: " +
            // Const.getOpcodeName(nextOpcode));
            LocalVariableAnnotation possibleTarget = LocalVariableAnnotation.findMatchingIgnoredParameter(getClassContext(),
                    getMethod(), getNameConstantOperand(), xField.getSignature());
            if (possibleTarget == null) {
                possibleTarget = LocalVariableAnnotation.findUniqueBestMatchingParameter(getClassContext(), getMethod(),
                        getNameConstantOperand(), getSigConstantOperand());
            }
            int priority = unreadFields.getReadFields().contains(xField) ? NORMAL_PRIORITY : LOW_PRIORITY;
            boolean priorityLoweredBecauseOfIfNonnullTest = false;
            if (possibleTarget != null) {
                priority--;
            } else {
                FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary();
                if (fieldSummary.callsOverriddenMethodsFromSuperConstructor(getClassDescriptor())) {
                    priority++;
                } else if (nextOpcode == Const.IFNONNULL) {
                    priority++;
                    priorityLoweredBecauseOfIfNonnullTest = true;
                }
            }

            BugInstance bug = new BugInstance(this, "UR_UNINIT_READ", priority).addClassAndMethod(this).addField(f)
                    .addOptionalAnnotation(possibleTarget).addSourceLine(this);
            pendingBugs.add(bug);
            if (priorityLoweredBecauseOfIfNonnullTest) {
                uninitializedFieldReadAndCheckedForNonnull = bug;
            }
            initializedFields.add(f);
        }
    } else if ((seen == Const.INVOKESPECIAL && !(Const.CONSTRUCTOR_NAME.equals(getNameConstantOperand()) && !getClassConstantOperand().equals(
            getClassName())))
            || (seen == Const.INVOKESTATIC && "doPrivileged".equals(getNameConstantOperand()) && "java/security/AccessController".equals(
                    getClassConstantOperand()))
            || (seen == Const.INVOKEVIRTUAL && getClassConstantOperand().equals(getClassName()))
            || (seen == Const.INVOKEVIRTUAL && "start".equals(getNameConstantOperand()))) {

        inConstructor = false;
    }

    thisOnTOS = false;
}
 
Example 15
Source File: WrongMapIterator.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    boolean loadedPreserved = false;
    if (isRegisterStore() && !isRegisterLoad()) {
        handleStore(getRegisterOperand());
    } else {
        switch (seen) {
        case Const.INVOKEINTERFACE:
        case Const.INVOKEVIRTUAL:
            if (!loadedVariable.none() &&
                    "keySet".equals(getNameConstantOperand()) && "()Ljava/util/Set;".equals(getSigConstantOperand())
                    // Following check solves sourceforge bug 1830576
                    && implementsMap(getClassDescriptorOperand())) {
                try {
                    LocationAndFactPair lfp = getClassContext().getTypeDataflow(getMethod()).getLocationAndFactForInstruction(
                            getPC());
                    // Skip EnumMap if TypeAnalysis knows that the type is EnumMap
                    if (lfp != null && lfp.frame.getTopValue().getSignature().equals("Ljava/util/EnumMap;")) {
                        break;
                    }
                } catch (DataflowAnalysisException | CFGBuilderException e) {
                    // ignore
                }
                mapVariable = loadedVariable;
                removedFromStack(true);
                keySetRegister = IN_STACK;
            } else if ((keySetRegister == IN_STACK || loadedVariable.isRegister(keySetRegister))
                    && "iterator".equals(getNameConstantOperand()) && "()Ljava/util/Iterator;".equals(getSigConstantOperand())) {
                removedFromStack(true);
                iteratorRegister = IN_STACK;
            } else if ((iteratorRegister == IN_STACK || loadedVariable.isRegister(iteratorRegister))
                    && "next".equals(getNameConstantOperand())
                    && "()Ljava/lang/Object;".equals(getSigConstantOperand())) {
                removedFromStack(true);
                keyRegister = IN_STACK;
            } else if (mapAndKeyLoaded && "get".equals(getNameConstantOperand())
                    && "(Ljava/lang/Object;)Ljava/lang/Object;".equals(getSigConstantOperand())) {
                MethodAnnotation ma = MethodAnnotation.fromVisitedMethod(this);
                bugAccumulator.accumulateBug(mapVariable
                        .annotate(new BugInstance(this, "WMI_WRONG_MAP_ITERATOR", NORMAL_PRIORITY).addClass(this).addMethod(ma)),
                        this);
                reset();
            } else if (("intValue".equals(getNameConstantOperand()) && "java/lang/Integer".equals(getClassConstantOperand())) ||
                    ("longValue".equals(getNameConstantOperand()) && "java/lang/Long".equals(getClassConstantOperand())) ||
                    ("doubleValue".equals(getNameConstantOperand()) && "java/lang/Double".equals(getClassConstantOperand())) ||
                    ("floatValue".equals(getNameConstantOperand()) && "java/lang/Float".equals(getClassConstantOperand()))) {
                removedFromStack(false);
            } else {
                removedFromStack(true);
            }
            break;
        case Const.INVOKESTATIC:
            if ("valueOf".equals(getNameConstantOperand())
                    && ("java/lang/Integer".equals(getClassConstantOperand())
                            || "java/lang/Long".equals(getClassConstantOperand())
                            || "java/lang/Double".equals(getClassConstantOperand()) || "java/lang/Float"
                                    .equals(getClassConstantOperand()))) {
                loadedPreserved = true;
            }
            removedFromStack(true);
            break;
        case Const.CHECKCAST:
            removedFromStack(false);
            break;
        default:
            removedFromStack(true);
        }
    }
    if (!loadedPreserved) {
        boolean mapLoaded = !loadedVariable.none() && loadedVariable.same(mapVariable);
        loadedVariable = loadedVariable.seen(seen);
        mapAndKeyLoaded = mapLoaded && loadedVariable.isRegister(keyRegister);
    }
}
 
Example 16
Source File: FindNonShortCircuit.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void scanForBooleanValue(int seen) {
    switch (seen) {

    case Const.IAND:
    case Const.IOR:
        switch (prevOpcode) {
        case Const.ILOAD:
        case Const.ILOAD_0:
        case Const.ILOAD_1:
        case Const.ILOAD_2:
        case Const.ILOAD_3:
            clearAll();
            break;
        default:
            break;
        }
        break;
    case Const.ICONST_1:
        stage1 = 1;
        switch (prevOpcode) {
        case Const.IFNONNULL:
        case Const.IFNULL:
            sawNullTest = true;
            break;
        case Const.IF_ICMPGT:
        case Const.IF_ICMPGE:
        case Const.IF_ICMPLT:
        case Const.IF_ICMPLE:
            sawNumericTest = true;
            break;
        }

        break;
    case Const.GOTO:
        if (stage1 == 1) {
            stage1 = 2;
        } else {
            stage1 = 0;
            clearAll();
        }
        break;
    case Const.ICONST_0:
        if (stage1 == 2) {
            sawBooleanValue();
        }
        stage1 = 0;
        break;
    case Const.INVOKEINTERFACE:
    case Const.INVOKEVIRTUAL:
    case Const.INVOKESPECIAL:
    case Const.INVOKESTATIC:
        String sig = getSigConstantOperand();
        if (sig.endsWith(")Z")) {
            sawBooleanValue();
        }
        stage1 = 0;
        break;
    default:
        stage1 = 0;
    }
}
 
Example 17
Source File: FindNoSideEffectMethods.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (!allowedFields.isEmpty() && seen == Const.PUTFIELD) {
        Item objItem = getStack().getStackItem(1);
        if (objItem.getRegisterNumber() == 0) {
            if (allowedFields.contains(getFieldDescriptorOperand())) {
                Item valueItem = getStack().getStackItem(0);
                if (!isNew(valueItem) && !valueItem.isNull()) {
                    allowedFields.remove(getFieldDescriptorOperand());
                }
            }
        }
    }
    if (status == SideEffectStatus.SIDE_EFFECT && allowedFields.isEmpty()) {
        // Nothing to do: skip the rest of the method
        throw new EarlyExitException();
    }
    if (status == SideEffectStatus.SIDE_EFFECT) {
        return;
    }
    switch (seen) {
    case Const.ASTORE:
    case Const.ASTORE_0:
    case Const.ASTORE_1:
    case Const.ASTORE_2:
    case Const.ASTORE_3:
        if (finallyTargets.contains(getPC())) {
            finallyExceptionRegisters.add(getRegisterOperand());
        }
        break;
    case Const.ATHROW: {
        Item exceptionItem = getStack().getStackItem(0);
        if (!finallyExceptionRegisters.remove(exceptionItem.getRegisterNumber())) {
            uselessVoidCandidate = false;
            try {
                JavaClass javaClass = exceptionItem.getJavaClass();
                if (javaClass != null && ALLOWED_EXCEPTIONS.contains(javaClass.getClassName())) {
                    break;
                }
            } catch (ClassNotFoundException e) {
            }
            status = SideEffectStatus.SIDE_EFFECT;
        }
        break;
    }
    case Const.PUTSTATIC:
        if (classInit) {
            if (getClassConstantOperand().equals(getClassName())) {
                break;
            }
        }
        status = SideEffectStatus.SIDE_EFFECT;
        break;
    case Const.INVOKEDYNAMIC:
        status = SideEffectStatus.SIDE_EFFECT;
        break;
    case Const.PUTFIELD:
        sawCall(getMethodCall(FIELD_STORE_STUB_METHOD), false);
        break;
    case Const.AASTORE:
    case Const.DASTORE:
    case Const.CASTORE:
    case Const.BASTORE:
    case Const.IASTORE:
    case Const.LASTORE:
    case Const.FASTORE:
    case Const.SASTORE:
        sawCall(getMethodCall(ARRAY_STORE_STUB_METHOD), false);
        break;
    case Const.INVOKESTATIC:
        if (changesOnlyNewObjects(getMethodDescriptorOperand())) {
            break;
        }
        sawCall(new MethodCall(getMethodDescriptorOperand(), TARGET_OTHER), false);
        break;
    case Const.INVOKESPECIAL:
    case Const.INVOKEINTERFACE:
    case Const.INVOKEVIRTUAL: {
        XMethod xMethodOperand = getXMethodOperand();
        MethodDescriptor methodDescriptorOperand = xMethodOperand == null ? getMethodDescriptorOperand()
                : xMethodOperand
                        .getMethodDescriptor();
        if (changesOnlyNewObjects(getMethodDescriptorOperand())) {
            break;
        }
        MethodCall methodCall = getMethodCall(methodDescriptorOperand);
        sawCall(methodCall, false);
        break;
    }
    default:
        break;
    }
}
 
Example 18
Source File: SuspiciousThreadInterrupted.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {

    if (state == SEEN_POSSIBLE_THREAD) {
        if (seen == Const.POP) {
            state = SEEN_UNKNOWNCONTEXT_POP;
            return;
        } else {
            state = SEEN_NOTHING;
        }
    }
    switch (state) {
    case SEEN_NOTHING:
        if ((seen == Const.INVOKESTATIC) && "java/lang/Thread".equals(getClassConstantOperand())
                && "currentThread".equals(getNameConstantOperand()) && "()Ljava/lang/Thread;".equals(getSigConstantOperand())) {
            state = SEEN_CURRENTTHREAD;
        } else if ((seen == Const.INVOKESTATIC || seen == Const.INVOKEINTERFACE || seen == Const.INVOKEVIRTUAL || seen == Const.INVOKESPECIAL)
                && getSigConstantOperand().endsWith("Ljava/lang/Thread;")) {
            state = SEEN_POSSIBLE_THREAD;
        } else if (seen == Const.ALOAD) {
            if (localsWithCurrentThreadValue.get(getRegisterOperand())) {
                state = SEEN_CURRENTTHREAD;
            } else {
                state = SEEN_POSSIBLE_THREAD;
            }
        } else if ((seen >= Const.ALOAD_0) && (seen <= Const.ALOAD_3)) {
            if (localsWithCurrentThreadValue.get(seen - Const.ALOAD_0)) {
                state = SEEN_CURRENTTHREAD;
            } else {
                state = SEEN_POSSIBLE_THREAD;
            }
        } else if ((seen == Const.GETFIELD || seen == Const.GETSTATIC) && "Ljava/lang/Thread;".equals(getSigConstantOperand())) {
            state = SEEN_POSSIBLE_THREAD;
        }
        break;

    case SEEN_CURRENTTHREAD:
        if (seen == Const.POP) {
            state = SEEN_POP_AFTER_CURRENTTHREAD;
        } else if (seen == Const.ASTORE) {
            localsWithCurrentThreadValue.set(getRegisterOperand());
            state = SEEN_NOTHING;
        } else if ((seen >= Const.ASTORE_0) && (seen <= Const.ASTORE_3)) {
            localsWithCurrentThreadValue.set(seen - Const.ASTORE_0);
            state = SEEN_NOTHING;
        } else {
            state = SEEN_NOTHING;
        }
        break;

    default:
        if ((seen == Const.INVOKESTATIC) && "java/lang/Thread".equals(getClassConstantOperand())
                && "interrupted".equals(getNameConstantOperand()) && "()Z".equals(getSigConstantOperand())) {
            if (state == SEEN_POP_AFTER_CURRENTTHREAD) {
                bugReporter.reportBug(new BugInstance(this, "STI_INTERRUPTED_ON_CURRENTTHREAD", LOW_PRIORITY)
                        .addClassAndMethod(this).addSourceLine(this));
            } else if (state == SEEN_UNKNOWNCONTEXT_POP) {
                bugReporter.reportBug(new BugInstance(this, "STI_INTERRUPTED_ON_UNKNOWNTHREAD", NORMAL_PRIORITY)
                        .addClassAndMethod(this).addSourceLine(this));
            }
        }
        state = SEEN_NOTHING;
        break;
    }
}
 
Example 19
Source File: InefficientToArray.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (DEBUG) {
        System.out.println("State: " + state + "  Opcode: " + Const.getOpcodeName(seen));
    }

    switch (state) {
    case SEEN_NOTHING:
        if (seen == Const.ICONST_0) {
            state = SEEN_ICONST_0;
        }
        break;

    case SEEN_ICONST_0:
        if (seen == Const.ANEWARRAY) {
            state = SEEN_ANEWARRAY;
        } else {
            state = SEEN_NOTHING;
        }
        break;

    case SEEN_ANEWARRAY:
        if (((seen == Const.INVOKEVIRTUAL) || (seen == Const.INVOKEINTERFACE)) && ("toArray".equals(getNameConstantOperand()))
                && ("([Ljava/lang/Object;)[Ljava/lang/Object;".equals(getSigConstantOperand()))) {
            try {
                String clsName = getDottedClassConstantOperand();
                JavaClass cls = Repository.lookupClass(clsName);
                if (cls.implementationOf(collectionClass)) {
                    bugAccumulator.accumulateBug(
                            new BugInstance(this, "ITA_INEFFICIENT_TO_ARRAY", LOW_PRIORITY).addClassAndMethod(this), this);
                }

            } catch (ClassNotFoundException cnfe) {
                bugReporter.reportMissingClass(cnfe);
            }
        }
        state = SEEN_NOTHING;
        break;

    default:
        state = SEEN_NOTHING;
        break;
    }
}
 
Example 20
Source File: INVOKEVIRTUAL.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
public INVOKEVIRTUAL(final int index) {
    super(Const.INVOKEVIRTUAL, index);
}