Java Code Examples for org.apache.bcel.Const#POP
The following examples show how to use
org.apache.bcel.Const#POP .
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: FindUninitializedGet.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@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 2
Source File: SuspiciousThreadInterrupted.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@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 3
Source File: ReadReturnShouldBeChecked.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { if (seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE) { lastCallClass = getDottedClassConstantOperand(); lastCallMethod = getNameConstantOperand(); lastCallSig = getSigConstantOperand(); } if (seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE) { if ("available".equals(getNameConstantOperand()) && "()I".equals(getSigConstantOperand()) || getNameConstantOperand().startsWith("get") && getNameConstantOperand().endsWith("Length") && "()I".equals(getSigConstantOperand()) || "java/io/File".equals(getClassConstantOperand()) && "length".equals(getNameConstantOperand()) && "()J".equals(getSigConstantOperand())) { sawAvailable = 70; return; } } sawAvailable--; if ((seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE) && "read".equals(getNameConstantOperand()) && ("([B)I".equals(getSigConstantOperand()) || "([BII)I".equals(getSigConstantOperand()) || "([C)I".equals(getSigConstantOperand()) || "([CII)I".equals(getSigConstantOperand())) && isInputStream()) { sawRead = true; recentCallToAvailable = sawAvailable > 0; locationOfCall = getPC(); return; } if ((seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE) && ("skip".equals(getNameConstantOperand()) && "(J)J".equals(getSigConstantOperand()) || "skipBytes".equals(getNameConstantOperand()) && "(I)I".equals(getSigConstantOperand())) && isInputStream() && !isImageIOInputStream()) { // if not ByteArrayInput Stream // and either no recent calls to length // or it is a BufferedInputStream wasBufferedInputStream = isBufferedInputStream(); sawSkip = true; locationOfCall = getPC(); recentCallToAvailable = sawAvailable > 0 && !wasBufferedInputStream; return; } if ((seen == Const.POP) || (seen == Const.POP2)) { if (sawRead) { accumulator.accumulateBug( new BugInstance(this, "RR_NOT_CHECKED", recentCallToAvailable ? LOW_PRIORITY : NORMAL_PRIORITY) .addClassAndMethod(this).addCalledMethod(lastCallClass, lastCallMethod, lastCallSig, false), SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, locationOfCall)); } else if (sawSkip) { accumulator.accumulateBug( new BugInstance(this, "SR_NOT_CHECKED", (wasBufferedInputStream ? HIGH_PRIORITY : recentCallToAvailable ? LOW_PRIORITY : NORMAL_PRIORITY)).addClassAndMethod(this) .addCalledMethod(lastCallClass, lastCallMethod, lastCallSig, false), SourceLineAnnotation .fromVisitedInstruction(getClassContext(), this, locationOfCall)); } } sawRead = false; sawSkip = false; }
Example 4
Source File: MethodReturnCheck.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isPop(int seen) { return seen == Const.POP || seen == Const.POP2; }