[Fb-contrib-commit] SF.net SVN: fb-contrib:[1149] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-03-18 20:35:36
|
Revision: 1149
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1149&view=rev
Author: dbrosius
Date: 2009-03-18 20:34:57 +0000 (Wed, 18 Mar 2009)
Log Message:
-----------
add SPP check for non private serialVersionUID fields
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2009-03-17 06:36:26 UTC (rev 1148)
+++ trunk/fb-contrib/etc/findbugs.xml 2009-03-18 20:34:57 UTC (rev 1149)
@@ -426,6 +426,7 @@
<BugPattern abbrev="SPP" type="SPP_USE_CONTAINSKEY" category="STYLE"/>
<BugPattern abbrev="SPP" type="SPP_USE_ISEMPTY" category="STYLE"/>
<BugPattern abbrev="SPP" type="SPP_USE_GETPROPERTY" category="STYLE"/>
+ <BugPattern abbrev="SPP" type="SPP_SERIALVER_SHOULD_BE_PRIVATE" category="STYLE"/>
<BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" />
<BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" />
<BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2009-03-17 06:36:26 UTC (rev 1148)
+++ trunk/fb-contrib/etc/messages.xml 2009-03-18 20:34:57 UTC (rev 1149)
@@ -2097,6 +2097,19 @@
</Details>
</BugPattern>
+ <BugPattern type="SPP_SERIALVER_SHOULD_BE_PRIVATE">
+ <ShortDescription>Class defines a serialVersionUID as non private</ShortDescription>
+ <LongDescription>Class {0} defines a serialVersionUID as non private</LongDescription>
+ <Details>
+ <![CDATA[
+ This class defines a static field 'serialVersionUID' to define the serialization
+ version for this class. This field is marked as non private. As the serialVersionUID only
+ controls the current class, and doesn't effect any derived classes, defining it as non
+ private is confusing. It is suggested you change this variable to be private.
+ ]]>
+ </Details>
+ </BugPattern>
+
<BugPattern type="BAS_BLOATED_ASSIGNMENT_SCOPE">
<ShortDescription>Method assigns a variable in a larger scope then is needed</ShortDescription>
<LongDescription>Method {1} assigns a variable in a larger scope then is needed</LongDescription>
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2009-03-17 06:36:26 UTC (rev 1148)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2009-03-18 20:34:57 UTC (rev 1149)
@@ -1,3 +1,4 @@
+import java.io.Serializable;
import java.math.BigDecimal;
import java.util.BitSet;
import java.util.Calendar;
@@ -9,9 +10,11 @@
import java.util.Set;
import java.util.StringTokenizer;
-public class SPP_Sample
+public class SPP_Sample implements Serializable
{
- private static final double pi = 3.14;
+ public static final long serialVersionUID = -2766574418713802220L;
+
+ private static final double pi = 3.14;
private static final double e = 2.72;
public static final String FALSE_POSITIVE = "INTERN_OK_HERE".intern();
@@ -47,13 +50,17 @@
public void testNAN(double d)
{
if (d == Double.NaN)
- System.out.println("It's a nan");
+ {
+ System.out.println("It's a nan");
+ }
}
public void testNAN(float f)
{
if (f == Float.NaN)
- System.out.println("It's a nan");
+ {
+ System.out.println("It's a nan");
+ }
}
public void testBigDecimal()
@@ -69,21 +76,29 @@
public void equalsOnEnum(Flap f)
{
if (f.equals(Flap.Jack))
- System.out.println("Flap Jacks");
+ {
+ System.out.println("Flap Jacks");
+ }
}
public void testCPPBoolean(Boolean a, Boolean b, Boolean c, Boolean d, Boolean e)
{
if (b && b.booleanValue())
- System.out.println("Booya");
+ {
+ System.out.println("Booya");
+ }
if (e && e.booleanValue())
- System.out.println("Booya");
+ {
+ System.out.println("Booya");
+ }
}
public char usechatAt(String s)
{
if (s.length() > 0)
- return s.toCharArray()[0];
+ {
+ return s.toCharArray()[0];
+ }
return ' ';
}
@@ -95,7 +110,9 @@
public boolean testFPUselessTrinary(boolean a, boolean b)
{
if (a && b)
- return a || b;
+ {
+ return a || b;
+ }
return a && b;
}
@@ -111,18 +128,30 @@
String e = "Foo";
if ((s == null) || (s.length() > 0))
- System.out.println("Booya");
+ {
+ System.out.println("Booya");
+ }
if ((s == null) || (s.length() != 0))
- System.out.println("Booya");
+ {
+ System.out.println("Booya");
+ }
if ((s != null) && (s.length() == 0))
- System.out.println("Booya");
+ {
+ System.out.println("Booya");
+ }
if ((e == null) || (e.length() > 0))
+ {
System.out.println("Booya");
+ }
if ((e == null) || (e.length() != 0))
+ {
System.out.println("Booya");
+ }
if ((e != null) && (e.length() == 0))
+ {
System.out.println("Booya");
+ }
}
public void testFPSST(String s)
@@ -131,22 +160,34 @@
String e = "Foo";
if ((s == null) || (s.length() == 0))
+ {
System.out.println("Booya");
+ }
if ((s != null) && (s.length() >= 0))
+ {
System.out.println("Booya");
+ }
if ((s != null) && (s.length() != 0))
+ {
System.out.println("Booya");
+ }
if ((e == null) || (e.length() == 0))
+ {
System.out.println("Booya");
+ }
if ((e != null) && (e.length() >= 0))
+ {
System.out.println("Booya");
+ }
if ((e != null) && (e.length() != 0))
+ {
System.out.println("Booya");
+ }
Set<String> m = new HashSet<String>();
Iterator<String> it = m.iterator();
@@ -165,9 +206,13 @@
public void sbToString(StringBuffer sb)
{
if (sb.toString().length() == 0)
- System.out.println("Booya");
- else if (sb.toString().equals(""))
- System.out.println("Booya");
+ {
+ System.out.println("Booya");
+ }
+ else if (sb.toString().equals(""))
+ {
+ System.out.println("Booya");
+ }
}
public String cpNullOrZero(StringTokenizer tokenizer)
@@ -195,13 +240,17 @@
public void testUseContainsKey(Map m)
{
if (m.keySet().contains("Foo"))
- System.out.println("Yup");
+ {
+ System.out.println("Yup");
+ }
}
public void testCollectionSizeEqualsZero(Set<String> s)
{
if (s.size() == 0)
- System.out.println("empty");
+ {
+ System.out.println("empty");
+ }
}
public boolean testDerivedGregorianCalendar()
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2009-03-17 06:36:26 UTC (rev 1148)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2009-03-18 20:34:57 UTC (rev 1149)
@@ -32,6 +32,7 @@
import org.apache.bcel.classfile.ConstantNameAndType;
import org.apache.bcel.classfile.ConstantPool;
import org.apache.bcel.classfile.ConstantString;
+import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.LocalVariable;
import org.apache.bcel.classfile.LocalVariableTable;
@@ -90,6 +91,17 @@
}
@Override
+ public void visitField(Field field) {
+ if ("serialVersionUID".equals(field.getName())
+ && ((field.getAccessFlags() & ACC_STATIC) != 0)
+ && ((field.getAccessFlags() & ACC_PRIVATE) == 0)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_SERIALVER_SHOULD_BE_PRIVATE", LOW_PRIORITY)
+ .addClass(this)
+ .addField(this));
+ }
+ }
+
+ @Override
public void visitClassContext(ClassContext classContext) {
try {
stack = new OpcodeStack();
@@ -264,10 +276,14 @@
boolean bug = true;
Set<Integer> branchInsSet = branchTargets.get(Integer14.valueOf(lastPCs[1]));
if (branchInsSet != null)
- bug = false;
+ {
+ bug = false;
+ }
branchInsSet = branchTargets.get(Integer14.valueOf(lastPCs[3]));
if ((branchInsSet != null) && branchInsSet.size() > 1)
- bug = false;
+ {
+ bug = false;
+ }
if (bug) {
bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY)
@@ -363,7 +379,9 @@
String methodName = getNameConstantOperand();
if ("java/lang/System".equals(className)) {
if ("getProperties".equals(methodName))
- userValue = "getProperties";
+ {
+ userValue = "getProperties";
+ }
}
} else if (seen == INVOKEVIRTUAL) {
String className = getClassConstantOperand();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|