Search in sources :

Example 11 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class JPAIssues method catalogFieldOrMethod.

/**
 * parses a field or method for spring-tx or jpa annotations
 *
 * @param fm
 *            the currently parsed field or method
 */
private void catalogFieldOrMethod(FieldOrMethod fm) {
    for (AnnotationEntry entry : fm.getAnnotationEntries()) {
        String type = entry.getAnnotationType();
        switch(type) {
            case "Lorg/springframework/transaction/annotation/Transactional;":
                if (fm instanceof Method) {
                    boolean isWrite = true;
                    for (ElementValuePair pair : entry.getElementValuePairs()) {
                        if ("readOnly".equals(pair.getNameString())) {
                            isWrite = "false".equals(pair.getValue().stringifyValue());
                            break;
                        }
                    }
                    transactionalMethods.put(new FQMethod(cls.getClassName(), fm.getName(), fm.getSignature()), isWrite ? TransactionalType.WRITE : TransactionalType.READ);
                }
                break;
            case "Ljavax/persistence/Id;":
                hasId = true;
                break;
            case "Ljavax/persistence/GeneratedValue;":
                hasGeneratedValue = true;
                break;
            case "Ljavax/persistence/OneToMany;":
                for (ElementValuePair pair : entry.getElementValuePairs()) {
                    if ("fetch".equals(pair.getNameString()) && "EAGER".equals(pair.getValue().stringifyValue())) {
                        hasEagerOneToMany = true;
                        break;
                    }
                }
                break;
            case "Lorg/hibernate/annotations/Fetch;":
            case "Lorg/eclipse/persistence/annotations/JoinFetch;":
            case "Lorg/eclipse/persistence/annotations/BatchFetch;":
                hasFetch = true;
                break;
            default:
                break;
        }
    }
}
Also used : AnnotationEntry(org.apache.bcel.classfile.AnnotationEntry) ElementValuePair(org.apache.bcel.classfile.ElementValuePair) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod) FieldOrMethod(org.apache.bcel.classfile.FieldOrMethod) Method(org.apache.bcel.classfile.Method) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod)

Example 12 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class LingeringGraphicsObjects method sawOpcode.

