use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class PartiallyConstructedObjectAccess method reportChainedMethods.
private void reportChainedMethods() {
Set<Method> checkedMethods = new HashSet<>();
JavaClass cls = getClassContext().getJavaClass();
for (Map.Entry<Method, Map<Method, SourceLineAnnotation>> entry : methodToCalledMethods.entrySet()) {
Method m = entry.getKey();
if (Values.CONSTRUCTOR.equals(m.getName())) {
checkedMethods.clear();
Deque<SourceLineAnnotation> slas = foundPrivateInChain(m, checkedMethods);
if (slas != null) {
BugInstance bi = new BugInstance(this, BugType.PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS.name(), LOW_PRIORITY).addClass(cls).addMethod(cls, m);
for (SourceLineAnnotation sla : slas) {
bi.addSourceLine(sla);
}
bugReporter.reportBug(bi);
}
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class MisleadingOverloadModel method visitClassContext.
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass cls = classContext.getJavaClass();
String clsName = cls.getClassName();
Method[] methods = cls.getMethods();
Map<String, MethodFoundType> declMethods = new HashMap<>(methods.length);
for (Method m : methods) {
String methodName = m.getName();
boolean report;
MethodFoundType newType;
if (m.isStatic()) {
report = declMethods.get(methodName) == MethodFoundType.Instance;
if (report) {
newType = MethodFoundType.Both;
} else {
newType = MethodFoundType.Static;
}
} else {
report = declMethods.get(m.getName()) == MethodFoundType.Static;
if (report) {
newType = MethodFoundType.Both;
} else {
newType = MethodFoundType.Instance;
}
}
declMethods.put(methodName, newType);
if (report) {
bugReporter.reportBug(new BugInstance(this, BugType.MOM_MISLEADING_OVERLOAD_MODEL.name(), NORMAL_PRIORITY).addClass(cls).addMethod(XFactory.createXMethod(clsName, m)).addString(methodName));
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OCSDebugger method visitCode.
@Override
public void visitCode(Code obj) {
Method m = getMethod();
String curMethodDesc = getClassContext().getJavaClass().getClassName() + '.' + m.getName() + m.getSignature();
if (curMethodDesc.equals(METHOD_DESC)) {
try {
pw = new PrintWriter(OUTPUT_FILE_NAME, StandardCharsets.UTF_8.name());
stack.resetForMethodEntry(this);
super.visitCode(obj);
} catch (IOException e) {
// ignore
} finally {
pw.close();
pw = null;
}
}
}
use of org.apache.bcel.classfile.Method 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 org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class CloneUsability method visitCode.
/**
* overrides the visitor to grab the method name and reset the state.
*
* @param obj
* the method being parsed
*/
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "FCBL_FIELD_COULD_BE_LOCAL", justification = "False positives occur when state is maintained across callbacks")
@Override
public void visitCode(Code obj) {
try {
Method m = getMethod();
if (m.isPublic() && !m.isSynthetic() && "clone".equals(m.getName()) && (m.getArgumentTypes().length == 0)) {
String returnClsName = m.getReturnType().getSignature();
returnClsName = SignatureUtils.stripSignature(returnClsName);
if (!clsName.equals(returnClsName)) {
if (Values.DOTTED_JAVA_LANG_OBJECT.equals(returnClsName)) {
bugReporter.reportBug(new BugInstance(this, BugType.CU_CLONE_USABILITY_OBJECT_RETURN.name(), NORMAL_PRIORITY).addClass(this).addMethod(this));
} else {
JavaClass clonedClass = Repository.lookupClass(returnClsName);
if (!cls.instanceOf(clonedClass)) {
bugReporter.reportBug(new BugInstance(this, BugType.CU_CLONE_USABILITY_MISMATCHED_RETURN.name(), HIGH_PRIORITY).addClass(this).addMethod(this));
}
}
}
ExceptionTable et = m.getExceptionTable();
if ((et != null) && (et.getLength() > 0)) {
throwsCNFE = false;
if (prescreen(m)) {
stack.resetForMethodEntry(this);
super.visitCode(obj);
}
if (!throwsCNFE) {
bugReporter.reportBug(new BugInstance(this, BugType.CU_CLONE_USABILITY_THROWS.name(), NORMAL_PRIORITY).addClass(this).addMethod(this));
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
Aggregations