Search in sources :

Example 41 with Type

use of org.apache.bcel.generic.Type 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)

Example 42 with Type

use of org.apache.bcel.generic.Type in project fb-contrib by mebigfatguy.

the class ArrayIndexOutOfBounds method visitCode.

/**
 * overrides the visitor to collect parameter registers
 *
 * @param obj
 *            the code block of the currently parsed method
 */
@Override
public void visitCode(Code obj) {
    Method m = getMethod();
    stack.resetForMethodEntry(this);
    initializedRegs.clear();
    modifyRegs.clear();
    Type[] argTypes = m.getArgumentTypes();
    int arg = m.isStatic() ? 0 : 1;
    for (Type argType : argTypes) {
        String argSig = argType.getSignature();
        initializedRegs.set(arg);
        arg += SignatureUtils.getSignatureSize(argSig);
    }
    nullStoreToLocation.clear();
    super.visitCode(obj);
    for (Integer pc : nullStoreToLocation.values()) {
        bugReporter.reportBug(new BugInstance(this, BugType.AIOB_ARRAY_STORE_TO_NULL_REFERENCE.name(), HIGH_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, pc.intValue()));
    }
}
Also used : ConstantInteger(org.apache.bcel.classfile.ConstantInteger) BugType(com.mebigfatguy.fbcontrib.utils.BugType) Type(org.apache.bcel.generic.Type) BugInstance(edu.umd.cs.findbugs.BugInstance) Method(org.apache.bcel.classfile.Method)

Aggregations

Type (org.apache.bcel.generic.Type)42 BugType (com.mebigfatguy.fbcontrib.utils.BugType)9 ObjectType (org.apache.bcel.generic.ObjectType)9 FieldInstruction (org.apache.bcel.generic.FieldInstruction)8 InstructionHandle (org.apache.bcel.generic.InstructionHandle)8 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)8 JavaClass (org.apache.bcel.classfile.JavaClass)7 Instruction (org.apache.bcel.generic.Instruction)7 InstructionList (org.apache.bcel.generic.InstructionList)7 ReferenceType (org.apache.bcel.generic.ReferenceType)7 Method (org.apache.bcel.classfile.Method)6 GETFIELD (org.apache.bcel.generic.GETFIELD)6 PUTFIELD (org.apache.bcel.generic.PUTFIELD)6 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)5 MethodGen (org.apache.bcel.generic.MethodGen)5 BranchInstruction (org.apache.bcel.generic.BranchInstruction)4 GETSTATIC (org.apache.bcel.generic.GETSTATIC)4 LDC (org.apache.bcel.generic.LDC)4 LoadInstruction (org.apache.bcel.generic.LoadInstruction)4 PUTSTATIC (org.apache.bcel.generic.PUTSTATIC)4