@Override
public void sawOpcode(int seen) {
    Integer sawNewGraphicsAt = null;
    try {
        stack.precomputation(this);
        switch(seen) {
            case Const.ALOAD:
            case Const.ALOAD_0:
            case Const.ALOAD_1:
            case Const.ALOAD_2:
            case Const.ALOAD_3:
                {
                    int reg = RegisterUtils.getALoadReg(this, seen);
                    sawNewGraphicsAt = graphicsRegs.get(Integer.valueOf(reg));
                }
                break;
            case Const.ASTORE:
            case Const.ASTORE_0:
            case Const.ASTORE_1:
            case Const.ASTORE_2:
            case Const.ASTORE_3:
                {
                    if (stack.getStackDepth() > 0) {
                        OpcodeStack.Item item = stack.getStackItem(0);
                        sawNewGraphicsAt = (Integer) item.getUserValue();
                        Integer reg = Integer.valueOf(RegisterUtils.getAStoreReg(this, seen));
                        if (sawNewGraphicsAt != null) {
                            graphicsRegs.put(reg, sawNewGraphicsAt);
                        } else {
                            graphicsRegs.remove(reg);
                        }
                        sawNewGraphicsAt = null;
                    }
                }
                break;
            case Const.ARETURN:
                if (stack.getStackDepth() > 0) {
                    OpcodeStack.Item item = stack.getStackItem(0);
                    graphicsRegs.remove(Integer.valueOf(item.getRegisterNumber()));
                }
                break;
            case Const.INVOKEVIRTUAL:
                String clsName = getClassConstantOperand();
                String methodName = getNameConstantOperand();
                String methodSig = getSigConstantOperand();
                FQMethod methodInfo = new FQMethod(clsName, methodName, methodSig);
                if (GRAPHICS_PRODUCERS.contains(methodInfo)) {
                    sawNewGraphicsAt = Integer.valueOf(getPC());
                } else if (GRAPHICS_DISPOSERS.contains(methodInfo) && (stack.getStackDepth() > 0)) {
                    OpcodeStack.Item item = stack.getStackItem(0);
                    graphicsRegs.remove(Integer.valueOf(item.getRegisterNumber()));
                }
                break;
            default:
                break;
        }
    } finally {
        TernaryPatcher.pre(stack, seen);
        stack.sawOpcode(this, seen);
        TernaryPatcher.post(stack, seen);
        if ((sawNewGraphicsAt != null) && (stack.getStackDepth() > 0)) {
            OpcodeStack.Item item = stack.getStackItem(0);
            item.setUserValue(sawNewGraphicsAt);
        }
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod)

Example 13 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class ListUsageIssues method sawOpcode.

@Override
public void sawOpcode(int seen) {
    LUIUserValue userValue = null;
    try {
        if (seen == Const.INVOKESTATIC) {
            FQMethod fqm = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand());
            if (ARRAYS_ASLIST_METHOD.equals(fqm)) {
                if (stack.getStackDepth() > 0) {
                    OpcodeStack.Item itm = stack.getStackItem(0);
                    if (Values.ONE.equals(itm.getConstant())) {
                        if (clsVersion >= Const.MAJOR_1_8) {
                            bugReporter.reportBug(new BugInstance(this, BugType.LUI_USE_SINGLETON_LIST.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
                        }
                        userValue = LUIUserValue.ONE_ITEM_LIST;
                    }
                }
            } else if (COLLECTIONS_SINGLETONLIST_METHOD.equals(fqm)) {
                userValue = LUIUserValue.ONE_ITEM_LIST;
            }
        } else if (seen == Const.INVOKEINTERFACE) {
            FQMethod fqm = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand());
            if (ADDALL_METHODS.contains(fqm)) {
                if (stack.getStackDepth() >= 2) {
                    OpcodeStack.Item itm = stack.getStackItem(0);
                    if ((itm.getUserValue() == LUIUserValue.ONE_ITEM_LIST) && (itm.getRegisterNumber() < 0) && (itm.getXField() == null)) {
                        bugReporter.reportBug(new BugInstance(this, BugType.LUI_USE_COLLECTION_ADD.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
                    }
                }
            } else if (LIST_STREAM_METHOD.equals(fqm)) {
                userValue = LUIUserValue.LIST_STREAM;
            } else if (STREAM_FINDFIRST_METHOD.equals(fqm)) {
                if (stack.getStackDepth() > 0) {
                    OpcodeStack.Item itm = stack.getStackItem(0);
                    if (itm.getUserValue() == LUIUserValue.LIST_STREAM) {
                        userValue = LUIUserValue.STREAM_OPTIONAL;
                    }
                }
            }
        } else if (seen == INVOKEVIRTUAL) {
            FQMethod fqm = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand());
            if (OPTIONAL_GET_METHOD.equals(fqm)) {
                if (stack.getStackDepth() > 0) {
                    OpcodeStack.Item itm = stack.getStackItem(0);
                    if (itm.getUserValue() == LUIUserValue.STREAM_OPTIONAL) {
                        bugReporter.reportBug(new BugInstance(this, BugType.LUI_USE_GET0.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
                    }
                }
            }
        }
    } finally {
        stack.sawOpcode(this, seen);
        if ((userValue != null) && (stack.getStackDepth() > 0)) {
            OpcodeStack.Item itm = stack.getStackItem(0);
            itm.setUserValue(userValue);
        }
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 14 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class IOIssues method processInvokeStatic.

private void processInvokeStatic() {
    String clsName = getClassConstantOperand();
    String methodName = getNameConstantOperand();
    FQMethod m = new FQMethod(clsName, methodName, ANY_PARMS);
    if (COPY_METHODS.contains(m)) {
        String signature = getSigConstantOperand();
        int numArguments = SignatureUtils.getNumParameters(signature);
        if (stack.getStackDepth() >= numArguments) {
            for (int i = 0; i < numArguments; i++) {
                OpcodeStack.Item itm = stack.getStackItem(i);
                IOIUserValue uv = (IOIUserValue) itm.getUserValue();
                if (uv != null) {
                    switch(uv) {
                        case BUFFER:
                            bugReporter.reportBug(new BugInstance(this, BugType.IOI_DOUBLE_BUFFER_COPY.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
                            break;
                        case READER:
                            bugReporter.reportBug(new BugInstance(this, BugType.IOI_COPY_WITH_READER.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
                    }
                    break;
                }
            }
        }
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod) BugInstance(edu.umd.cs.findbugs.BugInstance)

Example 15 with FQMethod

use of com.mebigfatguy.fbcontrib.utils.FQMethod in project fb-contrib by mebigfatguy.

the class ConflictingTimeUnits method processInvoke.

private Units processInvoke() {
    String signature = getSigConstantOperand();
    FQMethod methodCall = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), signature);
    Units unit = TIME_UNIT_GENERATING_METHODS.get(methodCall);
    if (unit == Units.CALLER) {
        int offset = SignatureUtils.getNumParameters(signature);
        if (stack.getStackDepth() > offset) {
            OpcodeStack.Item item = stack.getStackItem(offset);
            unit = (Units) item.getUserValue();
        } else {
            unit = null;
        }
    }
    return unit;
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) FQMethod(com.mebigfatguy.fbcontrib.utils.FQMethod)

Aggregations

FQMethod (com.mebigfatguy.fbcontrib.utils.FQMethod)25 OpcodeStack (edu.umd.cs.findbugs.OpcodeStack)15 BugInstance (edu.umd.cs.findbugs.BugInstance)13 XMethod (edu.umd.cs.findbugs.ba.XMethod)7 ToString (com.mebigfatguy.fbcontrib.utils.ToString)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Method (org.apache.bcel.classfile.Method)3 MethodInfo (com.mebigfatguy.fbcontrib.collect.MethodInfo)2 QMethod (com.mebigfatguy.fbcontrib.utils.QMethod)2 JavaClass (org.apache.bcel.classfile.JavaClass)2 Statistics (com.mebigfatguy.fbcontrib.collect.Statistics)1 XField (edu.umd.cs.findbugs.ba.XField)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Nullable (javax.annotation.Nullable)1 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)1 BootstrapMethod (org.apache.bcel.classfile.BootstrapMethod)1