use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class Section508Compliance method processSetSizeOps.
/**
* looks for calls to setSize on components, rather than letting the layout manager set them
*
* @param methodName
* the method that was called on a component
*
* @throws ClassNotFoundException
* if the gui class wasn't found
*/
private void processSetSizeOps(String methodName) throws ClassNotFoundException {
if ("setSize".equals(methodName)) {
int argCount = SignatureUtils.getNumParameters(getSigConstantOperand());
if ((windowClass != null) && (stack.getStackDepth() > argCount)) {
OpcodeStack.Item item = stack.getStackItem(argCount);
JavaClass cls = item.getJavaClass();
if ((cls != null) && cls.instanceOf(windowClass)) {
bugReporter.reportBug(new BugInstance(this, BugType.S508C_NO_SETSIZE.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
}
}
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class SluggishGui method visitCode.
/**
* overrides the visitor to segregate method into two, those that implement listeners, and those that don't. The ones that don't are processed first.
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
try {
for (JavaClass inf : guiInterfaces) {
Method[] methods = inf.getMethods();
for (Method m : methods) {
if (m.getName().equals(methodName) && m.getSignature().equals(methodSig)) {
listenerCode.put(obj, this.getMethod());
return;
}
}
}
isListenerMethod = false;
super.visitCode(obj);
} catch (StopOpcodeParsingException e) {
// method already reported
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class SpoiledChildInterfaceImplementor method filterSuperInterfaceMethods.
/**
* removes methods found in an interface when a super interface having the same methods is implemented in a parent. While this is somewhat hinky, we'll
* allow it.
*
* @param inf
* the interface to look for super interfaces for
* @param infMethods
* the remaining methods that are needed to be found
* @param cls
* the super class to look for these methods in
*/
private void filterSuperInterfaceMethods(JavaClass inf, Set<QMethod> infMethods, JavaClass cls) {
try {
if (infMethods.isEmpty()) {
return;
}
JavaClass[] superInfs = inf.getInterfaces();
for (JavaClass superInf : superInfs) {
if (cls.implementationOf(superInf)) {
Set<QMethod> superInfMethods = buildMethodSet(superInf);
infMethods.removeAll(superInfMethods);
if (infMethods.isEmpty()) {
return;
}
}
filterSuperInterfaceMethods(superInf, infMethods, cls);
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
infMethods.clear();
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class SpoiledChildInterfaceImplementor method visitClassContext.
/**
* looks for classes that implement interfaces but don't provide those methods
*
* @param classContext
* the context object of the currently parsed class
*/
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
if (cls.isAbstract() || cls.isInterface()) {
return;
}
if (Values.DOTTED_JAVA_LANG_OBJECT.equals(cls.getSuperclassName())) {
return;
}
JavaClass[] infs = cls.getInterfaces();
if (infs.length > 0) {
Set<QMethod> clsMethods = buildMethodSet(cls);
for (JavaClass inf : infs) {
Set<QMethod> infMethods = buildMethodSet(inf);
if (!infMethods.isEmpty()) {
infMethods.removeAll(clsMethods);
if (!infMethods.isEmpty()) {
JavaClass superCls = cls.getSuperClass();
filterSuperInterfaceMethods(inf, infMethods, superCls);
if (!infMethods.isEmpty() && !superCls.implementationOf(inf)) {
int priority = AnalysisContext.currentAnalysisContext().isApplicationClass(superCls) ? NORMAL_PRIORITY : LOW_PRIORITY;
BugInstance bi = new BugInstance(this, BugType.SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTOR.name(), priority).addClass(cls).addString("Implementing interface: " + inf.getClassName()).addString("Methods:");
for (QMethod methodInfo : infMethods) {
bi.addString('\t' + methodInfo.toString());
}
bugReporter.reportBug(bi);
return;
}
}
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class SpuriousThreadStates method sawOpcode.
@Override
public void sawOpcode(int seen) {
OpcodeStack.Item itm = null;
try {
stack.precomputation(this);
if (seen == INVOKEVIRTUAL) {
String className = getClassConstantOperand();
if (Values.SLASHED_JAVA_LANG_OBJECT.equals(className)) {
if (stack.getStackDepth() > 0) {
String methodName = getNameConstantOperand();
String signature = getSigConstantOperand();
if (("wait".equals(methodName) || "notify".equals(methodName) || "notifyAll".equals(methodName)) && SignatureBuilder.SIG_VOID_TO_VOID.equals(signature)) {
itm = stack.getStackItem(0);
} else if ("wait".equals(methodName)) {
if (SignatureBuilder.SIG_LONG_TO_VOID.equals(signature) && (stack.getStackDepth() > 1)) {
itm = stack.getStackItem(1);
} else if (SignatureBuilder.SIG_LONG_AND_INT_TO_VOID.equals(signature) && (stack.getStackDepth() > 2)) {
itm = stack.getStackItem(2);
}
}
}
if (itm != null) {
JavaClass cls = itm.getJavaClass();
boolean found = false;
if (cls != null) {
if ("java.lang.Thread".equals(cls.getClassName())) {
found = true;
} else {
JavaClass[] supers = cls.getSuperClasses();
for (JavaClass jc : supers) {
if ("java.lang.Thread".equals(jc.getClassName())) {
found = true;
break;
}
}
}
}
if (found) {
bugReporter.reportBug(new BugInstance(this, "STS_SPURIOUS_THREAD_STATES", NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
}
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
stack.sawOpcode(this, seen);
}
}
Aggregations