use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class AbnormalFinallyBlockReturn method visitCode.
/**
* 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
}
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class BogusExceptionDeclaration method visitCode.
/**
* implements the visitor to see if the method declares that it throws any checked exceptions.
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
Method method = getMethod();
if (method.isSynthetic()) {
return;
}
declaredCheckedExceptions.clear();
stack.resetForMethodEntry(this);
ExceptionTable et = method.getExceptionTable();
if (et != null) {
if (classIsFinal || classIsAnonymous || method.isStatic() || method.isPrivate() || method.isFinal() || ((Values.CONSTRUCTOR.equals(method.getName()) && !isAnonymousInnerCtor(method, getThisClass())))) {
String[] exNames = et.getExceptionNames();
for (String exName : exNames) {
try {
JavaClass exCls = Repository.lookupClass(exName);
if (!exCls.instanceOf(runtimeExceptionClass)) {
declaredCheckedExceptions.add(exName);
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
if (!declaredCheckedExceptions.isEmpty()) {
try {
super.visitCode(obj);
if (!declaredCheckedExceptions.isEmpty()) {
BugInstance bi = new BugInstance(this, BugType.BED_BOGUS_EXCEPTION_DECLARATION.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, 0);
for (String ex : declaredCheckedExceptions) {
bi.addString(ex.replaceAll("/", "."));
}
bugReporter.reportBug(bi);
}
} catch (StopOpcodeParsingException e) {
// no exceptions left
}
}
}
String[] exNames = et.getExceptionNames();
for (int i = 0; i < (exNames.length - 1); i++) {
try {
JavaClass exCls1 = Repository.lookupClass(exNames[i]);
for (int j = i + 1; j < exNames.length; j++) {
JavaClass exCls2 = Repository.lookupClass(exNames[j]);
JavaClass childEx;
JavaClass parentEx;
if (exCls1.instanceOf(exCls2)) {
childEx = exCls1;
parentEx = exCls2;
} else if (exCls2.instanceOf(exCls1)) {
childEx = exCls2;
parentEx = exCls1;
} else {
continue;
}
if (!parentEx.equals(exceptionClass)) {
bugReporter.reportBug(new BugInstance(this, BugType.BED_HIERARCHICAL_EXCEPTION_DECLARATION.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString(childEx.getClassName() + " derives from " + parentEx.getClassName()));
return;
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class ConfusingFunctionSemantics method visitCode.
/**
* implements the visitor to look for any non-immutable typed parameters are assignable to the return type. If found, the method is parsed.
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
try {
possibleParmRegs.clear();
Method m = getMethod();
String methodSignature = m.getSignature();
String retSignature = SignatureUtils.getReturnSignature(methodSignature);
JavaClass returnClass = null;
int[] parmRegs = null;
if (retSignature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX) && !knownImmutables.contains(retSignature)) {
List<String> parmTypes = SignatureUtils.getParameterSignatures(methodSignature);
for (int p = 0; p < parmTypes.size(); p++) {
String parmSignature = parmTypes.get(p);
if (parmSignature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX) && !knownImmutables.contains(parmSignature)) {
if (returnClass == null) {
returnClass = Repository.lookupClass(SignatureUtils.trimSignature(retSignature));
parmRegs = RegisterUtils.getParameterRegisters(m);
}
if (parmRegs != null) {
JavaClass parmClass = Repository.lookupClass(SignatureUtils.stripSignature(parmSignature));
if (parmClass.instanceOf(returnClass)) {
possibleParmRegs.put(Integer.valueOf(parmRegs[p]), new ParmUsage());
}
}
}
}
if (!possibleParmRegs.isEmpty()) {
try {
stack.resetForMethodEntry(this);
super.visitCode(obj);
for (ParmUsage pu : possibleParmRegs.values()) {
if ((pu.returnPC >= 0) && (pu.alteredPC >= 0) && (pu.returnPC > pu.alteredPC)) {
bugReporter.reportBug(new BugInstance(this, BugType.CFS_CONFUSING_FUNCTION_SEMANTICS.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, pu.returnPC).addSourceLine(this, pu.alteredPC));
}
}
} catch (StopOpcodeParsingException e) {
// no parm regs left
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class SluggishGui method sawOpcode.
/**
* overrides the visitor to look for the execution of expensive calls
*
* @param seen
* the currently parsed opcode
*/
@Override
public void sawOpcode(int seen) {
if ((seen == INVOKEINTERFACE) || (seen == INVOKEVIRTUAL) || (seen == INVOKESPECIAL) || (seen == INVOKESTATIC)) {
String clsName = getClassConstantOperand();
String mName = getNameConstantOperand();
String methodInfo = clsName + ':' + mName;
String thisMethodInfo = (clsName.equals(getClassName())) ? (mName + ':' + methodSig) : "0";
if (expensiveCalls.contains(methodInfo) || expensiveThisCalls.contains(thisMethodInfo)) {
if (isListenerMethod) {
bugReporter.reportBug(new BugInstance(this, BugType.SG_SLUGGISH_GUI.name(), NORMAL_PRIORITY).addClass(this).addMethod(this.getClassContext().getJavaClass(), listenerCode.get(this.getCode())));
} else {
expensiveThisCalls.add(getMethodName() + ':' + getMethodSig());
}
throw new StopOpcodeParsingException();
}
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method visitCode.
/**
* implements the visitor to collect information about the parameters of a this method
*
* @param obj
* the currently parsed code block
*/
@Override
public void visitCode(final Code obj) {
try {
if (methodSignatureIsConstrained) {
return;
}
if (obj.getCode() == null) {
return;
}
Method m = getMethod();
if (m.isSynthetic()) {
return;
}
if (m.getName().startsWith("access$")) {
return;
}
methodIsStatic = m.isStatic();
parmCount = m.getArgumentTypes().length;
if (parmCount == 0) {
return;
}
parameterDefiners.clear();
usedParameters.clear();
stack.resetForMethodEntry(this);
if (buildParameterDefiners()) {
try {
super.visitCode(obj);
reportBugs();
} catch (StopOpcodeParsingException e) {
// no more possible parameter definers
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
Aggregations