Search in sources :

Example 1 with ParameterAnnotationEntry

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;
}
Also used : Type(org.apache.bcel.generic.Type) BugType(com.mebigfatguy.fbcontrib.utils.BugType) JavaClass(org.apache.bcel.classfile.JavaClass) ParameterAnnotationEntry(org.apache.bcel.classfile.ParameterAnnotationEntry) ArrayList(java.util.ArrayList) List(java.util.List) Method(org.apache.bcel.classfile.Method) ToString(com.mebigfatguy.fbcontrib.utils.ToString)

Example 2 with ParameterAnnotationEntry

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++;
        }
    }
}
Also used : BugType(com.mebigfatguy.fbcontrib.utils.BugType) Type(org.apache.bcel.generic.Type) ParameterAnnotationEntry(org.apache.bcel.classfile.ParameterAnnotationEntry) AnnotationEntry(org.apache.bcel.classfile.AnnotationEntry) BugInstance(edu.umd.cs.findbugs.BugInstance) ParameterAnnotationEntry(org.apache.bcel.classfile.ParameterAnnotationEntry)

Aggregations

BugType (com.mebigfatguy.fbcontrib.utils.BugType)2 ParameterAnnotationEntry (org.apache.bcel.classfile.ParameterAnnotationEntry)2 Type (org.apache.bcel.generic.Type)2 ToString (com.mebigfatguy.fbcontrib.utils.ToString)1 BugInstance (edu.umd.cs.findbugs.BugInstance)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)1 JavaClass (org.apache.bcel.classfile.JavaClass)1 Method (org.apache.bcel.classfile.Method)1