use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method visitCode.
/**
* implements the visitor to collect information about the parameters of a this method
*
* @param obj
* the currently parsed code block
*/
@Override
public void visitCode(final Code obj) {
try {
if (methodSignatureIsConstrained) {
return;
}
if (obj.getCode() == null) {
return;
}
Method m = getMethod();
if (m.isSynthetic()) {
return;
}
if (m.getName().startsWith("access$")) {
return;
}
methodIsStatic = m.isStatic();
parmCount = m.getArgumentTypes().length;
if (parmCount == 0) {
return;
}
parameterDefiners.clear();
usedParameters.clear();
stack.resetForMethodEntry(this);
if (buildParameterDefiners()) {
try {
super.visitCode(obj);
reportBugs();
} catch (StopOpcodeParsingException e) {
// no more possible parameter definers
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method visitMethod.
/**
* implements the visitor to look to see if this method is constrained by a superclass or interface.
*
* @param obj
* the currently parsed method
*/
@Override
public void visitMethod(Method obj) {
methodSignatureIsConstrained = false;
String methodName = obj.getName();
if (!Values.CONSTRUCTOR.equals(methodName) && !Values.STATIC_INITIALIZER.equals(methodName)) {
String methodSig = obj.getSignature();
methodSignatureIsConstrained = methodIsSpecial(methodName, methodSig) || methodHasSyntheticTwin(methodName, methodSig);
if (!methodSignatureIsConstrained) {
for (AnnotationEntry entry : obj.getAnnotationEntries()) {
if (CONVERSION_ANNOTATIONS.contains(entry.getAnnotationType())) {
methodSignatureIsConstrained = true;
break;
}
}
}
if (!methodSignatureIsConstrained) {
String parms = methodSig.split("\\(|\\)")[1];
if (parms.indexOf(Values.SIG_QUALIFIED_CLASS_SUFFIX_CHAR) >= 0) {
outer: for (JavaClass constrainCls : constrainingClasses) {
Method[] methods = constrainCls.getMethods();
for (Method m : methods) {
if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) {
methodSignatureIsConstrained = true;
break outer;
}
}
}
}
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method getPublicMethodInfos.
/**
* returns a list of method information of all public or protected methods in this class
*
* @param cls
* the class to look for methods
* @return a map of (method name)(method signature)
*/
private static List<MethodInfo> getPublicMethodInfos(final JavaClass cls) {
List<MethodInfo> methodInfos = new ArrayList<>();
Method[] methods = cls.getMethods();
for (Method m : methods) {
if ((m.getAccessFlags() & (Const.ACC_PUBLIC | Const.ACC_PROTECTED)) != 0) {
ExceptionTable et = m.getExceptionTable();
methodInfos.add(new MethodInfo(m.getName(), m.getSignature(), et == null ? null : et.getExceptionNames()));
}
}
return methodInfos;
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class OverlyPermissiveMethod method isConstrainedByInterface.
/**
* looks to see if this method is an implementation of a method in an interface, including generic specified interface methods.
*
* @param fqMethod
* the method to check
* @return if this method is constrained by an interface method
*/
private boolean isConstrainedByInterface(FQMethod fqMethod) {
try {
JavaClass fqCls = Repository.lookupClass(fqMethod.getClassName());
if (fqCls.isInterface()) {
return true;
}
for (JavaClass inf : fqCls.getAllInterfaces()) {
for (Method infMethod : inf.getMethods()) {
if (infMethod.getName().equals(fqMethod.getMethodName())) {
String infMethodSig = infMethod.getSignature();
String fqMethodSig = fqMethod.getSignature();
if (infMethodSig.equals(fqMethodSig)) {
return true;
}
List<String> infTypes = SignatureUtils.getParameterSignatures(infMethodSig);
List<String> fqTypes = SignatureUtils.getParameterSignatures(fqMethodSig);
if (infTypes.size() == fqTypes.size()) {
boolean matches = true;
for (int i = 0; i < infTypes.size(); i++) {
String infParmType = infTypes.get(i);
String fqParmType = fqTypes.get(i);
if (infParmType.equals(fqParmType)) {
if ((infParmType.charAt(0) != 'L') || (fqParmType.charAt(0) != 'L')) {
matches = false;
break;
}
JavaClass infParmClass = Repository.lookupClass(SignatureUtils.stripSignature(infParmType));
JavaClass fqParmClass = Repository.lookupClass(SignatureUtils.stripSignature(fqParmType));
if (!fqParmClass.instanceOf(infParmClass)) {
matches = false;
break;
}
}
}
if (matches) {
return true;
}
}
}
}
}
return false;
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
return true;
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class PartiallyConstructedObjectAccess method sawOpcode.
@Override
public void sawOpcode(int seen) {
try {
stack.precomputation(this);
if ((seen == Const.INVOKEVIRTUAL) || (seen == Const.INVOKEINTERFACE) || (seen == Const.INVOKESPECIAL)) {
int parmCount = SignatureUtils.getNumParameters(getSigConstantOperand());
if (stack.getStackDepth() > parmCount) {
OpcodeStack.Item itm = stack.getStackItem(parmCount);
if (itm.getRegisterNumber() == 0) {
JavaClass cls = itm.getJavaClass();
if (cls != null) {
Method m = findMethod(cls, getNameConstantOperand(), getSigConstantOperand());
if ((m != null) && (!m.isFinal())) {
if (isCtor && (seen != Const.INVOKESPECIAL)) {
bugReporter.reportBug(new BugInstance(this, BugType.PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, getPC()));
throw new StopOpcodeParsingException();
} else {
if (!Values.CONSTRUCTOR.equals(m.getName())) {
Map<Method, SourceLineAnnotation> calledMethods = methodToCalledMethods.get(getMethod());
calledMethods.put(m, SourceLineAnnotation.fromVisitedInstruction(this));
}
}
}
}
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
stack.sawOpcode(this, seen);
}
}
Aggregations