use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class MapUsageIssues method sawOpcode.
@Override
public void sawOpcode(int seen) {
try {
if (!mapContainsKeyUsed.isEmpty()) {
Iterator<Map.Entry<MapRef, ContainsKey>> it = mapContainsKeyUsed.entrySet().iterator();
int pc = getPC();
while (it.hasNext()) {
Map.Entry<MapRef, ContainsKey> entry = it.next();
if (!entry.getKey().isValid() || entry.getValue().outOfScope(pc)) {
it.remove();
}
}
}
// checking for a branch might be overkill, but for now lets go with it
if (!mapGetUsed.isEmpty() && OpcodeUtils.isBranch(seen)) {
Iterator<Map.Entry<MapRef, Get>> it = mapGetUsed.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<MapRef, Get> entry = it.next();
it.remove();
}
}
if ((seen == Const.IFNULL) || (seen == Const.IFNONNULL)) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
XMethod method = itm.getReturnValueOf();
if ((method != null) && (mapClass != null)) {
if (COLLECTION_ACCESSORS.contains(method.getName())) {
JavaClass cls = Repository.lookupClass(method.getClassName());
if (cls.implementationOf(mapClass)) {
bugReporter.reportBug(new BugInstance(this, BugType.MUI_NULL_CHECK_ON_MAP_SUBSET_ACCESSOR.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
}
}
}
}
} else if (seen == Const.INVOKEINTERFACE) {
FQMethod fqm = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand());
if (CONTAINS_METHOD.equals(fqm)) {
if (stack.getStackDepth() >= 2) {
OpcodeStack.Item item = stack.getStackItem(1);
if ((item.getRegisterNumber() < 0) && (item.getXField() == null)) {
XMethod xm = item.getReturnValueOf();
if ((xm != null) && COLLECTION_ACCESSORS.contains(xm.getName()) && Values.DOTTED_JAVA_UTIL_MAP.equals(xm.getClassName())) {
bugReporter.reportBug(new BugInstance(this, BugType.MUI_USE_CONTAINSKEY.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
}
}
}
} else if (CONTAINSKEY_METHOD.equals(fqm)) {
if (getNextOpcode() == Const.IFEQ) {
int ifEnd = getNextPC() + CodeByteUtils.getshort(getCode().getCode(), getNextPC() + 1);
if (stack.getStackDepth() >= 2) {
OpcodeStack.Item itm = stack.getStackItem(1);
mapContainsKeyUsed.put(new MapRef(itm), new ContainsKey(stack.getStackItem(0), ifEnd));
}
}
} else if (GET_METHOD.equals(fqm)) {
if (stack.getStackDepth() >= 2) {
OpcodeStack.Item itm = stack.getStackItem(1);
ContainsKey ck = mapContainsKeyUsed.remove(new MapRef(itm));
if ((ck != null) && new ContainsKey(stack.getStackItem(0), 0).equals(ck)) {
bugReporter.reportBug(new BugInstance(this, BugType.MUI_CONTAINSKEY_BEFORE_GET.name(), ck.getReportLevel()).addClass(this).addMethod(this).addSourceLine(this));
}
mapGetUsed.put(new MapRef(itm), new Get(stack.getStackItem(0)));
}
} else if (REMOVE_METHOD.equals(fqm)) {
if (stack.getStackDepth() >= 2) {
OpcodeStack.Item itm = stack.getStackItem(1);
Get get = mapGetUsed.remove(new MapRef(itm));
if ((get != null) && new Get(stack.getStackItem(0)).equals(get)) {
bugReporter.reportBug(new BugInstance(this, BugType.MUI_GET_BEFORE_REMOVE.name(), get.getReportLevel()).addClass(this).addMethod(this).addSourceLine(this));
}
}
}
QMethod qm = new QMethod(getNameConstantOperand(), getSigConstantOperand());
if (SIZE_METHOD.equals(qm)) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
if ((itm.getRegisterNumber() < 0) && (itm.getXField() == null)) {
XMethod xm = itm.getReturnValueOf();
if ((xm != null) && Values.DOTTED_JAVA_UTIL_MAP.equals(xm.getClassName()) && COLLECTION_ACCESSORS.contains(xm.getName())) {
bugReporter.reportBug(new BugInstance(this, BugType.MUI_CALLING_SIZE_ON_SUBCONTAINER.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
}
}
}
}
}
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
} finally {
stack.sawOpcode(this, seen);
}
}
use of org.apache.bcel.classfile.JavaClass 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.JavaClass in project fb-contrib by mebigfatguy.
the class AbstractClassEmptyMethods method visitClassContext.
/**
* overrides the visitor to check for abstract classes.
*
* @param classContext
* the context object that holds the JavaClass being parsed
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
if (cls.isAbstract()) {
interfaceMethods = collectInterfaceMethods(cls);
super.visitClassContext(classContext);
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
interfaceMethods = null;
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class AnnotationIssues method visitClassContext.
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
if (cls.getMajor() >= Const.MAJOR_1_5) {
if (isCollecting() || !cls.isAnonymous()) {
stack = new OpcodeStack();
assumedNullTill = new HashMap<>();
assumedNonNullTill = new HashMap<>();
noAssumptionsPossible = new HashSet<>();
super.visitClassContext(classContext);
}
}
} finally {
stack = null;
assumedNullTill = null;
assumedNonNullTill = null;
noAssumptionsPossible = null;
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class BackportReusePublicIdentifiers method visitClassContext.
/**
* overrides the visitor to make sure this is a 'modern' class better than 1.4
*
* @param classContext
* the currently parsed class
*/
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass cls = classContext.getJavaClass();
clsVersion = cls.getMajor();
super.visitClassContext(classContext);
}
Aggregations