Search in sources :

Example 1 with OpcodeStack

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

the class DubiousMapCollection method visitClassContext.

@Override
public void visitClassContext(ClassContext classContext) {
    if ((mapInterface == null) || (propertiesClass == null)) {
        return;
    }
    try {
        stack = new OpcodeStack();
        mapFields = new HashMap<>();
        super.visitClassContext(classContext);
        for (FieldAnnotation mapField : mapFields.values()) {
            bugReporter.reportBug(new BugInstance(this, BugType.DMC_DUBIOUS_MAP_COLLECTION.toString(), NORMAL_PRIORITY).addClass(this).addField(mapField));
        }
    } finally {
        mapFields = null;
        stack = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) FieldAnnotation(edu.umd.cs.findbugs.FieldAnnotation) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 2 with OpcodeStack

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

the class PossibleMemoryBloat method visitClassContext.

/**
 * collects static fields that are likely bloatable objects and if found allows the visitor to proceed, at the end report all leftover fields
 *
 * @param classContext
 *            the class context object of the currently parsed java class
 */
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        bloatableCandidates = new HashMap<>();
        bloatableFields = new HashMap<>();
        threadLocalNonStaticFields = new HashSet<>();
        parseFields(classContext);
        if (!bloatableCandidates.isEmpty()) {
            stack = new OpcodeStack();
            super.visitClassContext(classContext);
            reportMemoryBloatBugs();
            reportThreadLocalBugs();
        }
    } catch (StopOpcodeParsingException e) {
    // no more bloatable candidates
    } finally {
        stack = null;
        bloatableCandidates = null;
        bloatableFields = null;
        threadLocalNonStaticFields = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) StopOpcodeParsingException(com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException)

Example 3 with OpcodeStack

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

the class PossibleUnsuspectedSerialization method visitClassContext.

/**
 * implements the visitor to setup and tear down the opcode stack
 *
 * @param classContext
 *            the context object 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 4 with OpcodeStack

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

the class PresizeCollections method visitClassContext.

/**
 * overrides the visitor to initialize the opcode stack
 *
 * @param classContext
 *            the context object that holds the JavaClass being parsed
 */
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        stack = new OpcodeStack();
        storeToUserValue = new HashMap<>();
        allocLocation = new HashMap<>();
        allocToAddPCs = new HashMap<>();
        optionalRanges = new ArrayList<>();
        super.visitClassContext(classContext);
    } finally {
        stack = null;
        storeToUserValue = null;
        allocLocation = null;
        allocToAddPCs = null;
        optionalRanges = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack)

Example 5 with OpcodeStack

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

the class ReflectionOnObjectMethods method visitClassContext.

/**
 * implements the visitor to create the stack and local and field maps for Class arrays to be used for getting the reflection method
 *
 * @param classContext
 *            the context object of the currently parse class
 */
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        stack = new OpcodeStack();
        localClassTypes = new HashMap<>();
        fieldClassTypes = new HashMap<>();
        JavaClass cls = classContext.getJavaClass();
        Method staticInit = findStaticInitializer(cls);
        if (staticInit != null) {
            setupVisitorForClass(cls);
            doVisitMethod(staticInit);
        }
        super.visitClassContext(classContext);
    } finally {
        stack = null;
        localClassTypes = null;
        fieldClassTypes = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) JavaClass(org.apache.bcel.classfile.JavaClass) Method(org.apache.bcel.classfile.Method)

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