use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class AbstractOverriddenMethod method visitMethod.
/**
* overrides the visitor to find abstract methods that override concrete ones
*
* @param obj
* the context object of the currently parsed method
*/
@Override
public void visitMethod(Method obj) {
if (!obj.isAbstract())
return;
String methodName = obj.getName();
String methodSig = obj.getSignature();
outer: for (JavaClass cls : superClasses) {
Method[] methods = cls.getMethods();
for (Method m : methods) {
if (m.isPrivate() || m.isAbstract())
continue;
if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) {
BugInstance bug = new BugInstance(this, BugType.AOM_ABSTRACT_OVERRIDDEN_METHOD.name(), NORMAL_PRIORITY).addClass(this).addMethod(this);
Code code = obj.getCode();
if (code != null)
bug.addSourceLineRange(clsContext, this, 0, code.getLength() - 1);
bugReporter.reportBug(bug);
break outer;
}
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class AnnotationIssues method visitCode.
@Override
public void visitCode(Code obj) {
Method method = getMethod();
String sig = method.getSignature();
String returnType = sig.substring(sig.indexOf(')') + 1);
char returnTypeChar = returnType.charAt(0);
if ((returnTypeChar != 'L') && (returnTypeChar != '[')) {
return;
}
if (method.isSynthetic() && !isCollecting()) {
return;
}
if (Values.SIG_JAVA_LANG_VOID.equals(returnType)) {
return;
}
if (methodHasNullableAnnotation(method)) {
if (isCollecting()) {
MethodInfo methodInfo = Statistics.getStatistics().getMethodStatistics(getClassName(), method.getName(), method.getSignature());
methodInfo.setCanReturnNull(true);
}
return;
}
MethodInfo methodInfo = Statistics.getStatistics().getMethodStatistics(getClassName(), method.getName(), method.getSignature());
if (!isCollecting() && methodInfo.getCanReturnNull()) {
bugReporter.reportBug(new BugInstance(this, BugType.AI_ANNOTATION_ISSUES_NEEDS_NULLABLE.name(), LOW_PRIORITY).addClass(this).addMethod(this));
} else {
methodIsNullable = false;
stack.resetForMethodEntry(this);
assumedNullTill.clear();
assumedNonNullTill.clear();
noAssumptionsPossible.clear();
super.visitCode(obj);
if (methodIsNullable) {
if (isCollecting()) {
methodInfo.setCanReturnNull(true);
} else {
bugReporter.reportBug(new BugInstance(this, BugType.AI_ANNOTATION_ISSUES_NEEDS_NULLABLE.name(), LOW_PRIORITY).addClass(this).addMethod(this));
}
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class ArrayIndexOutOfBounds method visitCode.
/**
* overrides the visitor to collect parameter registers
*
* @param obj
* the code block of the currently parsed method
*/
@Override
public void visitCode(Code obj) {
Method m = getMethod();
stack.resetForMethodEntry(this);
initializedRegs.clear();
modifyRegs.clear();
Type[] argTypes = m.getArgumentTypes();
int arg = m.isStatic() ? 0 : 1;
for (Type argType : argTypes) {
String argSig = argType.getSignature();
initializedRegs.set(arg);
arg += SignatureUtils.getSignatureSize(argSig);
}
nullStoreToLocation.clear();
super.visitCode(obj);
for (Integer pc : nullStoreToLocation.values()) {
bugReporter.reportBug(new BugInstance(this, BugType.AIOB_ARRAY_STORE_TO_NULL_REFERENCE.name(), HIGH_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, pc.intValue()));
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class BloatedAssignmentScope method visitCode.
/**
* implements the visitor to reset the register to location map
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
try {
ignoreRegs.clear();
Method method = getMethod();
if (!method.isStatic()) {
ignoreRegs.set(0);
}
int[] parmRegs = RegisterUtils.getParameterRegisters(method);
for (int parm : parmRegs) {
ignoreRegs.set(parm);
}
rootScopeBlock = new ScopeBlock(0, obj.getLength());
tryBlocks.clear();
catchHandlers.clear();
CodeException[] exceptions = obj.getExceptionTable();
if (exceptions != null) {
for (CodeException ex : exceptions) {
tryBlocks.set(ex.getStartPC());
catchHandlers.set(ex.getHandlerPC());
}
}
switchTargets.clear();
stack.resetForMethodEntry(this);
dontReport = false;
sawDup = false;
sawNull = false;
super.visitCode(obj);
if (!dontReport) {
rootScopeBlock.findBugs(new HashSet<Integer>());
}
} finally {
rootScopeBlock = null;
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class BloatedSynchronizedBlock method visitCode.
/**
* implement the visitor to reset the sync count, the stack, and gather some information
*
* @param obj
* the context object for the currently parsed method
*/
@Override
public void visitCode(Code obj) {
Method m = getMethod();
if (prescreen(m)) {
if (m.isSynchronized()) {
syncPC = 0;
} else {
syncPC = -1;
}
isStatic = m.isStatic();
unsafeAliases.clear();
unsafeAliases.set(0);
branchInfo.clear();
unsafeCallOccurred = false;
stack.resetForMethodEntry(this);
}
}
Aggregations