use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class BogusExceptionDeclaration method sawOpcode.
/**
* implements the visitor to look for method calls that could throw the exceptions that are listed in the declaration.
*/
@Override
public void sawOpcode(int seen) {
try {
stack.precomputation(this);
if (OpcodeUtils.isStandardInvoke(seen)) {
String clsName = getClassConstantOperand();
if (!safeClasses.contains(clsName)) {
try {
JavaClass cls = Repository.lookupClass(clsName);
Method[] methods = cls.getMethods();
String methodName = getNameConstantOperand();
String signature = getSigConstantOperand();
boolean found = false;
for (Method m : methods) {
if (m.getName().equals(methodName) && m.getSignature().equals(signature)) {
if (isAnonymousInnerCtor(m, cls)) {
// constructors, so just clear if so
break;
}
ExceptionTable et = m.getExceptionTable();
if (et != null) {
String[] thrownExceptions = et.getExceptionNames();
for (String thrownException : thrownExceptions) {
removeThrownExceptionHierarchy(thrownException);
}
}
found = true;
break;
}
}
if (!found) {
clearExceptions();
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
clearExceptions();
}
} else if ("wait".equals(getNameConstantOperand())) {
removeException("java.lang.InterruptedException");
}
} else if (seen == Const.ATHROW) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
String exSig = item.getSignature();
String thrownException = SignatureUtils.stripSignature(exSig);
removeThrownExceptionHierarchy(thrownException);
} else {
clearExceptions();
}
}
} finally {
stack.sawOpcode(this, seen);
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class BuryingLogic method visitCode.
@Override
public void visitCode(Code obj) {
Method m = getMethod();
if (m.getReturnType() == Type.VOID) {
return;
}
stack.resetForMethodEntry(this);
ifBlocks.clear();
activeUnconditional = null;
CodeException[] ces = obj.getExceptionTable();
if (CollectionUtils.isEmpty(ces)) {
catchPCs = null;
} else {
catchPCs = new BitSet();
for (CodeException ce : ces) {
catchPCs.set(ce.getHandlerPC());
}
}
gotoBranchPCs.clear();
casePositions.clear();
lookingForResetOp = false;
try {
super.visitCode(obj);
} catch (StopOpcodeParsingException e) {
// reported an issue, so get out
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class FunctionalInterfaceIssues method visitClassContext.
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
if (cls.getMajor() >= Const.MAJOR_1_8) {
bootstrapAtt = getBootstrapAttribute(cls);
if (bootstrapAtt != null) {
stack = new OpcodeStack();
functionalInterfaceInfo = new HashMap<>();
super.visitClassContext(classContext);
for (Map.Entry<Method, List<FIInfo>> entry : functionalInterfaceInfo.entrySet()) {
for (FIInfo fii : entry.getValue()) {
}
}
}
}
} finally {
functionalInterfaceInfo = null;
bootstrapAtt = null;
stack = null;
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class CollectMethodsReturningImmutableCollections method visitCode.
/**
* overrides the visitor to reset the stack for the new method, then checks if the immutability field is set to immutable and if so reports it
*
* @param obj
* the context object of the currently parsed method
*/
@Override
public void visitCode(Code obj) {
try {
String signature = SignatureUtils.getReturnSignature(getMethod().getSignature());
if (signature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX) && CollectionUtils.isListSetMap(SignatureUtils.stripSignature(signature))) {
stack.resetForMethodEntry(this);
imType = ImmutabilityType.UNKNOWN;
super.visitCode(obj);
if ((imType == ImmutabilityType.IMMUTABLE) || (imType == ImmutabilityType.POSSIBLY_IMMUTABLE)) {
Method m = getMethod();
Statistics.getStatistics().addImmutabilityStatus(clsName, m.getName(), m.getSignature(), imType);
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
Aggregations