use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class ConfusingAutoboxedOverloading method visitClassContext.
/**
* overrides the visitor to look for confusing signatures
*
* @param classContext
* the context object that holds the JavaClass currently being parsed
*/
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass cls = classContext.getJavaClass();
if (cls.isClass() && (cls.getMajor() >= JDK15_MAJOR)) {
Map<String, Set<String>> methodInfo = new HashMap<>();
populateMethodInfo(cls, methodInfo);
Method[] methods = cls.getMethods();
for (Method m : methods) {
String name = m.getName();
String signature = m.getSignature();
Set<String> sigs = methodInfo.get(name);
if (sigs != null) {
for (String sig : sigs) {
if (confusingSignatures(sig, signature)) {
bugReporter.reportBug(new BugInstance(this, BugType.CAO_CONFUSING_AUTOBOXED_OVERLOADING.name(), NORMAL_PRIORITY).addClass(cls.getClassName()).addString(name + signature).addString(name + sig));
}
}
}
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class CopiedOverriddenMethod method visitCode.
/**
* overrides the visitor to find code blocks of methods that are the same as its parents
*
* @param obj
* the code object of the currently parsed method
*/
@Override
public void visitCode(Code obj) {
try {
Method m = getMethod();
if ((!m.isPublic() && !m.isProtected()) || m.isAbstract() || m.isSynthetic()) {
return;
}
CodeInfo superCode = superclassCode.remove(curMethodInfo);
if (superCode != null) {
if (sameAccess(getMethod().getAccessFlags(), superCode.getAccess()) && codeEquals(obj, superCode.getCode())) {
bugReporter.reportBug(new BugInstance(this, BugType.COM_COPIED_OVERRIDDEN_METHOD.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(classContext, this, getPC()));
return;
}
if ((getMethod().getAccessFlags() & Const.ACC_SYNCHRONIZED) != (superCode.getAccess() & Const.ACC_SYNCHRONIZED)) {
return;
}
parmTypes = getMethod().getArgumentTypes();
nextParmIndex = 0;
nextParmOffset = getMethod().isStatic() ? 0 : 1;
sawAload0 = nextParmOffset == 0;
sawParentCall = false;
super.visitCode(obj);
}
} catch (StopOpcodeParsingException e) {
// method is unique
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class LoggerOddities method visitCode.
/**
* implements the visitor to reset the stack
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
stack.resetForMethodEntry(this);
Method m = getMethod();
if (Values.CONSTRUCTOR.equals(m.getName())) {
for (String parmSig : SignatureUtils.getParameterSignatures(m.getSignature())) {
if (SignatureUtils.classToSignature(SLF4J_LOGGER).equals(parmSig) || SignatureUtils.classToSignature(LOG4J_LOGGER).equals(parmSig) || SignatureUtils.classToSignature(LOG4J2_LOGGER).equals(parmSig) || SignatureUtils.classToSignature(COMMONS_LOGGER).equals(parmSig)) {
bugReporter.reportBug(new BugInstance(this, BugType.LO_SUSPECT_LOG_PARAMETER.name(), NORMAL_PRIORITY).addClass(this).addMethod(this));
}
}
}
isStaticInitializer = Values.STATIC_INITIALIZER.equals(m.getName());
super.visitCode(obj);
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class MethodReturnsConstant method visitCode.
/**
* implements the visitor to reset the stack and proceed for private methods
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
Method m = getMethod();
if (overloadedMethods.contains(m)) {
return;
}
int aFlags = m.getAccessFlags();
if ((((aFlags & Const.ACC_PRIVATE) != 0) || ((aFlags & Const.ACC_STATIC) != 0)) && ((aFlags & Const.ACC_SYNTHETIC) == 0) && (!m.getSignature().endsWith(")Z"))) {
stack.resetForMethodEntry(this);
returnRegister = Values.NEGATIVE_ONE;
returnConstant = null;
registerConstants.clear();
returnPC = -1;
try {
super.visitCode(obj);
if ((returnConstant != null)) {
BugInstance bi = new BugInstance(this, BugType.MRC_METHOD_RETURNS_CONSTANT.name(), ((aFlags & Const.ACC_PRIVATE) != 0) ? NORMAL_PRIORITY : LOW_PRIORITY).addClass(this).addMethod(this);
if (returnPC >= 0) {
bi.addSourceLine(this, returnPC);
}
bi.addString(returnConstant.toString());
bugReporter.reportBug(bi);
}
} catch (StopOpcodeParsingException e) {
// method was not suspect
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class AbnormalFinallyBlockReturn method sawOpcode.
/**
* overrides the visitor to find return/exceptions from the finally block.
*
* @param seen
* the opcode that is being visited
*/
@Override
public void sawOpcode(int seen) {
FinallyBlockInfo fbi = fbInfo.get(0);
if (getPC() < fbi.startPC) {
return;
}
if (getPC() == fbi.startPC) {
if (OpcodeUtils.isAStore(seen)) {
fbi.exReg = RegisterUtils.getAStoreReg(this, seen);
} else {
removeEarliestFinallyBlock();
sawOpcode(seen);
return;
}
return;
}
if (seen == Const.MONITORENTER) {
fbi.monitorCount++;
} else if (seen == Const.MONITOREXIT) {
fbi.monitorCount--;
if (fbi.monitorCount < 0) {
removeEarliestFinallyBlock();
sawOpcode(seen);
return;
}
}
if ((seen == Const.ATHROW) && (loadedReg == fbi.exReg)) {
removeEarliestFinallyBlock();
sawOpcode(seen);
return;
} else if (OpcodeUtils.isALoad(seen)) {
loadedReg = RegisterUtils.getALoadReg(this, seen);
} else {
loadedReg = -1;
}
if (OpcodeUtils.isReturn(seen) || (seen == Const.ATHROW)) {
bugReporter.reportBug(new BugInstance(this, BugType.AFBR_ABNORMAL_FINALLY_BLOCK_RETURN.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
removeEarliestFinallyBlock();
} else if (OpcodeUtils.isStandardInvoke(seen)) {
try {
JavaClass cls = Repository.lookupClass(getClassConstantOperand());
Method m = findMethod(cls, getNameConstantOperand(), getSigConstantOperand());
if (m != null) {
ExceptionTable et = m.getExceptionTable();
if ((et != null) && (et.getLength() > 0) && !catchBlockInFinally(fbi)) {
bugReporter.reportBug(new BugInstance(this, BugType.AFBR_ABNORMAL_FINALLY_BLOCK_RETURN.name(), LOW_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
removeEarliestFinallyBlock();
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
}
Aggregations