use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class WeakExceptionMessaging method checkForWEM.
private void checkForWEM() throws ClassNotFoundException {
if (stack.getStackDepth() == 0) {
return;
}
OpcodeStack.Item item = stack.getStackItem(0);
if (item.getUserValue() == null) {
return;
}
JavaClass exClass = item.getJavaClass();
if ((exClass == null) || !ignorableExceptionTypes.contains(exClass.getClassName())) {
bugReporter.reportBug(new BugInstance(this, BugType.WEM_WEAK_EXCEPTION_MESSAGING.name(), LOW_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method buildParameterDefiners.
/**
* builds a map of method information for each method of each interface that each parameter implements of this method
*
* @return a map by parameter id of all the method signatures that interfaces of that parameter implements
*
* @throws ClassNotFoundException
* if the class can't be loaded
*/
private boolean buildParameterDefiners() throws ClassNotFoundException {
Method m = getMethod();
Type[] parms = m.getArgumentTypes();
if (parms.length == 0) {
return false;
}
ParameterAnnotationEntry[] annotations = m.getParameterAnnotationEntries();
boolean hasPossiblyOverlyConcreteParm = false;
for (int i = 0; i < parms.length; i++) {
if ((annotations.length <= i) || (annotations[i] == null) || (annotations[i].getAnnotationEntries().length == 0)) {
String parm = parms[i].getSignature();
if (parm.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX)) {
String clsName = SignatureUtils.stripSignature(parm);
if (clsName.startsWith("java.lang.")) {
continue;
}
JavaClass clz = Repository.lookupClass(clsName);
if (clz.isClass() && (!clz.isAbstract())) {
Map<JavaClass, List<MethodInfo>> definers = getClassDefiners(clz);
if (!definers.isEmpty()) {
parameterDefiners.put(Integer.valueOf(i + (methodIsStatic ? 0 : 1)), definers);
hasPossiblyOverlyConcreteParm = true;
}
}
}
}
}
return hasPossiblyOverlyConcreteParm;
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method removeUselessDefiners.
/**
* parses through the interface that 'may' define a parameter defined by reg, and look to see if we can rule it out, because a method is called on the
* object that can't be satisfied by the interface, if so remove that candidate interface.
*
* @param reg
* the parameter register number to look at
*/
private void removeUselessDefiners(final int reg) {
Map<JavaClass, List<MethodInfo>> definers = parameterDefiners.get(Integer.valueOf(reg));
if (CollectionUtils.isEmpty(definers)) {
return;
}
String methodSig = getSigConstantOperand();
String methodName = getNameConstantOperand();
MethodInfo methodInfo = new MethodInfo(methodName, methodSig);
Iterator<List<MethodInfo>> it = definers.values().iterator();
while (it.hasNext()) {
boolean methodDefined = false;
List<MethodInfo> methodSigs = it.next();
for (MethodInfo mi : methodSigs) {
if (methodInfo.equals(mi)) {
methodDefined = true;
String[] exceptions = mi.getMethodExceptions();
if (exceptions != null) {
for (String ex : exceptions) {
if (!isExceptionHandled(ex)) {
methodDefined = false;
break;
}
}
}
break;
}
}
if (!methodDefined) {
it.remove();
}
}
if (definers.isEmpty()) {
parameterDefiners.remove(Integer.valueOf(reg));
}
}
use of org.apache.bcel.classfile.JavaClass in project fb-contrib by mebigfatguy.
the class ParallelLists method visitClassContext.
@Override
public void visitClassContext(final ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
listFields = new HashSet<>();
Field[] flds = cls.getFields();
for (Field f : flds) {
String sig = f.getSignature();
if (sig.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX)) {
sig = SignatureUtils.trimSignature(sig);
if (sig.startsWith("java/util/") && sig.endsWith("List")) {
listFields.add(f.getName());
}
} else if (sig.startsWith(Values.SIG_ARRAY_PREFIX) && !sig.startsWith(Values.SIG_ARRAY_OF_ARRAYS_PREFIX)) {
listFields.add(f.getName());
}
}
if (!listFields.isEmpty()) {
stack = new OpcodeStack();
indexToFieldMap = new HashMap<>();
super.visitClassContext(classContext);
}
} finally {
stack = null;
indexToFieldMap = null;
}
}
use of org.apache.bcel.classfile.JavaClass 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);
}
}
}
}
Aggregations