Search in sources :

Example 71 with OpcodeStack

use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.

the class WiringIssues method visitClassContext.

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "Only a few cases need special handling")
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        JavaClass cls = classContext.getJavaClass();
        Field[] fields = cls.getFields();
        if (fields.length > 0) {
            Map<WiringType, FieldAnnotation> wiredFields = new HashMap<>();
            boolean loadedParents = false;
            for (Field field : fields) {
                boolean hasAutowired = false;
                String qualifier = "";
                for (AnnotationEntry entry : field.getAnnotationEntries()) {
                    switch(entry.getAnnotationType()) {
                        case SPRING_AUTOWIRED:
                            if (!loadedParents) {
                                loadParentAutowireds(cls.getSuperClass(), wiredFields);
                                loadedParents = true;
                            }
                            hasAutowired = true;
                            break;
                        case SPRING_QUALIFIER:
                            qualifier = entry.getElementValuePairs()[0].getValue().stringifyValue();
                            break;
                    }
                }
                if (hasAutowired) {
                    WiringType wt = new WiringType(field.getSignature(), field.getGenericSignature(), qualifier);
                    FieldAnnotation existingAnnotation = wiredFields.get(wt);
                    if (existingAnnotation == null) {
                        wiredFields.put(wt, FieldAnnotation.fromBCELField(cls.getClassName(), field));
                    } else {
                        bugReporter.reportBug(new BugInstance(this, BugType.WI_DUPLICATE_WIRED_TYPES.name(), NORMAL_PRIORITY).addClass(cls).addField(FieldAnnotation.fromBCELField(cls, field)).addField(existingAnnotation));
                        wiredFields.remove(wt);
                    }
                }
            }
        }
        stack = new OpcodeStack();
        super.visitClassContext(classContext);
    } catch (ClassNotFoundException e) {
        bugReporter.reportMissingClass(e);
    } finally {
        stack = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) HashMap(java.util.HashMap) BugInstance(edu.umd.cs.findbugs.BugInstance) ToString(com.mebigfatguy.fbcontrib.utils.ToString) Field(org.apache.bcel.classfile.Field) AnnotationEntry(org.apache.bcel.classfile.AnnotationEntry) JavaClass(org.apache.bcel.classfile.JavaClass) FieldAnnotation(edu.umd.cs.findbugs.FieldAnnotation)

Example 72 with OpcodeStack

use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.

the class DubiousSetOfCollections method visitClassContext.

/**
 * implement the visitor to set up the opcode stack, and make sure that collection, set and map classes could be loaded.
 *
 * @param clsContext
 *            the context object of the currently parsed class
 */
@Override
public void visitClassContext(ClassContext clsContext) {
    try {
        if ((collectionCls == null) || (setCls == null) || (mapCls == null)) {
            return;
        }
        stack = new OpcodeStack();
        super.visitClassContext(clsContext);
    } finally {
        stack = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack)

Example 73 with OpcodeStack

use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.

the class ExceptionSoftening method visitClassContext.

/**
 * overrides the visitor to reset the stack
 *
 * @param classContext
 *            the context object of the currently parsed class
 */
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        if (runtimeClass != null) {
            stack = new OpcodeStack();
            super.visitClassContext(classContext);
        }
    } finally {
        stack = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack)

Example 74 with OpcodeStack

use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.

the class InvalidConstantArgument method visitClassContext.

/**
 * overrides the visitor to initialize the opcode stack
 *
 * @param classContext
 *            the context of the currently parsed class
 */
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        stack = new OpcodeStack();
        super.visitClassContext(classContext);
    } finally {
        stack = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack)

Example 75 with OpcodeStack

use of edu.umd.cs.findbugs.OpcodeStack in project fb-contrib by mebigfatguy.

the class JDBCVendorReliance method visitClassContext.

/**
 * implements the visitor to reset the stack and jdbc locals
 *
 * @param classContext
 *            the context object of the currently parsed class
 */
@Override
public void visitClassContext(ClassContext classContext) {
    stack = new OpcodeStack();
    jdbcLocals = new HashMap<>();
    super.visitClassContext(classContext);
    stack = null;
    jdbcLocals = null;
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack)

Aggregations

OpcodeStack (edu.umd.cs.findbugs.OpcodeStack)95 JavaClass (org.apache.bcel.classfile.JavaClass)20 BitSet (java.util.BitSet)15 BugInstance (edu.umd.cs.findbugs.BugInstance)7 HashMap (java.util.HashMap)4 Map (java.util.Map)3 Field (org.apache.bcel.classfile.Field)3 StopOpcodeParsingException (com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException)2 FieldAnnotation (edu.umd.cs.findbugs.FieldAnnotation)2 XField (edu.umd.cs.findbugs.ba.XField)2 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)2 Method (org.apache.bcel.classfile.Method)2 ToString (com.mebigfatguy.fbcontrib.utils.ToString)1 ClassDescriptor (edu.umd.cs.findbugs.classfile.ClassDescriptor)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ConstantInteger (org.apache.bcel.classfile.ConstantInteger)1