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;
@Override public void visitCode(Code obj) { code = obj; super.visitCode(obj); CodeException[] exceptions = obj.getExceptionTable(); for (CodeException exception : exceptions) { exception.accept(this); } Attribute[] attributes = obj.getAttributes(); for (Attribute attribute : attributes) { attribute.accept(this); } visitAfter(obj); code = null; }
public Set<String> getSurroundingCaughtExceptions(int pc, int maxTryBlockSize) { HashSet<String> result = new HashSet<>(); if (code == null) { throw new IllegalStateException("Not visiting Code"); } int size = maxTryBlockSize; if (code.getExceptionTable() == null) { return result; } for (CodeException catchBlock : code.getExceptionTable()) { int startPC = catchBlock.getStartPC(); int endPC = catchBlock.getEndPC(); if (pc >= startPC && pc <= endPC) { int thisSize = endPC - startPC; if (size > thisSize) { result.clear(); size = thisSize; result.add("C" + catchBlock.getCatchType()); } else if (size == thisSize) { result.add("C" + catchBlock.getCatchType()); } } } return result; }
@Override public void visit(CodeException obj) { int type = obj.getCatchType(); if (type == 0) { return; } String name = getConstantPool().constantToString(getConstantPool().getConstant(type)); if (DEBUG) { String msg = "Catching " + name + " in " + getFullyQualifiedMethodName(); if (msgs.add(msg)) { System.out.println(msg); } } if ("java.lang.IllegalMonitorStateException".equals(name)) { bugReporter.reportBug(new BugInstance(this, "IMSE_DONT_CATCH_IMSE", HIGH_PRIORITY).addClassAndMethod(this) .addSourceLine(this.classContext, this, obj.getHandlerPC())); } }
/** * adds optionalRanges for all try/catch blocks * * @param c * the currently parsed code object */ private void addExceptionRanges(Code c) { Map<CodeRange, List<Integer>> ranges = new HashMap<>(); CodeException[] ces = c.getExceptionTable(); if (ces != null) { for (CodeException ce : ces) { CodeRange range = new CodeRange(ce.getStartPC(), ce.getEndPC(), false); List<Integer> handlers = ranges.get(range); if (handlers == null) { handlers = new ArrayList<>(6); ranges.put(range, handlers); } handlers.add(ce.getHandlerPC()); } } for (Map.Entry<CodeRange, List<Integer>> entry : ranges.entrySet()) { optionalRanges.add(entry.getKey()); List<Integer> handlers = entry.getValue(); Collections.sort(handlers); for (int h = 0; h < (handlers.size() - 1); h++) { optionalRanges.add(new CodeRange(handlers.get(h), handlers.get(h + 1), false)); } } }
/** * overrides the visitor to collect finally block info. * * @param obj * the code object to scan for finally blocks */ @Override public void visitCode(Code obj) { fbInfo.clear(); loadedReg = -1; CodeException[] exc = obj.getExceptionTable(); if (exc != null) { for (CodeException ce : exc) { if ((ce.getCatchType() == 0) && (ce.getStartPC() == ce.getHandlerPC())) { fbInfo.add(new FinallyBlockInfo(ce.getStartPC())); } } } if (!fbInfo.isEmpty()) { try { super.visitCode(obj); } catch (StopOpcodeParsingException e) { // no more finally blocks to check } } }
/** * returns the catch handler for a given try block * * @param pc * the current instruction * @return the pc of the handler for this pc if it's the start of a try block, or -1 * */ private int findCatchHandlerFor(int pc) { CodeException[] exceptions = getMethod().getCode().getExceptionTable(); if (exceptions != null) { for (CodeException ex : exceptions) { if (ex.getStartPC() == pc) { return ex.getHandlerPC(); } } } return -1; }
public int[] getExceptionScope(){ try { CodeException[] exceptionTable = this.code.getExceptionTable(); int[] exception_scop = new int[exceptionTable.length * 2]; for (int i = 0; i < exceptionTable.length; i++) { exception_scop[i * 2] = exceptionTable[i].getStartPC(); exception_scop[i * 2 + 1] = exceptionTable[i].getEndPC(); } return exception_scop; }catch (Exception e){ // e.printStackTrace(); } return new int[0]; }
/** * implements the visitor to reset the stack, and method call maps for new method Note: that when collecting branch targets, it's unfortunately not good * enough to just collect the handler pcs, as javac plays fast and loose, and will sometimes jam code below the end pc and before the first handler pc, * which gets executed. So we need to clear our maps if we go past the end pc as well. * * @param obj * the context object of the currently parsed code block */ @Override public void visitCode(Code obj) { stack.resetForMethodEntry(this); localMethodCalls.clear(); fieldMethodCalls.clear(); staticMethodCalls.clear(); branchTargets.clear(); CodeException[] codeExceptions = obj.getExceptionTable(); for (CodeException codeEx : codeExceptions) { // adding the end pc seems silly, but it is need because javac may repeat // part of the finally block in the try block, at times. branchTargets.set(codeEx.getEndPC()); branchTargets.set(codeEx.getHandlerPC()); } super.visitCode(obj); }
public boolean atCatchBlock() { for (CodeException e : getCode().getExceptionTable()) { if (e.getHandlerPC() == getPC()) { return true; } } return false; }
public static String getExceptionSig(DismantleBytecode dbc, CodeException e) { if (e.getCatchType() == 0) { return "Ljava/lang/Throwable;"; } Constant c = dbc.getConstantPool().getConstant(e.getCatchType()); if (c instanceof ConstantClass) { return "L" + ((ConstantClass) c).getBytes(dbc.getConstantPool()) + ";"; } return "Ljava/lang/Throwable;"; }
public ExceptionHandlers(Code code) { CodeException previousCodeException= null; for (CodeException codeException : code.getExceptionTable()) { if (previousCodeException != null && previousCodeException.getHandlerPC() == codeException.getHandlerPC()) { previousCodeException.setEndPC(codeException.getEndPC()); } else { add(new ExceptionHandler(codeException)); } previousCodeException= codeException; } } }
if (tryBlock != null && tryBlock.getEndPC() == getPC()) { pendingBug.lowerPriority();
public int getStartPC() { return codeException.getStartPC(); }
if (ce.getCatchType() > 0) Constant constant= constantPool.getConstant(ce.getCatchType()); exceptionType= Pass1.constantToString(constant, constantPool); System.out.println(ce.toString() + " " + exceptionType);
} catch (IOException e) { Log.e(TAG, e.getMessage(), e); throw new CodeException("Error: could not establish connection to server.");
public final String toString(ConstantPool cp) { return toString(cp, true); }
public static @CheckForNull CodeException getSurroundingTryBlock(ConstantPool constantPool, Code code, @CheckForNull String vmNameOfExceptionClass, int pc) { int size = Integer.MAX_VALUE; if (code.getExceptionTable() == null) { return null; } CodeException result = null; for (CodeException catchBlock : code.getExceptionTable()) { if (vmNameOfExceptionClass != null) { Constant catchType = constantPool.getConstant(catchBlock.getCatchType()); if (catchType == null && !vmNameOfExceptionClass.isEmpty() || catchType instanceof ConstantClass && !((ConstantClass) catchType).getBytes(constantPool).equals(vmNameOfExceptionClass)) { continue; } } int startPC = catchBlock.getStartPC(); int endPC = catchBlock.getEndPC(); if (pc >= startPC && pc <= endPC) { int thisSize = endPC - startPC; if (size > thisSize) { size = thisSize; result = catchBlock; } } } return result; }
/** * adds optionalRanges for all try/catch blocks * * @param c * the currently parsed code object */ private void addExceptionRanges(Code c) { Map<CodeRange, List<Integer>> ranges = new HashMap<>(); CodeException[] ces = c.getExceptionTable(); if (ces != null) { for (CodeException ce : ces) { CodeRange range = new CodeRange(ce.getStartPC(), ce.getEndPC(), false); List<Integer> handlers = ranges.get(range); if (handlers == null) { handlers = new ArrayList<>(6); ranges.put(range, handlers); } handlers.add(ce.getHandlerPC()); } } for (Map.Entry<CodeRange, List<Integer>> entry : ranges.entrySet()) { optionalRanges.add(entry.getKey()); List<Integer> handlers = entry.getValue(); Collections.sort(handlers); for (int h = 0; h < (handlers.size() - 1); h++) { optionalRanges.add(new CodeRange(handlers.get(h), handlers.get(h + 1), false)); } } }
if (e.getCatchType() == 0) { int pc = e.getHandlerPC(); firstHandler = Math.min(firstHandler, pc); if (jumpInfo != null) {