[Fb-contrib-commit] SF.net SVN: fb-contrib:[1382] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-12 05:13:51
|
Revision: 1382
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1382&view=rev
Author: dbrosius
Date: 2009-11-12 05:13:43 +0000 (Thu, 12 Nov 2009)
Log Message:
-----------
add NFF detector
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/NFF_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonFunctionalField.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2009-11-12 03:35:19 UTC (rev 1381)
+++ trunk/fb-contrib/etc/findbugs.xml 2009-11-12 05:13:43 UTC (rev 1382)
@@ -381,6 +381,10 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment"
speed="fast"
reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField"
+ speed="fast"
+ reports="NFF_NON_FUNCTIONAL_FIELD" />
<!-- BugPattern -->
@@ -511,4 +515,5 @@
<BugPattern abbrev="PDP" type="PDP_POORLY_DEFINED_PARAMETER" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="NSE" type="NSE_NON_SYMMETRIC_EQUALS" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT" category="CORRECTNESS" experimental="true"/>
+ <BugPattern abbrev="NFF" type="NFF_NON_FUNCTIONAL_FIELD" category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2009-11-12 03:35:19 UTC (rev 1381)
+++ trunk/fb-contrib/etc/messages.xml 2009-11-12 05:13:43 UTC (rev 1382)
@@ -1066,6 +1066,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField">
+ <Details>
+ <![CDATA[
+ <p>looks for fields in serializable classes that are defined as both final and
+ transient. As a transient field is not initialized when streamed, and is not
+ initialized in a constructor, it will remain null because it is defined final.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -2730,7 +2741,7 @@
<LongDescription>method {1} performs a contravariant array assignment</LongDescription>
<Details>
<![CDATA[
- <p>Finds contravariant array assignments. Since arrays are mutable data structures, their use
+ <p>this method contains a contravariant array assignment. Since arrays are mutable data structures, their use
must be restricted to covariant or invariant usage</p>
<pre>
@@ -2746,6 +2757,19 @@
</Details>
</BugPattern>
+ <BugPattern type="NFF_NON_FUNCTIONAL_FIELD">
+ <ShortDescription>serializable class defines a final transient field</ShortDescription>
+ <LongDescription>serializable class {0} defines a final transient field</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>this serializable class defines a field as both transient and final. As transient fields
+ are not serialized across the stream, it is required that some piece of code reinitialize that field
+ when it is deserialized. But since constructors aren't called when deserialization, the field is not initialized.
+ And since the field is final, no other method can initialize it as well.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -2835,4 +2859,5 @@
<BugCode abbrev="PDP">Poorly Defined Parameter</BugCode>
<BugCode abbrev="NSE">Non Symmetric Equals</BugCode>
<BugCode abbrev="CVAA">Contravariant Array Assignment</BugCode>
+ <BugCode abbrev="NFF">Non Functional Field</BugCode>
</MessageCollection>
\ No newline at end of file
Added: trunk/fb-contrib/samples/NFF_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NFF_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/NFF_Sample.java 2009-11-12 05:13:43 UTC (rev 1382)
@@ -0,0 +1,8 @@
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class NFF_Sample implements Serializable
+{
+ private final transient List<String> s = new ArrayList<String>();
+}
\ No newline at end of file
Property changes on: trunk/fb-contrib/samples/NFF_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonFunctionalField.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonFunctionalField.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonFunctionalField.java 2009-11-12 05:13:43 UTC (rev 1382)
@@ -0,0 +1,86 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2009 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.fbcontrib.detect;
+
+import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.Field;
+import org.apache.bcel.classfile.JavaClass;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.Detector;
+import edu.umd.cs.findbugs.Priorities;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.visitclass.PreorderVisitor;
+
+/**
+ * looks for fields in serializable classes that are defined as both final and
+ * transient. As a transient field is not initialized when streamed, and is not
+ * initialized in a constructor, it will remain null because it is defined final.
+ */
+public class NonFunctionalField extends PreorderVisitor implements Detector {
+
+ private static JavaClass serializableClass;
+
+ static {
+ try {
+ serializableClass = Repository.lookupClass("java/io/Serializable");
+ } catch (ClassNotFoundException cnfe) {
+ serializableClass = null;
+ }
+ }
+
+ private BugReporter bugReporter;
+ /**
+ * constructs a NFF detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public NonFunctionalField(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ /**
+ * checks to see if the class is Serializable, then looks for fields
+ * that are both final and transient
+ * @param classContext the context object of the currently parsed class
+ */
+
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ JavaClass cls = classContext.getJavaClass();
+ if ((serializableClass != null) && (cls.implementationOf(serializableClass))) {
+ Field[] fields = cls.getFields();
+ for (Field f : fields) {
+ if (f.isFinal() && f.isTransient()) {
+ bugReporter.reportBug(new BugInstance(this, "NFF_NON_FUNCTIONAL_FIELD", Priorities.NORMAL_PRIORITY)
+ .addClass(this)
+ .addField(cls.getClassName(), f.getName(), f.getSignature(), f.getAccessFlags()));
+ }
+ }
+ }
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ }
+ }
+
+ @Override
+ public void report() {
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonFunctionalField.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|