[Fb-contrib-commit] SF.net SVN: fb-contrib: [431] trunk/fb-contrib/etc
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-09 21:44:16
|
Revision: 431 Author: dbrosius Date: 2006-04-09 14:44:03 -0700 (Sun, 09 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=431&view=rev Log Message: ----------- NRTL is starting to hobble along Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-04-09 21:02:41 UTC (rev 430) +++ trunk/fb-contrib/etc/findbugs.xml 2006-04-09 21:44:03 UTC (rev 431) @@ -181,8 +181,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.NonRecycleableTaglibs" speed="moderate" - reports="NRTL_NON_RECYCLEABLE_TAG_LIBS" - hidden="true" /> + reports="NRTL_NON_RECYCLEABLE_TAG_LIBS" /> <!-- BugPattern --> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java 2006-04-09 21:02:41 UTC (rev 430) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java 2006-04-09 21:44:03 UTC (rev 431) @@ -10,8 +10,11 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.FieldAnnotation; +import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.StatelessDetector; import edu.umd.cs.findbugs.ba.ClassContext; @@ -43,9 +46,15 @@ } private BugReporter bugReporter; + /** + * methodname:methodsig -> type of setter methods + */ private Map<String, String> attributes; - private boolean isAttribute; - private boolean sawSet; + /** + * methodname:methodsig -> (fieldname:fieldtype)s + */ + private Map<String, Set<String>> methodWrites; + private Map<String, FieldAnnotation> fieldAnnotations; /** * constructs a NRTL detector given the reporter to report bugs on. @@ -80,7 +89,10 @@ for (JavaClass superCls : superClasses) { if (tagClasses.contains(superCls.getClassName())) { attributes = getAttributes(cls); + if (attributes.size() > 0) { + methodWrites = new HashMap<String, Set<String>>(); + fieldAnnotations = new HashMap<String, FieldAnnotation>(); super.visitClassContext(classContext); reportBugs(); } @@ -93,6 +105,8 @@ } finally { attributes = null; + methodWrites = null; + fieldAnnotations = null; } } @@ -114,12 +128,8 @@ String parmSig = args[0].getSignature(); if (validAttrTypes.contains(parmSig)) { Code code = m.getCode(); - if ((code != null) && code.getCode().length < MAX_ATTRIBUTE_CODE_LENGTH) { - attributes.put(name.substring("set".length()), parmSig); - isAttribute = true; - sawSet = false; - super.visitMethod(m); - } + if ((code != null) && code.getCode().length < MAX_ATTRIBUTE_CODE_LENGTH) + attributes.put(name + ":" + sig, parmSig); } } } @@ -134,28 +144,59 @@ */ @Override public void visitCode(Code obj) { + Method m = getMethod(); + String attName = m.getName() + ":" + m.getSignature(); super.visitCode(obj); } @Override public void sawOpcode(int seen) { - if (isAttribute) { - sawAttributeOpcode(seen); - } - } - - private void sawAttributeOpcode(int seen) { if (seen == PUTFIELD) { - String sig = getSigConstantOperand(); - - + String methodInfo = getMethodName() + ":" + getMethodSig(); + Set<String> fields = methodWrites.get(methodInfo); + if (fields == null) { + fields = new HashSet<String>(); + methodWrites.put(methodInfo, fields); + } + String fieldName = getNameConstantOperand(); + String fieldSig = getSigConstantOperand(); + FieldAnnotation fa = new FieldAnnotation(getClassName(), fieldName, fieldSig, false); + fa.setSourceLines(SourceLineAnnotation.fromVisitedInstruction(this)); + fieldAnnotations.put(fieldName, fa); + fields.add(fieldName + ":" + fieldSig); } } - + /** * generates all the bug reports for attributes that are not recycleable */ private void reportBugs() { - + for (Map.Entry<String, String> entry : attributes.entrySet()) { + String methodInfo = entry.getKey(); + String attType = entry.getValue(); + + Set<String> fields = methodWrites.get(methodInfo); + if (fields.size() != 1) + continue; + + String fieldInfo = fields.iterator().next(); + String fieldName = fieldInfo.substring(0, fieldInfo.indexOf(":")); + String fieldType = fieldInfo.substring(fieldInfo.indexOf(":")+1); + + if (!attType.equals(fieldType)) + continue; + + int cnt = 0; + for (Set<String> allFields : methodWrites.values()) { + if (allFields.contains(fieldInfo)) + cnt++; + } + + if (cnt > 1) { + bugReporter.reportBug(new BugInstance(this, "NRTL_NON_RECYCLEABLE_TAG_LIB", NORMAL_PRIORITY) + .addClass(this) + .addField(fieldAnnotations.get(fieldName))); + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |