Java Code Examples for org.apache.bcel.classfile.CodeException#getHandlerPC()

The following examples show how to use org.apache.bcel.classfile.CodeException#getHandlerPC() . 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: DismantleBytecode.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean atCatchBlock() {
    for (CodeException e : getCode().getExceptionTable()) {
        if (e.getHandlerPC() == getPC()) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: DumbMethods.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Flush out cached state at the end of a method.
 */
private void flush() {

    if (pendingAbsoluteValueBug != null) {
        absoluteValueAccumulator.accumulateBug(pendingAbsoluteValueBug, pendingAbsoluteValueBugSourceLine);
        pendingAbsoluteValueBug = null;
        pendingAbsoluteValueBugSourceLine = null;
    }
    accumulator.reportAccumulatedBugs();
    if (sawLoadOfMinValue) {
        absoluteValueAccumulator.clearBugs();
    } else {
        absoluteValueAccumulator.reportAccumulatedBugs();
    }
    if (gcInvocationBugReport != null && !sawCurrentTimeMillis) {
        // Make sure the GC invocation is not in an exception handler
        // for OutOfMemoryError.
        boolean outOfMemoryHandler = false;
        for (CodeException handler : exceptionTable) {
            if (gcInvocationPC < handler.getHandlerPC() || gcInvocationPC > handler.getHandlerPC() + OOM_CATCH_LEN) {
                continue;
            }
            int catchTypeIndex = handler.getCatchType();
            if (catchTypeIndex > 0) {
                ConstantPool cp = getThisClass().getConstantPool();
                Constant constant = cp.getConstant(catchTypeIndex);
                if (constant instanceof ConstantClass) {
                    String exClassName = (String) ((ConstantClass) constant).getConstantValue(cp);
                    if ("java/lang/OutOfMemoryError".equals(exClassName)) {
                        outOfMemoryHandler = true;
                        break;
                    }
                }
            }
        }

        if (!outOfMemoryHandler) {
            bugReporter.reportBug(gcInvocationBugReport);
        }
    }

    sawCurrentTimeMillis = false;
    gcInvocationBugReport = null;

    exceptionTable = null;
}
 
Example 3
Source File: NullDerefAndRedundantComparisonFinder.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Examine redundant branches.
 */
private void examineRedundantBranches() {
    for (RedundantBranch redundantBranch : redundantBranchList) {
        if (DEBUG) {
            System.out.println("Redundant branch: " + redundantBranch);
        }
        int lineNumber = redundantBranch.lineNumber;

        // The source to bytecode compiler may sometimes duplicate blocks of
        // code along different control paths. So, to report the bug,
        // we check to ensure that the branch is REALLY determined each
        // place it is duplicated, and that it is determined in the same
        // way.

        boolean confused = undeterminedBranchSet.get(lineNumber)
                || (definitelySameBranchSet.get(lineNumber) && definitelyDifferentBranchSet.get(lineNumber));

        // confused if there is JSR confusion or multiple null checks with
        // different results on the same line

        boolean reportIt = true;

        if (lineMentionedMultipleTimes.get(lineNumber) && confused) {
            reportIt = false;
        } else if (redundantBranch.location.getBasicBlock().isInJSRSubroutine() /*
                                                                                * occurs
                                                                                * in
                                                                                * a
                                                                                * JSR
                                                                                */
                && confused) {
            reportIt = false;
        } else {
            int pc = redundantBranch.location.getHandle().getPosition();
            for (CodeException e : method.getCode().getExceptionTable()) {
                if (e.getCatchType() == 0 && e.getStartPC() != e.getHandlerPC() && e.getEndPC() <= pc
                        && pc <= e.getEndPC() + 5) {
                    reportIt = false;
                }
            }
        }

        if (reportIt) {
            collector.foundRedundantNullCheck(redundantBranch.location, redundantBranch);
        }
    }
}