use of org.apache.bcel.classfile.ParameterAnnotationEntry 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.ParameterAnnotationEntry in project fb-contrib by mebigfatguy.
the class JAXRSIssues method processJAXRSMethod.
private void processJAXRSMethod(Method m, String path, boolean hasConsumes) {
Type[] parmTypes = m.getArgumentTypes();
int numParms = parmTypes.length;
if (numParms > 0) {
boolean sawBareParm = false;
ParameterAnnotationEntry[] pes = m.getParameterAnnotationEntries();
int parmIndex = 0;
for (ParameterAnnotationEntry pe : pes) {
boolean foundParamAnnotation = false;
for (AnnotationEntry a : pe.getAnnotationEntries()) {
String annotationType = a.getAnnotationType();
if (PARAM_ANNOTATIONS.contains(annotationType)) {
foundParamAnnotation = true;
if ((path != null) && "Ljavax/ws/rs/PathParam;".equals(annotationType)) {
String parmPath = getDefaultAnnotationValue(a);
if ((parmPath != null) && (!path.matches(".*\\{" + parmPath + "\\b.*"))) {
bugReporter.reportBug(new BugInstance(this, BugType.JXI_PARM_PARAM_NOT_FOUND_IN_PATH.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Path param: " + parmPath));
}
} else if ("Ljavax/ws/rs/core/Context;".equals(annotationType)) {
String parmSig = parmTypes[parmIndex].getSignature();
if (!VALID_CONTEXT_TYPES.contains(parmSig)) {
bugReporter.reportBug(new BugInstance(this, BugType.JXI_INVALID_CONTEXT_PARAMETER_TYPE.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Parameter signature: " + parmSig));
}
}
}
}
if (!foundParamAnnotation) {
if ((!sawBareParm) && (hasConsumes || NATIVE_JAXRS_TYPES.contains(parmTypes[parmIndex].getSignature()))) {
sawBareParm = true;
} else {
bugReporter.reportBug(new BugInstance(this, BugType.JXI_UNDEFINED_PARAMETER_SOURCE_IN_ENDPOINT.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Parameter " + (parmIndex + 1)));
break;
}
}
parmIndex++;
}
}
}
Aggregations