[Fb-contrib-commit] SF.net SVN: fb-contrib: [426] trunk/fb-contrib/etc
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2006-04-09 20:11:21
|
Revision: 426 Author: dbrosius Date: 2006-04-09 13:11:12 -0700 (Sun, 09 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=426&view=rev Log Message: ----------- Initial checkin NonRecycleableTaglibs -- not even close to working. :) Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- 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 20:09:29 UTC (rev 425) +++ trunk/fb-contrib/etc/findbugs.xml 2006-04-09 20:11:12 UTC (rev 426) @@ -179,6 +179,11 @@ speed="fast" reports="NOS_NON_OWNED_SYNCHRONIZATION" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.NonRecycleableTaglibs" + speed="moderate" + reports="NRTL_NON_RECYCLEABLE_TAG_LIBS" + hidden="true" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -215,11 +220,12 @@ <BugPattern abbrev="AWCBR" type="AWCBR_ARRAY_WRAPPED_CALL_BY_REFERENCE" category="STYLE" /> <BugPattern abbrev="SG" type="SG_SLUGGISH_GUI" category="PERFORMANCE" /> <BugPattern abbrev="NIR" type="NIR_NEEDLESS_INSTANCE_RETRIEVAL" category="PERFORMANCE" /> - <BugPattern abbrev="DDC" type="DDC_DOUBLE_DATE_COMPARISON" category="PERFORMANCE" experimental="true" /> - <BugPattern abbrev="SWCO" type="SWCO_SUSPICIOUS_WAIT_ON_CONCURRENT_OBJECT" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="JVR" type="JVR_JDBC_VENDOR_RELIANCE" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="PMB" type="PMB_POSSIBLE_MEMORY_BLOAT" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="LSYC" type="LSYC_LOCAL_SYNCHRONIZED_COLLECTION" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="DDC" type="DDC_DOUBLE_DATE_COMPARISON" category="PERFORMANCE" /> + <BugPattern abbrev="SWCO" type="SWCO_SUSPICIOUS_WAIT_ON_CONCURRENT_OBJECT" category="CORRECTNESS" /> + <BugPattern abbrev="JVR" type="JVR_JDBC_VENDOR_RELIANCE" category="CORRECTNESS" /> + <BugPattern abbrev="PMB" type="PMB_POSSIBLE_MEMORY_BLOAT" category="CORRECTNESS" /> + <BugPattern abbrev="LSYC" type="LSYC_LOCAL_SYNCHRONIZED_COLLECTION" category="CORRECTNESS" /> <BugPattern abbrev="FCBL" type="FCBL_FIELD_COULD_BE_LOCAL" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="NOS" type="NOS_NON_OWNED_SYNCHRONIZATION" category="STYLE" experimental="true" /> + <BugPattern abbrev="NRTL" type="NRTL_NON_RECYCLEABLE_TAG_LIB" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-04-09 20:09:29 UTC (rev 425) +++ trunk/fb-contrib/etc/messages.xml 2006-04-09 20:11:12 UTC (rev 426) @@ -517,6 +517,16 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.NonRecycleableTaglibs"> + <Details> + <![CDATA[ + <p>looks for tag libraries that are not recycleable because backing members + of taglib attributes are set in areas besides the setter method for the attribute.</p> + <p>It is a moderately fast detector</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1057,6 +1067,21 @@ ]]> </Details> </BugPattern> + + <BugPattern type="NRTL_NON_RECYCLEABLE_TAG_LIB"> + <ShortDescription>Tag library is not recycleable</ShortDescription> + <LongDescription>Tag library {0} is not recycleable</LongDescription> + <Details> + <![CDATA[ + <p>This Tag library class implements an attribute who's associated backing store field + is modified at another point in the tag library. In order for a taglibrary to be + recycleable, only the container is allowed to change this attribute, through the use + of the setXXX method of the taglib. By modifying the value programmatically, the + container will not initialize the attribute correctly on reuse.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1100,4 +1125,5 @@ <BugCode abbrev="LSYC">Local Synchronized Collection</BugCode> <BugCode abbrev="FCBL">Field Could Be Local</BugCode> <BugCode abbrev="NOS">Non Owned Synchronization</BugCode> + <BugCode abbrev="NRTL">Non Recycleable Taglib</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java 2006-04-09 20:11:12 UTC (rev 426) @@ -0,0 +1,143 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.StatelessDetector; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for tag libraries that are not recycleable because backing members of taglib attributes are + * set in areas besides the setter method for the attribute. + */ +public class NonRecycleableTaglibs extends BytecodeScanningDetector implements StatelessDetector { + private static final int MAX_ATTRIBUTE_CODE_LENGTH = 60; + + private static final Set<String> tagClasses = new HashSet<String>(); + static { + tagClasses.add("javax.servlet.jsp.tagext.TagSupport"); + tagClasses.add("javax.servlet.jsp.tagext.BodyTagSupport"); + } + private BugReporter bugReporter; + private Map<String, String> attributes; + private boolean isAttribute; + private boolean sawPut; + + /** + * constructs a NRTL detector given the reporter to report bugs on. + + * @param bugReporter the sync of bug reports + */ + public NonRecycleableTaglibs(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * clone this detector so that it can be a StatelessDetector. + * + * @return a clone of this object + * @throws CloneNotSupportedException never + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /** + * implements the visitor to look for classes that extend the TagSupport or BodyTagSupport class + * + * @param classContext the context object for the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + JavaClass cls = classContext.getJavaClass(); + JavaClass[] superClasses = cls.getSuperClasses(); + for (JavaClass superCls : superClasses) { + if (tagClasses.contains(superCls.getClassName())) { + attributes = getAttributes(cls); + if (attributes.size() > 0) { + super.visitClassContext(classContext); + reportBugs(); + } + break; + } + } + + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + finally { + attributes = null; + } + } + + /** + * collect all possible attributes given the name of methods available. + * + * @return the map of possible attributes/types + */ + private Map<String, String> getAttributes(JavaClass cls) { + Map<String, String> attributes = new HashMap<String, String>(); + Method[] methods = cls.getMethods(); + for (Method m : methods) { + String name = m.getName(); + if (name.startsWith("get") && m.isPublic() && !m.isStatic()) { + String sig = m.getSignature(); + if (sig.startsWith("()")) { + String retSig = sig.substring(sig.indexOf(")")+1); + if ((retSig.charAt(0) != 'L') && ("Ljava/lang/String;".equals(retSig))) { + Code code = m.getCode(); + if ((code != null) && code.getCode().length > MAX_ATTRIBUTE_CODE_LENGTH) { + attributes.put(name.substring("get".length()), retSig); + isAttribute = true; + sawPut = false; + super.visitMethod(m); + } + } + } + } + } + return attributes; + } + + /** + * implements the visitor to + * + * @param obj the context object for the currently parsed code object + */ + @Override + public void visitCode(Code obj) { + super.visitCode(obj); + } + + @Override + public void sawOpcode(int seen) { + if (isAttribute) { + sawAttributeOpcode(seen); + } + } + + private void sawAttributeOpcode(int seen) { + if (seen == PUTFIELD) { + String sig = getSigConstantOperand(); + + + } + } + + /** + * generates all the bug reports for attributes that are not recycleable + */ + private void reportBugs() { + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |