[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect DubiousListCollection.java,1.2,1
Brought to you by:
dbrosius
From: Dave B. <dbr...@us...> - 2005-09-22 05:45:21
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19588/src/com/mebigfatguy/fbcontrib/detect Modified Files: DubiousListCollection.java Log Message: if a method is called on an implementing List class, rather than the interface, then remove it from consideration Index: DubiousListCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- DubiousListCollection.java 22 Sep 2005 05:32:16 -0000 1.2 +++ DubiousListCollection.java 22 Sep 2005 05:45:13 -0000 1.3 @@ -98,30 +98,45 @@ String signature = getSigConstantOperand(); if (className.startsWith("java/util/") && className.endsWith("List")) { - int parmCount = Type.getArgumentTypes(signature).length; - if (stack.getStackDepth() > parmCount) { - OpcodeStack.Item itm = stack.getStackItem(parmCount); - FieldAnnotation fa = itm.getField(); - if (fa != null) { - String field = fa.getFieldName(); - Integer cnt = fieldsReported.get(field); - if (cnt != null) { - String methodInfo = methodName + signature; - if (listMethods.contains(methodInfo)) - fieldsReported.remove(field); - else if (setMethods.contains(methodInfo)) { - cnt = new Integer(cnt.intValue() + 1); - fieldsReported.put(field, cnt); - } + FieldAnnotation fa = getFieldFromStack(stack, signature); + if (fa != null) { + String field = fa.getFieldName(); + Integer cnt = fieldsReported.get(field); + if (cnt != null) { + String methodInfo = methodName + signature; + if (listMethods.contains(methodInfo)) + fieldsReported.remove(field); + else if (setMethods.contains(methodInfo)) { + cnt = new Integer(cnt.intValue() + 1); + fieldsReported.put(field, cnt); } } } } + } else if (seen == INVOKEVIRTUAL) { + String className = getClassConstantOperand(); + if (className.startsWith("java/util/") && className.endsWith("List")) { + FieldAnnotation fa = getFieldFromStack(stack, getSigConstantOperand()); + if (fa != null) { + String field = fa.getFieldName(); + fieldsReported.remove(field); + } + } } } finally { stack.sawOpcode(this, seen); } } + + private FieldAnnotation getFieldFromStack(OpcodeStack stk, String signature) { + int parmCount = Type.getArgumentTypes(signature).length; + if (stk.getStackDepth() > parmCount) { + OpcodeStack.Item itm = stk.getStackItem(parmCount); + FieldAnnotation fa = itm.getField(); + return fa; + } + return null; + } private void reportBugs() { for (Map.Entry<String, Integer> entry : fieldsReported.entrySet()) { |