Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [846] trunk/fb-contrib (Page 3)
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2007-02-09 22:57:05
|
Revision: 846
http://svn.sourceforge.net/fb-contrib/?rev=846&view=rev
Author: dbrosius
Date: 2007-02-09 14:57:00 -0800 (Fri, 09 Feb 2007)
Log Message:
-----------
Fix for [ 1655774 ] NAB_NEEDLESS_AUTOBOXING_PARSE for boolean?
Boolean.parseBoolean(String s)
wasn't introduced until 1.5, so don't report before then.
Modified Paths:
--------------
trunk/fb-contrib/samples/NAB_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
Modified: trunk/fb-contrib/samples/NAB_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NAB_Sample.java 2007-02-08 03:40:25 UTC (rev 845)
+++ trunk/fb-contrib/samples/NAB_Sample.java 2007-02-09 22:57:00 UTC (rev 846)
@@ -43,6 +43,7 @@
public void testNeedsParse(String data)
{
+ //The first one is a false positive for < 1.5
boolean bo = Boolean.valueOf(data).booleanValue();
byte b = Byte.valueOf(data).byteValue();
short s = Short.valueOf(data).shortValue();
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-08 03:40:25 UTC (rev 845)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-09 22:57:00 UTC (rev 846)
@@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.bcel.Constants;
import org.apache.bcel.classfile.Method;
import edu.umd.cs.findbugs.BugInstance;
@@ -96,7 +97,8 @@
boxClass = getClassConstantOperand();
if (boxClasses.containsKey(boxClass)) {
if ("valueOf".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) {
- state = SEEN_VALUEOF;
+ if (!"java/lang/Boolean".equals(boxClass) || (getClassContext().getJavaClass().getMajor() >= Constants.MAJOR_1_5))
+ state = SEEN_VALUEOF;
}
else {
String parseSig = parseClasses.get(boxClass);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-13 23:19:13
|
Revision: 851
http://svn.sourceforge.net/fb-contrib/?rev=851&view=rev
Author: dbrosius
Date: 2007-02-13 15:19:12 -0800 (Tue, 13 Feb 2007)
Log Message:
-----------
Fix [ 1655778 ] SPOILED_CHILD_INTERFACE_IMPLEMENTOR: wrong analysis
If a superclass implements a super interface of the interface that the child implements, and the super interface has the same methods as the child, then don't report -- even if hinky.
Modified Paths:
--------------
trunk/fb-contrib/samples/SCII_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java
Modified: trunk/fb-contrib/samples/SCII_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SCII_Sample.java 2007-02-13 04:34:14 UTC (rev 850)
+++ trunk/fb-contrib/samples/SCII_Sample.java 2007-02-13 23:19:12 UTC (rev 851)
@@ -34,6 +34,10 @@
interface A
{
public void a();
+
+ public void b();
+
+ public void c();
}
interface B extends A
@@ -41,15 +45,27 @@
public void b();
}
+ interface C extends B
+ {
+ public void c();
+ }
+
class AA implements A
{
public void a() {}
public void b() {}
+
+ public void c() {}
}
class BB extends AA implements B
{
}
+
+ class CC extends BB implements C
+ {
+
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2007-02-13 04:34:14 UTC (rev 850)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2007-02-13 23:19:12 UTC (rev 851)
@@ -71,18 +71,21 @@
infMethods.removeAll(clsMethods);
if (infMethods.size() > 0) {
JavaClass superCls = cls.getSuperClass();
- if (!superCls.implementationOf(inf)) {
- int priority = AnalysisContext.currentAnalysisContext().getSubtypes().isApplicationClass(superCls) ? NORMAL_PRIORITY : LOW_PRIORITY;
- BugInstance bi = new BugInstance(this, "SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR", priority)
- .addClass(cls)
- .addString("Implementing interface: " + inf.getClassName())
- .addString("Methods:");
- for (String nameSig : infMethods)
- bi.addString("\t" + nameSig);
-
- bugReporter.reportBug(bi);
- return;
- }
+ filterSuperInterfaceMethods(inf, infMethods, superCls);
+ if (infMethods.size() > 0) {
+ if (!superCls.implementationOf(inf)) {
+ int priority = AnalysisContext.currentAnalysisContext().getSubtypes().isApplicationClass(superCls) ? NORMAL_PRIORITY : LOW_PRIORITY;
+ BugInstance bi = new BugInstance(this, "SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR", priority)
+ .addClass(cls)
+ .addString("Implementing interface: " + inf.getClassName())
+ .addString("Methods:");
+ for (String nameSig : infMethods)
+ bi.addString("\t" + nameSig);
+
+ bugReporter.reportBug(bi);
+ return;
+ }
+ }
}
}
}
@@ -105,7 +108,7 @@
* @param cls the class to build the method set from
* @return a set of method names/signatures
*/
- public Set<String> buildMethodSet(JavaClass cls) {
+ private Set<String> buildMethodSet(JavaClass cls) {
Set<String> methods = new HashSet<String>();
for (Method m : cls.getMethods()) {
@@ -117,6 +120,35 @@
return methods;
}
+
+ /**
+ * removes methods found in an interface when a superinterface having the same methods
+ * is implemented in a parent. While this is somewhat hinky, we'll allow it.
+ *
+ * @param inf the interface to look for super interfaces for
+ * @param infMethods the remaining methods that are needed to be found
+ * @param cls the super class to look for these methods in
+ */
+ private void filterSuperInterfaceMethods(JavaClass inf, Set<String> infMethods, JavaClass cls) {
+ try {
+ if (infMethods.size() == 0)
+ return;
+
+ JavaClass[] superInfs = inf.getInterfaces();
+ for (JavaClass superInf : superInfs) {
+ if (cls.implementationOf(superInf)) {
+ Set<String> superInfMethods = buildMethodSet(superInf);
+ infMethods.removeAll(superInfMethods);
+ if (infMethods.size() == 0)
+ return;
+ }
+ filterSuperInterfaceMethods(superInf, infMethods, cls);
+ }
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ infMethods.clear();
+ }
+ }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-14 06:52:09
|
Revision: 857
http://svn.sourceforge.net/fb-contrib/?rev=857&view=rev
Author: dbrosius
Date: 2007-02-13 22:52:09 -0800 (Tue, 13 Feb 2007)
Log Message:
-----------
add build step to check for 1.5 methods
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/lib/findbugs.jar
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2007-02-14 06:51:31 UTC (rev 856)
+++ trunk/fb-contrib/build.xml 2007-02-14 06:52:09 UTC (rev 857)
@@ -121,9 +121,6 @@
in="${etc.dir}/messages.xml" out="${htdocs.dir}/bugdescriptions.html"/>
</target>
- <target name="build" depends="-init, validate_xml, compile, compile_samples, jar" description="builds the plugin jar">
- </target>
-
<target name="install" depends="clean, build" description="installs the plugin into FindBugs">
<property environment="env"/>
<copy todir="${env.FINDBUGS_HOME}/plugin">
@@ -156,4 +153,28 @@
<bottom><![CDATA[<i>Copyright © 2005-2007 MeBigFatGuy.com. All Rights Reserved.</i>]]></bottom>
</javadoc>
</target>
+
+ <target name="check14" depends="jar" description="Check for 1.5 only methods">
+ <mkdir dir="${basedir}/plugin"/>
+ <copy file="${basedir}/fb-contrib.jar" todir="${basedir}/plugin"/>
+
+ <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="${lib.dir}/findbugs-ant.jar;${lib.dir}/findbugs.jar;${lib.dir}/bcel.jar;${lib.dir}/dom4j-full.jar;${lib.dir}/asm-3.0.jar"/>
+
+ <findbugs output="xml"
+ home="${basedir}"
+ auxClasspath="${sampleslib.dir}/jsp-api.jar;${lib.dir}/findbugs.jar;${lib.dir}/bcel.jar"
+ visitors="SuspiciousJDKVersionUse"
+ reportLevel="medium"
+ outputFile="${basedir}/plugin/findbugs.xml"
+ jvmargs="-Xmx800m -Dfb-contrib.sjvu.jdkhome=${jdk14.home}"
+ failOnError="true">
+ <class location="${basedir}/fb-contrib.jar"/>
+ </findbugs>
+ <!--<delete dir="${basedir}/plugin"/>-->
+ </target>
+
+ <target name="build" depends="-init, validate_xml, compile, compile_samples, jar, check14, javadoc" description="builds the plugin jar">
+ </target>
+
+
</project>
\ No newline at end of file
Modified: trunk/fb-contrib/lib/findbugs.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-17 06:41:38
|
Revision: 860
http://svn.sourceforge.net/fb-contrib/?rev=860&view=rev
Author: dbrosius
Date: 2007-02-16 22:41:09 -0800 (Fri, 16 Feb 2007)
Log Message:
-----------
fix false positive
sb.append(ISB_Sample.getBigger(a + b, c));
Modified Paths:
--------------
trunk/fb-contrib/samples/ISB_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java
Modified: trunk/fb-contrib/samples/ISB_Sample.java
===================================================================
--- trunk/fb-contrib/samples/ISB_Sample.java 2007-02-14 07:01:14 UTC (rev 859)
+++ trunk/fb-contrib/samples/ISB_Sample.java 2007-02-17 06:41:09 UTC (rev 860)
@@ -69,4 +69,20 @@
sb.append(a + ":" + b);
return sb.toString();
}
+
+ public String testFPISB9(String a, String b, String c)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(ISB_Sample.getBigger(a + b, c));
+
+ return sb.toString();
+ }
+
+ private static String getBigger(String a, String b)
+ {
+ if (a.length() > b.length())
+ return a;
+ return b;
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2007-02-14 07:01:14 UTC (rev 859)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2007-02-17 06:41:09 UTC (rev 860)
@@ -75,25 +75,11 @@
@Override
public void sawOpcode(final int seen) {
+ boolean markAsSBToString = false;
try {
stack.mergeJumps(this);
- if (seen == INVOKESPECIAL) {
- String calledClass = getClassConstantOperand();
- if (("java/lang/StringBuffer".equals(calledClass)
- || "java/lang/StringBuilder".equals(calledClass))
- && "<init>".equals(getNameConstantOperand())
- && "()V".equals(getSigConstantOperand())) {
- OpcodeStack.Item itm = getStringBufferItemAt(2);
- if ((itm != null) && (itm.getUserValue() == null)) {
- bugReporter.reportBug(
- new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
- }
- }
- } else if (seen == INVOKEVIRTUAL) {
+ if (seen == INVOKEVIRTUAL) {
if (sawLDCEmpty) {
String calledClass = getClassConstantOperand();
if (("java/lang/StringBuffer".equals(calledClass)
@@ -118,12 +104,52 @@
}
}
}
+ } else {
+ String calledClass = getClassConstantOperand();
+ if (("java/lang/StringBuffer".equals(calledClass)
+ || "java/lang/StringBuilder".equals(calledClass))) {
+ if (("toString".equals(getNameConstantOperand())
+ && "()Ljava/lang/String;".equals(getSigConstantOperand()))) {
+ markAsSBToString = true;
+ } else if (("append".equals(getNameConstantOperand())
+ && (("(Ljava/lang/String;)L" + calledClass + ";").equals(getSigConstantOperand())))) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ Boolean sbVal = (Boolean)itm.getUserValue();
+ if ((sbVal != null) && sbVal.booleanValue()) {
+ bugReporter.reportBug(
+ new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
}
+ } else if (seen == INVOKESPECIAL) {
+ String calledClass = getClassConstantOperand();
+ if (("java/lang/StringBuffer".equals(calledClass)
+ || "java/lang/StringBuilder".equals(calledClass))
+ && "<init>".equals(getNameConstantOperand())
+ && "(Ljava/lang/String;)V".equals(getSigConstantOperand())) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ Boolean sbVal = (Boolean)itm.getUserValue();
+ if ((sbVal != null) && sbVal.booleanValue()) {
+ bugReporter.reportBug(
+ new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
} else if (seen == GOTO) {
int depth = stack.getStackDepth();
for (int i = 0; i < depth; i++) {
OpcodeStack.Item itm = stack.getStackItem(i);
- itm.setUserValue(Boolean.TRUE);
+ itm.setUserValue(Boolean.FALSE);
}
} else if (seen == LDC) {
Constant c = getConstantRefOperand();
@@ -135,6 +161,12 @@
}
} finally {
stack.sawOpcode(this, seen);
+ if (markAsSBToString) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ itm.setUserValue(Boolean.TRUE);
+ }
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-20 01:35:54
|
Revision: 864
http://svn.sourceforge.net/fb-contrib/?rev=864&view=rev
Author: dbrosius
Date: 2007-02-19 17:35:46 -0800 (Mon, 19 Feb 2007)
Log Message:
-----------
add SPP fix for pattern
if (b && b.booleanValue())
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 2007-02-20 00:31:17 UTC (rev 863)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-02-20 01:35:46 UTC (rev 864)
@@ -256,7 +256,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri"
speed="fast"
- reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM" />
+ reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
speed="fast"
@@ -360,6 +360,7 @@
<BugPattern abbrev="SPP" type="SPP_USE_BIGDECIMAL_STRING_CTOR" category="CORRECTNESS" />
<BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" />
<BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" />
+ <BugPattern abbrev="SPP" type="SPP_INVALID_BOOLEAN_NULL_CHECK" category="CORRECTNESS" />
<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 2007-02-20 00:31:17 UTC (rev 863)
+++ trunk/fb-contrib/etc/messages.xml 2007-02-20 01:35:46 UTC (rev 864)
@@ -1741,6 +1741,23 @@
</Details>
</BugPattern>
+ <BugPattern type="SPP_INVALID_BOOLEAN_NULL_CHECK">
+ <ShortDescription>Method uses invalid C++ style null check on Boolean</ShortDescription>
+ <LongDescription>Method {1} uses invalid C++ style null check on Boolean</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method attempts to check for null by just refering to the variable name
+ as would be done in C++. This ordinarily would be considered a compile error, except the
+ variable in question is a Boolean, which does an auto unbox to boolean.</p>
+ <pre>
+ if (b && b.booleanValue())
+ should be
+ if ((b != null) && b.booleanValue())
+ </pre>
+ ]]>
+ </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 2007-02-20 00:31:17 UTC (rev 863)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-02-20 01:35:46 UTC (rev 864)
@@ -62,4 +62,12 @@
if (f.equals(Flap.Jack))
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");
+ if (e && e.booleanValue())
+ System.out.println("Booya");
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-02-20 00:31:17 UTC (rev 863)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-02-20 01:35:46 UTC (rev 864)
@@ -18,6 +18,8 @@
*/
package com.mebigfatguy.fbcontrib.detect;
+import java.util.Arrays;
+
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.ConstantDouble;
@@ -38,6 +40,7 @@
{
private BugReporter bugReporter;
private OpcodeStack stack;
+ private int lastPCs[];
private int lastOpcode;
private int lastReg;
@@ -53,9 +56,11 @@
public void visitClassContext(ClassContext classContext) {
try {
stack = new OpcodeStack();
+ lastPCs = new int[4];
super.visitClassContext(classContext);
} finally {
stack = null;
+ lastPCs = null;
}
}
@@ -69,6 +74,7 @@
stack.resetForMethodEntry(this);
lastOpcode = -1;
lastReg = -1;
+ Arrays.fill(lastPCs, -1);
super.visitCode(obj);
}
@@ -181,6 +187,33 @@
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
+ } else if ("java/lang/Boolean".equals(className)
+ && "booleanValue".equals(methodName)) {
+ if (lastPCs[0] != -1) {
+ int range1Size = lastPCs[2] - lastPCs[0];
+ if (range1Size == (getNextPC() - lastPCs[3])) {
+ byte[] bytes = getCode().getCode();
+ int ifeq = 0x000000FF & bytes[lastPCs[2]];
+ if (ifeq == IFEQ) {
+ int start1 = lastPCs[0];
+ int start2 = lastPCs[3];
+ boolean found = true;
+ for (int i = 0; i < range1Size; i++) {
+ if (bytes[start1+i] != bytes[start2+i]) {
+ found = false;
+ break;
+ }
+ }
+
+ if (found) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_INVALID_BOOLEAN_NULL_CHECK", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
}
} else if (seen == INVOKESPECIAL) {
String className = getClassConstantOperand();
@@ -239,6 +272,8 @@
stack.sawOpcode(this, seen);
lastOpcode = seen;
lastReg = reg;
+ System.arraycopy(lastPCs, 1, lastPCs, 0, 3);
+ lastPCs[3] = getPC();
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-26 07:53:27
|
Revision: 868
http://svn.sourceforge.net/fb-contrib/?rev=868&view=rev
Author: dbrosius
Date: 2007-02-25 23:53:26 -0800 (Sun, 25 Feb 2007)
Log Message:
-----------
add NAB check for new Integer(1).intValue()
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/NAB_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-02-25 12:47:44 UTC (rev 867)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-02-26 07:53:26 UTC (rev 868)
@@ -115,7 +115,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing"
speed="fast"
- reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF" />
+ reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF,NAB_NEEDLESS_BOX_TO_UNBOX" />
<Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn"
speed="fast"
@@ -311,6 +311,7 @@
<BugPattern abbrev="NAB" type="NAB_NEEDLESS_AUTOBOXING_VALUEOF" category="PERFORMANCE" />
<BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_PARSE" category="PERFORMANCE" />
<BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_VALUEOF" category="PERFORMANCE" />
+ <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOX_TO_UNBOX" category="PERFORMANCE" experimental="true" />
<BugPattern abbrev="USBR" type="USBR_UNNECESSARY_STORE_BEFORE_RETURN" category="STYLE" />
<BugPattern abbrev="COM" type="COM_COPIED_OVERRIDDEN_METHOD" category="STYLE" />
<BugPattern abbrev="ABC" type="ABC_ARRAY_BASED_COLLECTIONS" category="CORRECTNESS" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-02-25 12:47:44 UTC (rev 867)
+++ trunk/fb-contrib/etc/messages.xml 2007-02-26 07:53:26 UTC (rev 868)
@@ -1095,6 +1095,22 @@
</Details>
</BugPattern>
+ <BugPattern type="NAB_NEEDLESS_BOX_TO_UNBOX">
+ <ShortDescription>method creates Boxed primitive from primitive only to get primitive value</ShortDescription>
+ <LongDescription>method {1} creates Boxed primitive from primitive only to get primitive value</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method constructs a Boxed Primitive from a primitive only to call the primitiveValue() method to
+ convert it back to a primitive. Just use the primitive value instead.</p>
+ <pre>
+ primitive i = new BoxedPrimitive(1).primitiveValue();
+ should just use
+ primitive i = 1;
+ </pre>
+ ]]>
+ </Details>
+ </BugPattern>
+
<BugPattern type="USBR_UNNECESSARY_STORE_BEFORE_RETURN">
<ShortDescription>method stores return result in local before immediately returning it</ShortDescription>
<LongDescription>method {1} stores return result in local before immediately returning it</LongDescription>
Modified: trunk/fb-contrib/samples/NAB_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NAB_Sample.java 2007-02-25 12:47:44 UTC (rev 867)
+++ trunk/fb-contrib/samples/NAB_Sample.java 2007-02-26 07:53:26 UTC (rev 868)
@@ -55,8 +55,8 @@
public void testExtraneousParse()
{
- Boolean bo = Boolean.valueOf(Boolean.parseBoolean("test"));
- bo = new Boolean(Boolean.parseBoolean("test"));
+ Boolean bo = Boolean.valueOf(Boolean.parseBoolean("true"));
+ bo = new Boolean(Boolean.parseBoolean("true"));
Byte b = Byte.valueOf(Byte.parseByte("1"));
b = new Byte(Byte.parseByte("1"));
Short s = Short.valueOf(Short.parseShort("1"));
@@ -70,4 +70,22 @@
Double d = Double.valueOf(Double.parseDouble("1"));
d = new Double(Double.parseDouble("1"));
}
+
+ public void testBoxToUnbox()
+ {
+ boolean bo = new Boolean(true).booleanValue();
+ bo = Boolean.valueOf(true).booleanValue();
+ byte b = new Byte((byte)1).byteValue();
+ b = Byte.valueOf((byte)1).byteValue();
+ short s = new Short((short)2).shortValue();
+ s = Short.valueOf((short) 2).shortValue();
+ int i = new Integer(3).intValue();
+ i = Integer.valueOf(3).intValue();
+ long l = new Long(4).longValue();
+ l = Long.valueOf(4).longValue();
+ float f = new Float(5.0f).floatValue();
+ f = Float.valueOf(5.0f).floatValue();
+ double d = new Double(6.0).doubleValue();
+ d = Double.valueOf(6.0).doubleValue();
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-25 12:47:44 UTC (rev 867)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-26 07:53:26 UTC (rev 868)
@@ -38,6 +38,7 @@
private static final int SEEN_VALUE = 1;
private static final int SEEN_VALUEOF = 2;
private static final int SEEN_PARSE = 3;
+ private static final int SEEN_CTOR = 4;
private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>();
static {
@@ -95,12 +96,12 @@
}
} else if (seen == INVOKESTATIC) {
boxClass = getClassConstantOperand();
- if (boxClasses.containsKey(boxClass)) {
+ String[] boxSigs = boxClasses.get(boxClass);
+ if (boxSigs != null) {
if ("valueOf".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) {
if (!"java/lang/Boolean".equals(boxClass) || (getClassContext().getJavaClass().getMajor() >= Constants.MAJOR_1_5))
state = SEEN_VALUEOF;
- }
- else {
+ } else {
String parseSig = parseClasses.get(boxClass);
if (parseSig != null) {
String methodInfo = getNameConstantOperand() + getSigConstantOperand();
@@ -110,6 +111,14 @@
}
}
}
+ } else if (seen == INVOKESPECIAL) {
+ boxClass = getClassConstantOperand();
+ String[] boxSigs = boxClasses.get(boxClass);
+ if (boxSigs != null) {
+ if ("<init>".equals(getNameConstantOperand()) && boxSigs[1].equals(getSigConstantOperand())) {
+ state = SEEN_CTOR;
+ }
+ }
}
break;
@@ -146,6 +155,19 @@
state = SEEN_NOTHING;
break;
+ case SEEN_CTOR:
+ if (seen == INVOKEVIRTUAL) {
+ String[] boxSigs = boxClasses.get(boxClass);
+ if (boxSigs[0].equals(getNameConstantOperand() + getSigConstantOperand())) {
+ bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_BOX_TO_UNBOX", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ state = SEEN_NOTHING;
+ break;
+
case SEEN_VALUEOF:
if (seen == INVOKEVIRTUAL) {
String[] boxSigs = boxClasses.get(boxClass);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-26 08:01:54
|
Revision: 869
http://svn.sourceforge.net/fb-contrib/?rev=869&view=rev
Author: dbrosius
Date: 2007-02-26 00:01:55 -0800 (Mon, 26 Feb 2007)
Log Message:
-----------
add detector for
BoxedPrimitive.valueOf(1).primitiveValue()
Modified Paths:
--------------
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-02-26 07:53:26 UTC (rev 868)
+++ trunk/fb-contrib/etc/messages.xml 2007-02-26 08:01:55 UTC (rev 869)
@@ -1104,6 +1104,9 @@
convert it back to a primitive. Just use the primitive value instead.</p>
<pre>
primitive i = new BoxedPrimitive(1).primitiveValue();
+ or
+ primitive i = BoxedPrimitive.valueOf(1).primitiveValue();
+
should just use
primitive i = 1;
</pre>
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-26 07:53:26 UTC (rev 868)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-26 08:01:55 UTC (rev 869)
@@ -36,9 +36,10 @@
{
private static final int SEEN_NOTHING = 0;
private static final int SEEN_VALUE = 1;
- private static final int SEEN_VALUEOF = 2;
+ private static final int SEEN_VALUEOFSTRING = 2;
private static final int SEEN_PARSE = 3;
private static final int SEEN_CTOR = 4;
+ private static final int SEEN_VALUEOFPRIMITIVE = 5;
private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>();
static {
@@ -98,9 +99,14 @@
boxClass = getClassConstantOperand();
String[] boxSigs = boxClasses.get(boxClass);
if (boxSigs != null) {
- if ("valueOf".equals(getNameConstantOperand()) && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) {
- if (!"java/lang/Boolean".equals(boxClass) || (getClassContext().getJavaClass().getMajor() >= Constants.MAJOR_1_5))
- state = SEEN_VALUEOF;
+ if ("valueOf".equals(getNameConstantOperand())) {
+ String sig = getSigConstantOperand();
+ if (sig.startsWith("(Ljava/lang/String;)")) {
+ if (!"java/lang/Boolean".equals(boxClass) || (getClassContext().getJavaClass().getMajor() >= Constants.MAJOR_1_5))
+ state = SEEN_VALUEOFSTRING;
+ } else {
+ state = SEEN_VALUEOFPRIMITIVE;
+ }
} else {
String parseSig = parseClasses.get(boxClass);
if (parseSig != null) {
@@ -156,6 +162,7 @@
break;
case SEEN_CTOR:
+ case SEEN_VALUEOFPRIMITIVE:
if (seen == INVOKEVIRTUAL) {
String[] boxSigs = boxClasses.get(boxClass);
if (boxSigs[0].equals(getNameConstantOperand() + getSigConstantOperand())) {
@@ -168,7 +175,7 @@
state = SEEN_NOTHING;
break;
- case SEEN_VALUEOF:
+ case SEEN_VALUEOFSTRING:
if (seen == INVOKEVIRTUAL) {
String[] boxSigs = boxClasses.get(boxClass);
if (boxSigs[0].equals(getNameConstantOperand() + getSigConstantOperand())) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-26 09:02:31
|
Revision: 871
http://svn.sourceforge.net/fb-contrib/?rev=871&view=rev
Author: dbrosius
Date: 2007-02-26 01:02:31 -0800 (Mon, 26 Feb 2007)
Log Message:
-----------
add check for new Float(f).intValue() and others.
Also filter out valueOf(String, radix) calls
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/NAB_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-02-26 08:11:18 UTC (rev 870)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-02-26 09:02:31 UTC (rev 871)
@@ -115,7 +115,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing"
speed="fast"
- reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF,NAB_NEEDLESS_BOX_TO_UNBOX" />
+ reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF,NAB_NEEDLESS_BOX_TO_UNBOX,NAB_NEEDLESS_BOX_TO_CAST" />
<Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn"
speed="fast"
@@ -312,6 +312,7 @@
<BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_PARSE" category="PERFORMANCE" />
<BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOXING_VALUEOF" category="PERFORMANCE" />
<BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOX_TO_UNBOX" category="PERFORMANCE" experimental="true" />
+ <BugPattern abbrev="NAB" type="NAB_NEEDLESS_BOX_TO_CAST" category="PERFORMANCE" experimental="true" />
<BugPattern abbrev="USBR" type="USBR_UNNECESSARY_STORE_BEFORE_RETURN" category="STYLE" />
<BugPattern abbrev="COM" type="COM_COPIED_OVERRIDDEN_METHOD" category="STYLE" />
<BugPattern abbrev="ABC" type="ABC_ARRAY_BASED_COLLECTIONS" category="CORRECTNESS" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-02-26 08:11:18 UTC (rev 870)
+++ trunk/fb-contrib/etc/messages.xml 2007-02-26 09:02:31 UTC (rev 871)
@@ -1113,6 +1113,25 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="NAB_NEEDLESS_BOX_TO_CAST">
+ <ShortDescription>method creates Boxed primitive from primitive only to cast to another primitive type</ShortDescription>
+ <LongDescription>method {1} creates Boxed primitive from primitive only to cast to another primitive type</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method constructs a Boxed Primitive from a primitive only to call the primitiveValue() method to
+ cast the value to another primitive typee. It is simpler to just use casting</p>
+ <pre>
+ primitive i = new BoxedPrimitive(1.0).primitiveValue();
+ or
+ primitive i = BoxedPrimitive.valueOf(1.0).primitiveValue();
+
+ should just use
+ primitive i = (primitive)1.0;
+ </pre>
+ ]]>
+ </Details>
+ </BugPattern>
<BugPattern type="USBR_UNNECESSARY_STORE_BEFORE_RETURN">
<ShortDescription>method stores return result in local before immediately returning it</ShortDescription>
Modified: trunk/fb-contrib/samples/NAB_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NAB_Sample.java 2007-02-26 08:11:18 UTC (rev 870)
+++ trunk/fb-contrib/samples/NAB_Sample.java 2007-02-26 09:02:31 UTC (rev 871)
@@ -88,4 +88,38 @@
double d = new Double(6.0).doubleValue();
d = Double.valueOf(6.0).doubleValue();
}
+
+ public void testBoxedCast()
+ {
+ short s = new Short((short)2).byteValue();
+ s = Short.valueOf((short) 2).byteValue();
+ int i = new Integer(3).byteValue();
+ i = Integer.valueOf(3).byteValue();
+ i = new Integer(3).shortValue();
+ i = Integer.valueOf(3).shortValue();
+ long l = new Long(4).byteValue();
+ l = Long.valueOf(4).byteValue();
+ l = new Long(4).shortValue();
+ l = Long.valueOf(4).shortValue();
+ l = new Long(4).intValue();
+ l = Long.valueOf(4).intValue();
+ float f = new Float(5.0f).byteValue();
+ f = Float.valueOf(5.0f).byteValue();
+ f = new Float(5.0f).shortValue();
+ f = Float.valueOf(5.0f).shortValue();
+ f = new Float(5.0f).intValue();
+ f = Float.valueOf(5.0f).intValue();
+ f = new Float(5.0f).longValue();
+ f = Float.valueOf(5.0f).longValue();
+ double d = new Double(6.0).byteValue();
+ d = Double.valueOf(6.0).byteValue();
+ d = new Double(6.0).shortValue();
+ d = Double.valueOf(6.0).shortValue();
+ d = new Double(6.0).intValue();
+ d = Double.valueOf(6.0).intValue();
+ d = new Double(6.0).longValue();
+ d = Double.valueOf(6.0).longValue();
+ d = new Double(6.0).floatValue();
+ d = Double.valueOf(6.0).floatValue();
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-26 08:11:18 UTC (rev 870)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-02-26 09:02:31 UTC (rev 871)
@@ -104,7 +104,7 @@
if (sig.startsWith("(Ljava/lang/String;)")) {
if (!"java/lang/Boolean".equals(boxClass) || (getClassContext().getJavaClass().getMajor() >= Constants.MAJOR_1_5))
state = SEEN_VALUEOFSTRING;
- } else {
+ } else if (!sig.startsWith("(Ljava/lang/String;")) {
state = SEEN_VALUEOFPRIMITIVE;
}
} else {
@@ -170,6 +170,11 @@
.addClass(this)
.addMethod(this)
.addSourceLine(this));
+ } else if (getSigConstantOperand().startsWith("()") && getNameConstantOperand().endsWith("Value")) {
+ bugReporter.reportBug(new BugInstance(this, "NAB_NEEDLESS_BOX_TO_CAST", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
}
}
state = SEEN_NOTHING;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-03-18 12:10:19
|
Revision: 882
http://svn.sourceforge.net/fb-contrib/?rev=882&view=rev
Author: dbrosius
Date: 2007-03-16 19:01:58 -0700 (Fri, 16 Mar 2007)
Log Message:
-----------
fix for bug [ 1678805 ] False+: UCC_UNRELATED_COLLECTION_CONTENTS
reused reg slots, and no variable table attribute
Modified Paths:
--------------
trunk/fb-contrib/samples/UCC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java
Modified: trunk/fb-contrib/samples/UCC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UCC_Sample.java 2007-03-13 03:31:20 UTC (rev 881)
+++ trunk/fb-contrib/samples/UCC_Sample.java 2007-03-17 02:01:58 UTC (rev 882)
@@ -1,4 +1,5 @@
import java.awt.Color;
+import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -44,4 +45,17 @@
s.add(new int[]{ 3,2});
s.add(new Color(0, 128, 255));
}
+
+ public void bug1678805()
+ {
+ final File[] files = new File[5];
+ for (int i = 0; i < 5; i++)
+ files[i] = getPath();
+
+ }
+
+ private File getPath()
+ {
+ return new File("c:\\temp");
+ }
}
\ No newline at end of file
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2007-03-13 03:31:20 UTC (rev 881)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2007-03-17 02:01:58 UTC (rev 882)
@@ -145,6 +145,10 @@
OpcodeStack.Item addItm = stack.getStackItem(0);
checkAdd(arrayItm, addItm);
}
+ } else if (seen == ASTORE) {
+ Integer reg = Integer14.valueOf(RegisterUtils.getAStoreReg(this, seen));
+ localCollections.remove(reg);
+ localSourceLineAnnotations.remove(reg);
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-05-27 21:13:54
|
Revision: 884
http://svn.sourceforge.net/fb-contrib/?rev=884&view=rev
Author: dbrosius
Date: 2007-05-27 14:13:53 -0700 (Sun, 27 May 2007)
Log Message:
-----------
don't report .intern on static strings in static initializers
Modified Paths:
--------------
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2007-04-29 19:37:54 UTC (rev 883)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-05-27 21:13:53 UTC (rev 884)
@@ -5,6 +5,7 @@
{
private static final double pi = 3.14;
private static final double e = 2.72;
+ public static final String FALSE_POSITIVE = "INTERN_OK_HERE".intern();
static enum Flap { Smack, Jack };
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-04-29 19:37:54 UTC (rev 883)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-05-27 21:13:53 UTC (rev 884)
@@ -165,13 +165,17 @@
}
} else if ("java/lang/String".equals(className)) {
if ("intern".equals(methodName)) {
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item item = stack.getStackItem(0);
- if (item.getConstant() != null) {
- bugReporter.reportBug(new BugInstance(this, "SPP_INTERN_ON_CONSTANT", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ String owningMethod = getMethod().getName();
+ if (!"<clinit>".equals(owningMethod))
+ {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (item.getConstant() != null) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_INTERN_ON_CONSTANT", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-06-08 02:53:17
|
Revision: 885
http://svn.sourceforge.net/fb-contrib/?rev=885&view=rev
Author: dbrosius
Date: 2007-06-07 19:53:18 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
add check for s.toCharArray()[0]
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 2007-05-27 21:13:53 UTC (rev 884)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-06-08 02:53:18 UTC (rev 885)
@@ -256,7 +256,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri"
speed="fast"
- reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK" />
+ reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
speed="fast"
@@ -363,6 +363,7 @@
<BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" />
<BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" />
<BugPattern abbrev="SPP" type="SPP_INVALID_BOOLEAN_NULL_CHECK" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="SPP" type="SPP_USE_CHARAT" category="PERFORMANCE" experimental="true" />
<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 2007-05-27 21:13:53 UTC (rev 884)
+++ trunk/fb-contrib/etc/messages.xml 2007-06-08 02:53:18 UTC (rev 885)
@@ -1796,6 +1796,18 @@
</Details>
</BugPattern>
+ <BugPattern type="SPP_USE_CHARAT">
+ <ShortDescription>Method fetches character array just to do the equivalent of the charAt method</ShortDescription>
+ <LongDescription>Method {1} fetches character array just to do the equivalent of the charAt method</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method calls the toCharArray method on a String the fetch an array of characters, only
+ to retrieve one of those characters by index. It is more performant to just use the charAt method.
+ </p>
+ ]]>
+ </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 2007-05-27 21:13:53 UTC (rev 884)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-06-08 02:53:18 UTC (rev 885)
@@ -71,4 +71,11 @@
if (e && e.booleanValue())
System.out.println("Booya");
}
+
+ public char usechatAt(String s)
+ {
+ if (s.length() > 0)
+ return s.toCharArray()[0];
+ return ' ';
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-05-27 21:13:53 UTC (rev 884)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-06-08 02:53:18 UTC (rev 885)
@@ -86,6 +86,7 @@
@Override
public void sawOpcode(int seen) {
int reg = -1;
+ String userValue = null;
try {
stack.mergeJumps(this);
@@ -142,6 +143,25 @@
.addSourceLine(this));
}
}
+ } else if ((seen >= ICONST_0) && (seen <= ICONST_3)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ String tca = (String)item.getUserValue();
+ if ("toCharArray".equals(tca)) {
+ userValue = "iconst";
+ }
+ }
+ } else if (seen == CALOAD) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ String ic = (String)item.getUserValue();
+ if ("iconst".equals(ic)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_USE_CHARAT", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
} else if (seen == INVOKEVIRTUAL) {
String className = getClassConstantOperand();
String methodName = getNameConstantOperand();
@@ -178,6 +198,8 @@
}
}
}
+ } else if ("toCharArray".equals(methodName)) {
+ userValue = "toCharArray";
}
} else if ("equals(Ljava/lang/Object;)Z".equals(methodName + getSigConstantOperand())) {
try {
@@ -274,6 +296,11 @@
} finally {
stack.sawOpcode(this, seen);
+ if (userValue != null)
+ {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(userValue);
+ }
lastOpcode = seen;
lastReg = reg;
System.arraycopy(lastPCs, 1, lastPCs, 0, 3);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-06-24 22:58:04
|
Revision: 887
http://svn.sourceforge.net/fb-contrib/?rev=887&view=rev
Author: dbrosius
Date: 2007-06-24 15:58:05 -0700 (Sun, 24 Jun 2007)
Log Message:
-----------
Initial checkin of UAA - doesn't work a lick
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-06-24 22:23:02 UTC (rev 886)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-06-24 22:58:05 UTC (rev 887)
@@ -277,10 +277,11 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse"
speed="slow"
- reports="SJVU_SUSPICIOUS_JDK_VERSION_USE"
- hidden="true"
- disabled="true" />
+ reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseAddAll"
+ speed="fast"
+ reports="UAA_USE_ADD_ALL" />
<!-- BugPattern -->
@@ -370,4 +371,5 @@
<BugPattern abbrev="DWI" type="DWI_MODIFYING_WHILE_ITERATING" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="USS" type="USS_USE_STRING_SPLIT" category="STYLE" />
<BugPattern abbrev="SJVU" type="SJVU_SUSPICIOUS_JDK_VERSION_USE" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="UAA" type="UAA_USE_ADD_ALL" category="STYLE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-06-24 22:23:02 UTC (rev 886)
+++ trunk/fb-contrib/etc/messages.xml 2007-06-24 22:58:05 UTC (rev 887)
@@ -754,6 +754,18 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseAddAll">
+ <Details>
+ <![CDATA[
+ <p>looks for loops that transfers the contents of one collection to another. These collection sources might
+ be local variables or member fields, including sets, maps key/values, lists, or arrays. It is simpler to
+ just use the addAll method of the collection class. In the case where the source is an array, you can use
+ Arrays.asList(array), and use that as the source to addAll.</p>
+ <p>It is a fast detector.</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -1897,6 +1909,19 @@
</Details>
</BugPattern>
+ <BugPattern type="UAA_USE_ADD_ALL">
+ <ShortDescription>method uses simple loop to copy contents of one collection to another</ShortDescription>
+ <LongDescription>method {1} uses simple loop to copy contents of one colleciton to another</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method uses a simple for loop to copy the contents of a set, list, map key/value, array or other collection
+ to another collection. It is simpler and more straight forward to just call the addAll method of the destination collection
+ passing in the source collection. In the case that the source is an array, you can use Array.asList method to massage the array
+ into a collection</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -1961,4 +1986,5 @@
<BugCode abbrev="DWI">Deleting While Iterating</BugCode>
<BugCode abbrev="USS">Use String Split</BugCode>
<BugCode abbrev="SJVU">Suspicious JDK Version Use</BugCode>
+ <BugCode abbrev="UAA">Use Add All</BugCode>
</MessageCollection>
\ No newline at end of file
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-24 22:58:05 UTC (rev 887)
@@ -0,0 +1,218 @@
+package com.mebigfatguy.fbcontrib.detect;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.JavaClass;
+
+import com.mebigfatguy.fbcontrib.utils.Integer14;
+import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+/**
+ * looks for loops that transfers the contents of one collection to another. These collection sources
+ * might be local variables or member fields, including sets, maps key/values, lists, or arrays.
+ * It is simpler to just use the addAll method of the collection class. In the case where the
+ * source is an array, you can use Arrays.asList(array), and use that as the source to addAll.
+ */
+public class UseAddAll extends BytecodeScanningDetector {
+ private static JavaClass collectionClass;
+ private static ClassNotFoundException ex;
+ static {
+ try {
+ collectionClass = Repository.lookupClass("java/util/Collection");
+ } catch (ClassNotFoundException cnfe) {
+ collectionClass = null;
+ ex = cnfe;
+ }
+ }
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ private Map<Integer, Object> userValues;
+
+ /**
+ * constructs a UTA detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public UseAddAll(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ /**
+ * implements the visitor to create and clear the stack, and report missing class errors
+ *
+ * @param classContext the context object of the currently parsed class
+ */
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ if (collectionClass == null) {
+ if (ex != null) {
+ bugReporter.reportMissingClass(ex);
+ ex = null;
+ }
+ return;
+ }
+
+ try {
+ stack = new OpcodeStack();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ }
+ }
+
+ /**
+ * implements the visitor to reset the stack and uservalues
+ *
+ * @param obj the context object of the currently parsed code block
+ */
+ @Override
+ public void visitCode(Code obj) {
+ try {
+ stack.resetForMethodEntry(this);
+ userValues = new HashMap<Integer, Object>();
+ super.visitCode(obj);
+ } finally {
+ userValues = null;
+ }
+ }
+
+ /**
+ * implements the visitor to look for manually copying of collections to collections
+ *
+ * @param seen the opcode of the currently parsed instruction
+ */
+ @Override
+ public void sawOpcode(int seen) {
+ int reg = -1;
+ Object uValue = null;
+ boolean sawAlias = false;
+ boolean sawLoad = false;
+
+ try {
+ if (seen == INVOKEINTERFACE) {
+ String methodName = getNameConstantOperand();
+ String signature = getSigConstantOperand();
+ if ("size".equals(methodName) && "()I".equals(signature)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ reg = isLocalCollection(itm);
+ if (reg >= 0) {
+ sawAlias = true;
+ }
+ }
+ } else if ("get".equals(methodName) && "(I)Ljava/lang/Object;".equals(signature)) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item itm = stack.getStackItem(1);
+ reg = isLocalCollection(itm);
+ if (reg >= 0) {
+ sawAlias = true;
+ }
+ }
+ } else if ("keySet".equals(methodName) || "values".equals(methodName) || "iterator".equals(methodName) || "next".equals(methodName)) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item itm = stack.getStackItem(1);
+ reg = isLocalCollection(itm);
+ if (reg >= 0) {
+ sawAlias = true;
+ }
+ }
+ } else if ("add".equals(methodName) && "(Ljava/lang/Object;)Z".equals(signature)) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item colItem = stack.getStackItem(1);
+ OpcodeStack.Item valueItem = stack.getStackItem(0);
+ reg = isLocalCollection(colItem);
+ if ((reg >= 0)
+ && (valueItem.getUserValue() != null)) {
+ bugReporter.reportBug(new BugInstance(this, "UTA_USE_ADD_ALL", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3)))
+ || ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) {
+ if (stack.getStackDepth() > 0) {
+ uValue = stack.getStackItem(0).getUserValue();
+ userValues.put(Integer14.valueOf(RegisterUtils.getStoreReg(this, seen)), uValue);
+ }
+ } else if (((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3)))
+ || ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3)))) {
+ sawLoad = true;
+ } else if (seen == IF_ICMPGE) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item itm1 = stack.getStackItem(1);
+ OpcodeStack.Item itm2 = stack.getStackItem(0);
+ reg = itm1.getRegisterNumber();
+ if ((reg >= 0) && (itm1.couldBeZero())) {
+ uValue = itm2.getUserValue();
+ if (uValue != null) {
+ userValues.put(Integer14.valueOf(reg), uValue);
+ }
+ }
+ }
+ } else if (seen == CHECKCAST) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ uValue = itm.getUserValue();
+ if (uValue instanceof Integer) {
+ reg = ((Integer)uValue).intValue();
+ sawAlias = true;
+ }
+ }
+ }
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (sawAlias) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ itm.setUserValue(Integer14.valueOf(reg));
+ }
+ } else if (sawLoad) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ reg = itm.getRegisterNumber();
+ if (reg >= 0) {
+ uValue = userValues.get(Integer14.valueOf(reg));
+ itm.setUserValue(uValue);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * determines if the stack item refers to a collection that is stored in a local variable
+ *
+ * param item the stack item to check
+ *
+ * @return the register number of the local variable that this collection refers to, or -1
+ * @throws ClassNotFoundException if the items class cannot be found
+ */
+ private int isLocalCollection(OpcodeStack.Item item) throws ClassNotFoundException {
+ Integer aliasReg = (Integer)item.getUserValue();
+ if (aliasReg != null)
+ return aliasReg.intValue();
+
+ int reg = item.getRegisterNumber();
+ if (reg < 0)
+ return -1;
+
+ JavaClass cls = item.getJavaClass();
+ if ((cls != null) && cls.implementationOf(collectionClass))
+ return reg;
+
+ return -1;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-09-15 18:59:24
|
Revision: 905
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=905&view=rev
Author: dbrosius
Date: 2007-09-15 11:59:26 -0700 (Sat, 15 Sep 2007)
Log Message:
-----------
initial checkin - NCS detector
Modified Paths:
--------------
trunk/fb-contrib/etc/bugdescriptions.xsl
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/BAS_Sample.java
trunk/fb-contrib/samples/DWI_Sample.java
trunk/fb-contrib/samples/ITC_Sample.java
trunk/fb-contrib/samples/LEST_Sample.java
trunk/fb-contrib/samples/NMCS_Sample.java
trunk/fb-contrib/samples/NOS_Sample.java
trunk/fb-contrib/samples/NRTL_Sample.java
trunk/fb-contrib/samples/PIS_Sample.java
trunk/fb-contrib/samples/RMC_Sample.java
trunk/fb-contrib/samples/S508C_Sample.java
trunk/fb-contrib/samples/SACM_Sample.java
trunk/fb-contrib/samples/SCII_Sample.java
trunk/fb-contrib/samples/SC_Sample.java
trunk/fb-contrib/samples/SIL_Sample.java
trunk/fb-contrib/samples/SJVU_Sample.java
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/samples/TR_Sample.java
trunk/fb-contrib/samples/UAA_Sample.java
trunk/fb-contrib/samples/UCPM_Sample.java
trunk/fb-contrib/samples/UEC_Sample.java
trunk/fb-contrib/samples/URV_Sample.java
trunk/fb-contrib/samples/USS_Sample.java
trunk/fb-contrib/samples/UTA_Sample.java
Added Paths:
-----------
trunk/fb-contrib/samples/NCS_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java
Property Changed:
----------------
trunk/fb-contrib/build.properties
trunk/fb-contrib/etc/bugdescriptions.xsl
trunk/fb-contrib/samples/BAS_Sample.java
trunk/fb-contrib/samples/DWI_Sample.java
trunk/fb-contrib/samples/ITC_Sample.java
trunk/fb-contrib/samples/LEST_Sample.java
trunk/fb-contrib/samples/NMCS_Sample.java
trunk/fb-contrib/samples/NOS_Sample.java
trunk/fb-contrib/samples/NRTL_Sample.java
trunk/fb-contrib/samples/PIS_Sample.java
trunk/fb-contrib/samples/RMC_Sample.java
trunk/fb-contrib/samples/S508C_Sample.java
trunk/fb-contrib/samples/SACM_Sample.java
trunk/fb-contrib/samples/SCII_Sample.java
trunk/fb-contrib/samples/SC_Sample.java
trunk/fb-contrib/samples/SIL_Sample.java
trunk/fb-contrib/samples/SJVU_Sample.java
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/samples/TR_Sample.java
trunk/fb-contrib/samples/UAA_Sample.java
trunk/fb-contrib/samples/UCPM_Sample.java
trunk/fb-contrib/samples/UEC_Sample.java
trunk/fb-contrib/samples/URV_Sample.java
trunk/fb-contrib/samples/USS_Sample.java
trunk/fb-contrib/samples/UTA_Sample.java
trunk/fb-contrib/samples/samples-bugs.xml
Property changes on: trunk/fb-contrib/build.properties
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/etc/bugdescriptions.xsl
===================================================================
--- trunk/fb-contrib/etc/bugdescriptions.xsl 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/etc/bugdescriptions.xsl 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,38 +1,38 @@
-<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
- <xsl:template match="/MessageCollection">
- <html>
- <head><title>fb-contrib: Bug Descriptions</title></head>
- <body background="true">
- <div style="position:absolute;top:0;left:0;width:256;height:65535;z-index:1;background-image:url(blend.jpg);">
- </div>
-
- <div style="position:absolute;top:20;left:20;z-index:2;">
- <h1>fb-contrib: Bug Descriptions</h1>
-
- <table border="1" width="100%">
- <xsl:apply-templates select="BugCode"/>
- </table>
- </div>
- </body>
- </html>
- </xsl:template>
-
- <xsl:template match="BugCode">
- <xsl:call-template name="Pattern">
- <xsl:with-param name="abbrev"><xsl:value-of select="@abbrev"/></xsl:with-param>
- </xsl:call-template>
- </xsl:template>
-
- <xsl:template name="Pattern">
- <xsl:param name="abbrev"/>
- <xsl:for-each select="//BugPattern[starts-with(@type,$abbrev)]">
- <tr><td><b><xsl:value-of select="@type"/></b></td></tr>
- <xsl:variable name="desc1"><xsl:value-of select="normalize-space(Details/text())"/></xsl:variable>
- <xsl:variable name="desc2"><xsl:value-of select="substring($desc1, 9)"/></xsl:variable>
- <xsl:variable name="desc"><xsl:value-of select="substring($desc2, 0, string-length($desc2) - 3)"/></xsl:variable>
- <tr><td><xsl:copy-of select="$desc"/></td></tr>
- </xsl:for-each>
- </xsl:template>
-
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:template match="/MessageCollection">
+ <html>
+ <head><title>fb-contrib: Bug Descriptions</title></head>
+ <body background="true">
+ <div style="position:absolute;top:0;left:0;width:256;height:65535;z-index:1;background-image:url(blend.jpg);">
+ </div>
+
+ <div style="position:absolute;top:20;left:20;z-index:2;">
+ <h1>fb-contrib: Bug Descriptions</h1>
+
+ <table border="1" width="100%">
+ <xsl:apply-templates select="BugCode"/>
+ </table>
+ </div>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="BugCode">
+ <xsl:call-template name="Pattern">
+ <xsl:with-param name="abbrev"><xsl:value-of select="@abbrev"/></xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="Pattern">
+ <xsl:param name="abbrev"/>
+ <xsl:for-each select="//BugPattern[starts-with(@type,$abbrev)]">
+ <tr><td><b><xsl:value-of select="@type"/></b></td></tr>
+ <xsl:variable name="desc1"><xsl:value-of select="normalize-space(Details/text())"/></xsl:variable>
+ <xsl:variable name="desc2"><xsl:value-of select="substring($desc1, 9)"/></xsl:variable>
+ <xsl:variable name="desc"><xsl:value-of select="substring($desc2, 0, string-length($desc2) - 3)"/></xsl:variable>
+ <tr><td><xsl:copy-of select="$desc"/></td></tr>
+ </xsl:for-each>
+ </xsl:template>
+
</xsl:transform>
\ No newline at end of file
Property changes on: trunk/fb-contrib/etc/bugdescriptions.xsl
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-09-15 18:59:26 UTC (rev 905)
@@ -287,6 +287,10 @@
speed="fast"
reports="MRC_METHOD_RETURNS_CONSTANT" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessCustomSerialization"
+ speed="fast"
+ reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" />
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -377,4 +381,5 @@
<BugPattern abbrev="SJVU" type="SJVU_SUSPICIOUS_JDK_VERSION_USE" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="UAA" type="UAA_USE_ADD_ALL" category="STYLE" experimental="true" />
<BugPattern abbrev="MRC" type="MRC_METHOD_RETURNS_CONSTANT" category="STYLE" experimental="true" />
+ <BugPattern abbrev="NCS" type="NCS_NEEDLESS_CUSTOM_SERIALIZATION" category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/etc/messages.xml 2007-09-15 18:59:26 UTC (rev 905)
@@ -778,7 +778,19 @@
</Details>
</Detector>
- <!-- BugPattern -->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessCustomSerialization">
+ <Details>
+ <![CDATA[
+ <p>looks for classes that implement the Serializable interface and implement the
+ standard readObject and writeObject methods by simply deferring to the Stream
+ parameter's defaultReadObject or defaultWriteObject and nothing else. As this is the
+ built in behavior, these methods are not needed.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
+ <!-- BugPattern -->
<BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING">
<ShortDescription>method passes simple concatenating string in StringBuffer or StringBuilder append</ShortDescription>
@@ -1946,6 +1958,17 @@
</Details>
</BugPattern>
+ <BugPattern type="NCS_NEEDLESS_CUSTOM_SERIALIZATION">
+ <ShortDescription>method needlessly implements what is default streaming behavior</ShortDescription>
+ <LongDescription>method {1} needlessly implements what is default streaming behavior</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method implements the Serializable interface by performing the same operations that
+ would be done if this method did not exist. Since this is the case, this method is not needed.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -2012,4 +2035,5 @@
<BugCode abbrev="SJVU">Suspicious JDK Version Use</BugCode>
<BugCode abbrev="UAA">Use Add All</BugCode>
<BugCode abbrev="MRC">Method Returns Constant</BugCode>
+ <BugCode abbrev="NCS">Needless Custom Serialization</BugCode>
</MessageCollection>
\ No newline at end of file
Modified: trunk/fb-contrib/samples/BAS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/BAS_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/BAS_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,91 +1,91 @@
-import java.util.List;
-
-public class BAS_Sample
-{
- public void testIfScope(String s)
- {
- Object o = new Object();
- if (s.equals("Foo"))
- {
- s = o.toString();
- }
- }
-
- public String testFPForScope(String s)
- {
- Object o = new Object();
- while (s.length() > 0)
- {
- o = s.substring(0, 1);
- s = s.substring(1);
- }
- return s;
- }
-
- public String testFP2Scopes(String s)
- {
- Object o = new Object();
- if (s.equals("Boo"))
- s = o.toString();
- else if (s.equals("Hoo"))
- s = o.toString();
-
- return s;
- }
-
- public String test2InnerScopes(String s)
- {
- Object o = new Object();
- if (s != null)
- {
- if (s.equals("Boo"))
- s = o.toString();
- else if (s.equals("Hoo"))
- s = o.toString();
- }
-
- return s;
- }
-
- public String testFPLoopCond(List<String> in)
- {
- StringBuilder sb = new StringBuilder();
- for (String s : in)
- {
- sb.append(s);
- }
- return sb.toString();
- }
-
- public List<String> getList()
- {
- return null;
- }
-
- public String testSwitch(int a)
- {
- String v = "Test";
-
- switch (a)
- {
- case 1:
- v = "Testa";
- break;
-
- case 2:
- v = "Tesseract";
- break;
-
- case 3:
- v = "Testy";
- break;
-
- default:
- v = "Rossa";
- break;
- }
-
- return null;
- }
-
-}
+import java.util.List;
+
+public class BAS_Sample
+{
+ public void testIfScope(String s)
+ {
+ Object o = new Object();
+ if (s.equals("Foo"))
+ {
+ s = o.toString();
+ }
+ }
+
+ public String testFPForScope(String s)
+ {
+ Object o = new Object();
+ while (s.length() > 0)
+ {
+ o = s.substring(0, 1);
+ s = s.substring(1);
+ }
+ return s;
+ }
+
+ public String testFP2Scopes(String s)
+ {
+ Object o = new Object();
+ if (s.equals("Boo"))
+ s = o.toString();
+ else if (s.equals("Hoo"))
+ s = o.toString();
+
+ return s;
+ }
+
+ public String test2InnerScopes(String s)
+ {
+ Object o = new Object();
+ if (s != null)
+ {
+ if (s.equals("Boo"))
+ s = o.toString();
+ else if (s.equals("Hoo"))
+ s = o.toString();
+ }
+
+ return s;
+ }
+
+ public String testFPLoopCond(List<String> in)
+ {
+ StringBuilder sb = new StringBuilder();
+ for (String s : in)
+ {
+ sb.append(s);
+ }
+ return sb.toString();
+ }
+
+ public List<String> getList()
+ {
+ return null;
+ }
+
+ public String testSwitch(int a)
+ {
+ String v = "Test";
+
+ switch (a)
+ {
+ case 1:
+ v = "Testa";
+ break;
+
+ case 2:
+ v = "Tesseract";
+ break;
+
+ case 3:
+ v = "Testy";
+ break;
+
+ default:
+ v = "Rossa";
+ break;
+ }
+
+ return null;
+ }
+
+}
Property changes on: trunk/fb-contrib/samples/BAS_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/DWI_Sample.java
===================================================================
--- trunk/fb-contrib/samples/DWI_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/DWI_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,39 +1,39 @@
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-public class DWI_Sample
-{
- Set<String> avail;
-
- public void deleteOdds(Set<Integer> bagOInts)
- {
- Iterator<Integer> it = bagOInts.iterator();
- while (it.hasNext())
- {
- Integer i = it.next();
- if ((i.intValue() & 0x01) == 1)
- bagOInts.remove(i);
- }
- }
-
- public void addIf(Set<String> s, Collection<String> c) {
- for (String ss : s)
- {
- if (ss.equals("addem"))
- s.addAll(c);
- }
- }
-
- public void fpUnaliased()
- {
- Iterator<String> it = avail.iterator();
- avail = new HashSet<String>();
-
- while (it.hasNext())
- {
- avail.add(it.next() + "booya");
- }
- }
-}
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class DWI_Sample
+{
+ Set<String> avail;
+
+ public void deleteOdds(Set<Integer> bagOInts)
+ {
+ Iterator<Integer> it = bagOInts.iterator();
+ while (it.hasNext())
+ {
+ Integer i = it.next();
+ if ((i.intValue() & 0x01) == 1)
+ bagOInts.remove(i);
+ }
+ }
+
+ public void addIf(Set<String> s, Collection<String> c) {
+ for (String ss : s)
+ {
+ if (ss.equals("addem"))
+ s.addAll(c);
+ }
+ }
+
+ public void fpUnaliased()
+ {
+ Iterator<String> it = avail.iterator();
+ avail = new HashSet<String>();
+
+ while (it.hasNext())
+ {
+ avail.add(it.next() + "booya");
+ }
+ }
+}
Property changes on: trunk/fb-contrib/samples/DWI_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/ITC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/ITC_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/ITC_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,19 +1,19 @@
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Vector;
-
-public class ITC_Sample
-{
- public String test(List<String> l)
- {
- if (l instanceof ArrayList)
- return (String)((ArrayList)l).remove(0);
- else if (l instanceof LinkedList)
- return (String)((LinkedList) l).removeFirst();
- else if (l instanceof Vector)
- return (String)((Vector) l).remove(0);
- else
- return null;
- }
-}
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Vector;
+
+public class ITC_Sample
+{
+ public String test(List<String> l)
+ {
+ if (l instanceof ArrayList)
+ return (String)((ArrayList)l).remove(0);
+ else if (l instanceof LinkedList)
+ return (String)((LinkedList) l).removeFirst();
+ else if (l instanceof Vector)
+ return (String)((Vector) l).remove(0);
+ else
+ return null;
+ }
+}
Property changes on: trunk/fb-contrib/samples/ITC_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/LEST_Sample.java
===================================================================
--- trunk/fb-contrib/samples/LEST_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/LEST_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,61 +1,61 @@
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class LEST_Sample
-{
- public Date testLest1(String input)
- {
- try
- {
- DateFormat df = new SimpleDateFormat("YYYY");
- return df.parse(input);
- }
- catch (ParseException pe)
- {
- throw new IllegalArgumentException(pe.getMessage());
- }
- }
-
- public Date testLest2(String input)
- {
- try
- {
- DateFormat df = new SimpleDateFormat("YYYY");
- return df.parse(input);
- }
- catch (ParseException pe)
- {
- throw new IllegalArgumentException(pe.getMessage(), pe);
- }
- }
-
- public Date testLestFP1(String input) throws ParseException
- {
- try
- {
- DateFormat df = new SimpleDateFormat("YYYY");
- return df.parse(input);
- }
- catch (ParseException pe)
- {
- throw pe;
- }
- }
-
- public Date testLestFP2(String input)
- {
- try
- {
- DateFormat df = new SimpleDateFormat("YYYY");
- return df.parse(input);
- }
- catch (ParseException pe)
- {
- IllegalArgumentException iae = new IllegalArgumentException(pe.getMessage());
- iae.initCause(pe);
- throw iae;
- }
- }
-}
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class LEST_Sample
+{
+ public Date testLest1(String input)
+ {
+ try
+ {
+ DateFormat df = new SimpleDateFormat("YYYY");
+ return df.parse(input);
+ }
+ catch (ParseException pe)
+ {
+ throw new IllegalArgumentException(pe.getMessage());
+ }
+ }
+
+ public Date testLest2(String input)
+ {
+ try
+ {
+ DateFormat df = new SimpleDateFormat("YYYY");
+ return df.parse(input);
+ }
+ catch (ParseException pe)
+ {
+ throw new IllegalArgumentException(pe.getMessage(), pe);
+ }
+ }
+
+ public Date testLestFP1(String input) throws ParseException
+ {
+ try
+ {
+ DateFormat df = new SimpleDateFormat("YYYY");
+ return df.parse(input);
+ }
+ catch (ParseException pe)
+ {
+ throw pe;
+ }
+ }
+
+ public Date testLestFP2(String input)
+ {
+ try
+ {
+ DateFormat df = new SimpleDateFormat("YYYY");
+ return df.parse(input);
+ }
+ catch (ParseException pe)
+ {
+ IllegalArgumentException iae = new IllegalArgumentException(pe.getMessage());
+ iae.initCause(pe);
+ throw iae;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/samples/LEST_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/fb-contrib/samples/NCS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NCS_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/NCS_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -0,0 +1,18 @@
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+
+public class NCS_Sample implements Serializable
+{
+ private void writeObject(ObjectOutputStream oos) throws IOException
+ {
+ oos.defaultWriteObject();
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
+ {
+ ois.defaultReadObject();
+ }
+}
Property changes on: trunk/fb-contrib/samples/NCS_Sample.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/NMCS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NMCS_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/NMCS_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,57 +1,57 @@
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Vector;
-
-public class NMCS_Sample
-{
- private static List<String> test1 = new Vector<String>();
- static {
- test1.add("one");
- test1.add("two");
- test1.add("three");
- }
-
- private Map<String, String> test2 = new Hashtable<String, String>();
-
- private Set<String> test3 = new HashSet<String>();
-
- private List<String> test4 = new Vector<String>();
-
- public String test1()
- {
- StringBuffer sb = new StringBuffer();
- String comma = "";
- for (String s : test1)
- {
- sb.append(comma);
- comma = ",";
- sb.append(s);
- }
-
- return sb.toString();
- }
-
- public String test2()
- {
- test2 = new Hashtable<String, String>();
-
- return test2.get("foo");
- }
-
- public Set<String> test3()
- {
- Set<String> temp = test3;
- temp.add("Foo");
- return temp;
- }
-
- public List<String> test4(boolean b1, boolean b2)
- {
- return b1 ? test4 :
- b2 ? new Vector<String>() : test4;
- }
-
-}
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+public class NMCS_Sample
+{
+ private static List<String> test1 = new Vector<String>();
+ static {
+ test1.add("one");
+ test1.add("two");
+ test1.add("three");
+ }
+
+ private Map<String, String> test2 = new Hashtable<String, String>();
+
+ private Set<String> test3 = new HashSet<String>();
+
+ private List<String> test4 = new Vector<String>();
+
+ public String test1()
+ {
+ StringBuffer sb = new StringBuffer();
+ String comma = "";
+ for (String s : test1)
+ {
+ sb.append(comma);
+ comma = ",";
+ sb.append(s);
+ }
+
+ return sb.toString();
+ }
+
+ public String test2()
+ {
+ test2 = new Hashtable<String, String>();
+
+ return test2.get("foo");
+ }
+
+ public Set<String> test3()
+ {
+ Set<String> temp = test3;
+ temp.add("Foo");
+ return temp;
+ }
+
+ public List<String> test4(boolean b1, boolean b2)
+ {
+ return b1 ? test4 :
+ b2 ? new Vector<String>() : test4;
+ }
+
+}
Property changes on: trunk/fb-contrib/samples/NMCS_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/NOS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NOS_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/NOS_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,30 +1,30 @@
-import java.util.Map;
-
-public class NOS_Sample {
- private Object lock = new Object();
-
- public String test(Object o) {
- synchronized(o) {
- return o.toString();
- }
- }
-
- public String test2(Object o) {
- synchronized(this) {
- return o.toString();
- }
- }
-
- public String test3(Map m) {
- String v = (String)m.get("boo");
- synchronized (v) {
- return v.substring(0,1);
- }
- }
-
- public String test4(Object o) {
- synchronized(lock) {
- return o.toString();
- }
- }
-}
+import java.util.Map;
+
+public class NOS_Sample {
+ private Object lock = new Object();
+
+ public String test(Object o) {
+ synchronized(o) {
+ return o.toString();
+ }
+ }
+
+ public String test2(Object o) {
+ synchronized(this) {
+ return o.toString();
+ }
+ }
+
+ public String test3(Map m) {
+ String v = (String)m.get("boo");
+ synchronized (v) {
+ return v.substring(0,1);
+ }
+ }
+
+ public String test4(Object o) {
+ synchronized(lock) {
+ return o.toString();
+ }
+ }
+}
Property changes on: trunk/fb-contrib/samples/NOS_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/NRTL_Sample.java
===================================================================
--- trunk/fb-contrib/samples/NRTL_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/NRTL_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,34 +1,34 @@
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspTagException;
-import javax.servlet.jsp.tagext.TagSupport;
-
-public class NRTL_Sample extends TagSupport {
- private String sample;
- private String sample2;
-
- public void setSample(String s) {
- sample = s;
- }
-
- @Override
- public int doStartTag() throws JspException {
- try {
- sample += Math.random();
- sample2 += sample;
- pageContext.getOut().print(sample2);
- } catch (Exception ex) {
- throw new JspTagException("NRTL_Sample: " + ex.getMessage());
- }
- return SKIP_BODY;
- }
-
- public void setSample2(String s) {
- sample2 = s;
- }
-
- @Override
- public int doEndTag() {
- return EVAL_PAGE;
- }
-
-}
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+public class NRTL_Sample extends TagSupport {
+ private String sample;
+ private String sample2;
+
+ public void setSample(String s) {
+ sample = s;
+ }
+
+ @Override
+ public int doStartTag() throws JspException {
+ try {
+ sample += Math.random();
+ sample2 += sample;
+ pageContext.getOut().print(sample2);
+ } catch (Exception ex) {
+ throw new JspTagException("NRTL_Sample: " + ex.getMessage());
+ }
+ return SKIP_BODY;
+ }
+
+ public void setSample2(String s) {
+ sample2 = s;
+ }
+
+ @Override
+ public int doEndTag() {
+ return EVAL_PAGE;
+ }
+
+}
Property changes on: trunk/fb-contrib/samples/NRTL_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/PIS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/PIS_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/PIS_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,60 +1,60 @@
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
-public class PIS_Sample
-{
- public static void main(String[] args)
- {
- try
- {
- B b = new B();
- b.a = 100;
- b.b = 100;
- D d = new D();
- d.a = 100;
- d.b = 100;
- d.c = 100;
- d.d = 100;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(b);
- oos.writeObject(d);
- oos.flush();
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ObjectInputStream ois = new ObjectInputStream(bais);
- B b2 = (B)ois.readObject();
- D d2 = (D)ois.readObject();
- if ((b.a == b2.a) && (b.b == b2.b))
- System.out.println("Equal!");
- if ((d.a == d2.a) && (d.b == d2.b) && (d.c == d2.c) && (d.d == d2.d))
- System.out.println("Equal!");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- public static class A
- {
- public int a = 0;
- }
-
- public static class B extends A implements Serializable
- {
- public int b = 1;
- }
-
- public static class C extends B
- {
- public int c = 2;
- }
-
- public static class D extends C
- {
- public int d = 3;
- }
-}
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+public class PIS_Sample
+{
+ public static void main(String[] args)
+ {
+ try
+ {
+ B b = new B();
+ b.a = 100;
+ b.b = 100;
+ D d = new D();
+ d.a = 100;
+ d.b = 100;
+ d.c = 100;
+ d.d = 100;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(b);
+ oos.writeObject(d);
+ oos.flush();
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ B b2 = (B)ois.readObject();
+ D d2 = (D)ois.readObject();
+ if ((b.a == b2.a) && (b.b == b2.b))
+ System.out.println("Equal!");
+ if ((d.a == d2.a) && (d.b == d2.b) && (d.c == d2.c) && (d.d == d2.d))
+ System.out.println("Equal!");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public static class A
+ {
+ public int a = 0;
+ }
+
+ public static class B extends A implements Serializable
+ {
+ public int b = 1;
+ }
+
+ public static class C extends B
+ {
+ public int c = 2;
+ }
+
+ public static class D extends C
+ {
+ public int d = 3;
+ }
+}
Property changes on: trunk/fb-contrib/samples/PIS_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/RMC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/RMC_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/RMC_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,33 +1,33 @@
-import java.nio.ByteBuffer;
-import java.util.Calendar;
-import java.util.Date;
-
-public class RMC_Sample
-{
- String data;
-
- public boolean test1(Calendar c)
- {
- Date d = c.getTime();
- long l = d.getTime();
- Date e = c.getTime();
- long j = e.getTime();
- return l == j;
- }
-
- public void rmcFP(ByteBuffer bb)
- {
- int i = bb.getInt();
- int j = bb.getInt();
- }
-
- @Override
- public boolean equals(Object o)
- {
- RMC_Sample rmc = (RMC_Sample)o;
- if (data.equals("INF") || rmc.data.equals("INF"))
- return false;
-
- return data.equals(rmc.data);
- }
-}
+import java.nio.ByteBuffer;
+import java.util.Calendar;
+import java.util.Date;
+
+public class RMC_Sample
+{
+ String data;
+
+ public boolean test1(Calendar c)
+ {
+ Date d = c.getTime();
+ long l = d.getTime();
+ Date e = c.getTime();
+ long j = e.getTime();
+ return l == j;
+ }
+
+ public void rmcFP(ByteBuffer bb)
+ {
+ int i = bb.getInt();
+ int j = bb.getInt();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ RMC_Sample rmc = (RMC_Sample)o;
+ if (data.equals("INF") || rmc.data.equals("INF"))
+ return false;
+
+ return data.equals(rmc.data);
+ }
+}
Property changes on: trunk/fb-contrib/samples/RMC_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/S508C_Sample.java
===================================================================
--- trunk/fb-contrib/samples/S508C_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/S508C_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,36 +1,36 @@
-import java.awt.Color;
-import java.awt.Container;
-
-import javax.swing.ImageIcon;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-
-public class S508C_Sample extends JFrame
-{
- private JLabel fLabel = new JLabel("Hello");
- private JLabel imgLabel = new JLabel(new ImageIcon("/boo.gif"));
- private JComponent c = new MyComponent();
-
- public S508C_Sample() {
- Container cp = getContentPane();
- cp.setLayout(null);
-
- cp.add(fLabel);
- JLabel lLabel = new JLabel("there");
- lLabel.setBackground(new Color(255, 0, 0));
- lLabel.setForeground(new Color(255, 255, 100));
- cp.add(lLabel);
-
- JLabel picLabel = new JLabel(new ImageIcon("/foo.gif"));
- cp.add(picLabel);
- cp.add(c);
-
- setSize(300, 200);
- }
-}
-
-class MyComponent extends JComponent
-{
-
-}
+import java.awt.Color;
+import java.awt.Container;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+
+public class S508C_Sample extends JFrame
+{
+ private JLabel fLabel = new JLabel("Hello");
+ private JLabel imgLabel = new JLabel(new ImageIcon("/boo.gif"));
+ private JComponent c = new MyComponent();
+
+ public S508C_Sample() {
+ Container cp = getContentPane();
+ cp.setLayout(null);
+
+ cp.add(fLabel);
+ JLabel lLabel = new JLabel("there");
+ lLabel.setBackground(new Color(255, 0, 0));
+ lLabel.setForeground(new Color(255, 255, 100));
+ cp.add(lLabel);
+
+ JLabel picLabel = new JLabel(new ImageIcon("/foo.gif"));
+ cp.add(picLabel);
+ cp.add(c);
+
+ setSize(300, 200);
+ }
+}
+
+class MyComponent extends JComponent
+{
+
+}
Property changes on: trunk/fb-contrib/samples/S508C_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/SACM_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SACM_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/SACM_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,12 +1,12 @@
-
-public class SACM_Sample
-{
- public String test(int i)
- {
- String[] giantSounds = new String[] { "fee", "fi", "fo", "fum", "burp", "fart" };
- if ((i < 0) || (i >= giantSounds.length))
- return "";
-
- return giantSounds[i];
- }
-}
+
+public class SACM_Sample
+{
+ public String test(int i)
+ {
+ String[] giantSounds = new String[] { "fee", "fi", "fo", "fum", "burp", "fart" };
+ if ((i < 0) || (i >= giantSounds.length))
+ return "";
+
+ return giantSounds[i];
+ }
+}
Property changes on: trunk/fb-contrib/samples/SACM_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/SCII_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SCII_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/SCII_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,71 +1,71 @@
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-
-public class SCII_Sample extends OverEndulgentParent implements MouseListener
-{
- public void mouseClicked(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
-}
-
-class OverEndulgentParent
-{
- public void mousePressed(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseReleased(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseEntered(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseExited(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
-
- interface A
- {
- public void a();
-
- public void b();
-
- public void c();
- }
-
- interface B extends A
- {
- public void b();
- }
-
- interface C extends B
- {
- public void c();
- }
-
- class AA implements A
- {
- public void a() {}
-
- public void b() {}
-
- public void c() {}
- }
-
- class BB extends AA implements B
- {
-
- }
-
- class CC extends BB implements C
- {
-
- }
-}
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+public class SCII_Sample extends OverEndulgentParent implements MouseListener
+{
+ public void mouseClicked(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+}
+
+class OverEndulgentParent
+{
+ public void mousePressed(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseReleased(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseEntered(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseExited(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ interface A
+ {
+ public void a();
+
+ public void b();
+
+ public void c();
+ }
+
+ interface B extends A
+ {
+ public void b();
+ }
+
+ interface C extends B
+ {
+ public void c();
+ }
+
+ class AA implements A
+ {
+ public void a() {}
+
+ public void b() {}
+
+ public void c() {}
+ }
+
+ class BB extends AA implements B
+ {
+
+ }
+
+ class CC extends BB implements C
+ {
+
+ }
+}
Property changes on: trunk/fb-contrib/samples/SCII_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/SC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SC_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/SC_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,28 +1,28 @@
-import java.util.Comparator;
-
-public class SC_Sample
-{
- public static final int T1 = 0;
- public static final int T2 = 1;
-
- int t = 0;
- class SampleComparator implements Comparator<SC_Sample>
- {
- public int compare(SC_Sample arg0, SC_Sample arg1) {
- if (arg0.t == arg1.t)
- return 0;
-
- return -1;
- }
- }
-
- class SampleComparable implements Comparable<SC_Sample>
- {
- public int compareTo(SC_Sample arg0) {
- if (t == arg0.t)
- return 0;
-
- return 1;
- }
- }
-}
+import java.util.Comparator;
+
+public class SC_Sample
+{
+ public static final int T1 = 0;
+ public static final int T2 = 1;
+
+ int t = 0;
+ class SampleComparator implements Comparator<SC_Sample>
+ {
+ public int compare(SC_Sample arg0, SC_Sample arg1) {
+ if (arg0.t == arg1.t)
+ return 0;
+
+ return -1;
+ }
+ }
+
+ class SampleComparable implements Comparable<SC_Sample>
+ {
+ public int compareTo(SC_Sample arg0) {
+ if (t == arg0.t)
+ return 0;
+
+ return 1;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/samples/SC_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/SIL_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SIL_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/SIL_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,20 +1,20 @@
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-public class SIL_Sample
-{
- public void test(ResultSet rs) throws SQLException
- {
- Connection c = rs.getStatement().getConnection();
- PreparedStatement ps = c.prepareStatement("select foo from boo where moo = ?");
-
- while (rs.next())
- {
- int key = rs.getInt(1);
- ps.setInt(1, key);
- ResultSet mrs = ps.executeQuery();
- }
- }
-}
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class SIL_Sample
+{
+ public void test(ResultSet rs) throws SQLException
+ {
+ Connection c = rs.getStatement().getConnection();
+ PreparedStatement ps = c.prepareStatement("select foo from boo where moo = ?");
+
+ while (rs.next())
+ {
+ int key = rs.getInt(1);
+ ps.setInt(1, key);
+ ResultSet mrs = ps.executeQuery();
+ }
+ }
+}
Property changes on: trunk/fb-contrib/samples/SIL_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/SJVU_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SJVU_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/SJVU_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,12 +1,12 @@
-
-public class SJVU_Sample
-{
- public void test14using15(int i)
- {
- Integer ii = Integer.valueOf(i);
- StringBuilder sb = new StringBuilder();
- sb.append(ii.intValue());
- }
-
-
-}
+
+public class SJVU_Sample
+{
+ public void test14using15(int i)
+ {
+ Integer ii = Integer.valueOf(i);
+ StringBuilder sb = new StringBuilder();
+ sb.append(ii.intValue());
+ }
+
+
+}
Property changes on: trunk/fb-contrib/samples/SJVU_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,81 +1,81 @@
-import java.math.BigDecimal;
-import java.util.BitSet;
-
-public class SPP_Sample
-{
- private static final double pi = 3.14;
- private static final double e = 2.72;
- public static final String FALSE_POSITIVE = "INTERN_OK_HERE".intern();
-
- static enum Flap { Smack, Jack };
-
- public void testSPPBitSet(BitSet b)
- {
- b.set(-1);
- }
-
- public String testSPPIntern()
- {
- return "FOO".intern(); //and yes i've seen this!
- }
-
- public String testSBWithChars()
- {
- StringBuffer sb = new StringBuffer('v');
- sb.append("ictory");
- return sb.toString();
- }
-
- public double area(double radius)
- {
- return pi * radius * radius;
- }
-
- public void testStutter(String s)
- {
- String a = a = s;
- }
-
- public void testNAN(double d)
- {
- if (d == Double.NaN)
- System.out.println("It's a nan");
- }
-
- public void testNAN(float f)
- {
- if (f == Float.NaN)
- System.out.println("It's a nan");
- }
-
- public void testBigDecimal()
- {
- BigDecimal d = new BigDecimal(2.1);
- }
-
- public void testEmptySB()
- {
- StringBuffer sb = new StringBuffer("");
- }
-
- public void equalsOnEnum(Flap f)
- {
- if (f.equals(Flap.Jack))
- 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");
- if (e && e.booleanValue())
- System.out.println("Booya");
- }
-
- public char usechatAt(String s)
- {
- if (s.length() > 0)
- return s.toCharArray()[0];
- return ' ';
- }
-}
+import java.math.BigDecimal;
+import java.util.BitSet;
+
+public class SPP_Sample
+{
+ private static final double pi = 3.14;
+ private static final double e = 2.72;
+ public static final String FALSE_POSITIVE = "INTERN_OK_HERE".intern();
+
+ static enum Flap { Smack, Jack };
+
+ public void testSPPBitSet(BitSet b)
+ {
+ b.set(-1);
+ }
+
+ public String testSPPIntern()
+ {
+ return "FOO".intern(); //and yes i've seen this!
+ }
+
+ public String testSBWithChars()
+ {
+ StringBuffer sb = new StringBuffer('v');
+ sb.append("ictory");
+ return sb.toString();
+ }
+
+ public double area(double radius)
+ {
+ return pi * radius * radius;
+ }
+
+ public void testStutter(String s)
+ {
+ String a = a = s;
+ }
+
+ public void testNAN(double d)
+ {
+ if (d == Double.NaN)
+ System.out.println("It's a nan");
+ }
+
+ public void testNAN(float f)
+ {
+ if (f == Float.NaN)
+ System.out.println("It's a nan");
+ }
+
+ public void testBigDecimal()
+ {
+ BigDecimal d = new BigDecimal(2.1);
+ }
+
+ public void testEmptySB()
+ {
+ StringBuffer sb = new StringBuffer("");
+ }
+
+ public void equalsOnEnum(Flap f)
+ {
+ if (f.equals(Flap.Jack))
+ 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");
+ if (e && e.booleanValue())
+ System.out.println("Booya");
+ }
+
+ public char usechatAt(String s)
+ {
+ if (s.length() > 0)
+ return s.toCharArray()[0];
+ return ' ';
+ }
+}
Property changes on: trunk/fb-contrib/samples/SPP_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/TR_Sample.java
===================================================================
--- trunk/fb-contrib/samples/TR_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/TR_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,11 +1,11 @@
-
-public class TR_Sample
-{
- public int factorial(int n)
- {
- if (n == 1)
- return 1;
-
- return n * factorial(n-1);
- }
-}
+
+public class TR_Sample
+{
+ public int factorial(int n)
+ {
+ if (n == 1)
+ return 1;
+
+ return n * factorial(n-1);
+ }
+}
Property changes on: trunk/fb-contrib/samples/TR_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/UAA_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UAA_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/UAA_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,54 +1,54 @@
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-
-public class UAA_Sample {
-
- private Set<String> in = new HashSet<String>();
- private Set<String> out = new HashSet<String>();
-
- public Set<String> testLocalSet(Set<String> in) {
- Set<String> out = new HashSet<String>();
- out.add("Foo");
- out.add("Bar");
- for (String s : in) {
- out.add(s);
- }
- return out;
- }
-
- public Set<String> testFPCondition(Set<String> in) {
- Set<String> out = new HashSet<String>();
- for (String s : in) {
- if (s.startsWith("a"))
- out.add(s);
- }
- return out;
- }
-
- public Set<String> testKeyOrValueAdd(Map<String, String> in)
- {
- Set<String> out = new HashSet<String>();
- for (String s : in.keySet())
- out.add(s);
-
- for (String s : in.values())
- out.add(s);
-
- return out;
- }
-
- public void testMemberSet() {
- for (String s : in)
- out.add(s);
- }
-
- public Set<String> testFromArray(String[] in) {
- Set<String> out = new HashSet<String>();
- for (String s : in)
- out.add(s);
-
- return out;
- }
-}
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public class UAA_Sample {
+
+ private Set<String> in = new HashSet<String>();
+ private Set<String> out = new HashSet<String>();
+
+ public Set<String> testLocalSet(Set<String> in) {
+ Set<String> out = new HashSet<String>();
+ out.add("Foo");
+ out.add("Bar");
+ for (String s : in) {
+ out.add(s);
+ }
+ return out;
+ }
+
+ public Set<String> testFPCondition(Set<String> in) {
+ Set<String> out = new HashSet<String>();
+ for (String s : in) {
+ if (s.startsWith("a"))
+ out.add(s);
+ }
+ return out;
+ }
+
+ public Set<String> testKeyOrValueAdd(Map<String, String> in)
+ {
+ Set<String> out = new HashSet<String>();
+ for (String s : in.keySet())
+ out.add(s);
+
+ for (String s : in.values())
+ out.add(s);
+
+ return out;
+ }
+
+ public void testMemberSet() {
+ for (String s : in)
+ out.add(s);
+ }
+
+ public Set<String> testFromArray(String[] in) {
+ Set<String> out = new HashSet<String>();
+ for (String s : in)
+ out.add(s);
+
+ return out;
+ }
+}
Property changes on: trunk/fb-contrib/samples/UAA_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/UCPM_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UCPM_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/UCPM_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,13 +1,13 @@
-
-public class UCPM_Sample
-{
- public int testUcpm1(String s)
- {
- return s.indexOf("*") * 10;
- }
-
- public String testUcpm2(String s)
- {
- return s.startsWith("*") ? s.substring(1) : s;
- }
-}
+
+public class UCPM_Sample
+{
+ public int testUcpm1(String s)
+ {
+ return s.indexOf("*") * 10;
+ }
+
+ public String testUcpm2(String s)
+ {
+ return s.startsWith("*") ? s.substring(1) : s;
+ }
+}
Property changes on: trunk/fb-contrib/samples/UCPM_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/UEC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UEC_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/UEC_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,63 +1,63 @@
-import java.util.EnumMap;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-
-public class UEC_Sample
-{
- public enum Suite { Spades, Hearts, Clubs, Diamonds };
- public enum FalsePositive { A, B, C };
-
- private Set<Suite> wildSuites = new HashSet<Suite>();
- private EnumSet<Suite> eWildSuites = EnumSet.noneOf(Suite.class);
-
- public UEC_Sample()
- {
- wildSuites.add(Suite.Spades);
- }
-
- public UEC_Sample(Suite s)
- {
- wildSuites.add(s);
- }
-
- public Map<Suite, Integer> deal()
- {
- Map<Suite, Integer> hand = new HashMap<Suite, Integer>();
- hand.put(Suite.Spades, new Integer(10));
- hand.put(Suite.Hearts, new Integer(9));
-
- return hand;
- }
-
- public EnumMap<Suite, Integer> eDeal()
- {
- EnumMap<Suite, Integer> hand = new EnumMap(Suite.class);
- hand.put(Suite.Spades, new Integer(10));
- hand.put(Suite.Hearts, new Integer(9));
-
- return hand;
- }
-
- public void uecFP()
- {
- Set<FalsePositive> testSet = EnumSet.of(FalsePositive.A);
-
- testSet.add(FalsePositive.B);
- }
-
- public Set<Suite> getSuites()
- {
- return EnumSet.<Suite>allOf(Suite.class);
- }
-
- public void uecFP2()
- {
- Set<Suite> suites = getSuites();
-
- suites.add(Suite.Clubs);
- }
-}
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public class UEC_Sample
+{
+ public enum Suite { Spades, Hearts, Clubs, Diamonds };
+ public enum FalsePositive { A, B, C };
+
+ private Set<Suite> wildSuites = new HashSet<Suite>();
+ private EnumSet<Suite> eWildSuites = EnumSet.noneOf(Suite.class);
+
+ public UEC_Sample()
+ {
+ wildSuites.add(Suite.Spades);
+ }
+
+ public UEC_Sample(Suite s)
+ {
+ wildSuites.add(s);
+ }
+
+ public Map<Suite, Integer> deal()
+ {
+ Map<Suite, Integer> hand = new HashMap<Suite, Integer>();
+ hand.put(Suite.Spades, new Integer(10));
+ hand.put(Suite.Hearts, new Integer(9));
+
+ return hand;
+ }
+
+ public EnumMap<Suite, Integer> eDeal()
+ {
+ EnumMap<Suite, Integer> hand = new EnumMap(Suite.class);
+ hand.put(Suite.Spades, new Integer(10));
+ hand.put(Suite.Hearts, new Integer(9));
+
+ return hand;
+ }
+
+ public void uecFP()
+ {
+ Set<FalsePositive> testSet = EnumSet.of(FalsePositive.A);
+
+ testSet.add(FalsePositive.B);
+ }
+
+ public Set<Suite> getSuites()
+ {
+ return EnumSet.<Suite>allOf(Suite.class);
+ }
+
+ public void uecFP2()
+ {
+ Set<Suite> suites = getSuites();
+
+ suites.add(Suite.Clubs);
+ }
+}
Property changes on: trunk/fb-contrib/samples/UEC_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/URV_Sample.java
===================================================================
--- trunk/fb-contrib/samples/URV_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/URV_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,38 +1,38 @@
-import java.util.HashSet;
-import java.util.TreeSet;
-
-public class URV_Sample extends URV_Super
-{
- public Object getASet(boolean b)
- {
- if (b)
- return new HashSet();
- else
- return new TreeSet();
- }
-
- public Object getInfo(boolean b)
- {
- if (b)
- return new String[4];
- else
- return "";
- }
-
- @Override
- public Object getInheritedInfo(boolean b)
- {
- if (b)
- return new Integer(1);
- else
- return new Float(1.0);
- }
-}
-
-class URV_Super
-{
- public Object getInheritedInfo(boolean b)
- {
- return null;
- }
-}
+import java.util.HashSet;
+import java.util.TreeSet;
+
+public class URV_Sample extends URV_Super
+{
+ public Object getASet(boolean b)
+ {
+ if (b)
+ return new HashSet();
+ else
+ return new TreeSet();
+ }
+
+ public Object getInfo(boolean b)
+ {
+ if (b)
+ return new String[4];
+ else
+ return "";
+ }
+
+ @Override
+ public Object getInheritedInfo(boolean b)
+ {
+ if (b)
+ return new Integer(1);
+ else
+ return new Float(1.0);
+ }
+}
+
+class URV_Super
+{
+ public Object getInheritedInfo(boolean b)
+ {
+ return null;
+ }
+}
Property changes on: trunk/fb-contrib/samples/URV_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/USS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/USS_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/USS_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,100 +1,100 @@
-import java.util.StringTokenizer;
-
-public class USS_Sample
-{
- public String[] testUss1(String s)
- {
- StringTokenizer st = new StringTokenizer(s, ";");
- int count = st.countTokens();
- String[] sarray = new String[count];
-
- int i = 0;
- while (st.hasMoreTokens())
- {
- sarray[i] = st.nextToken();
- i++;
- }
-
- return sarray;
- }
-
- public String[] testUss2(String s)
- {
- StringTokenizer st = new StringTokenizer(s, ";");
- int count = st.countTokens();
- String[] sarray = new String[count];
-
- int i = 0;
- while (st.hasMoreTokens())
- {
- sarray[i++] = st.nextToken();
- }
-
- return sarray;
- }
-
- public String[] testUss3(String s)
- {
- StringTokenizer st = new StringTokenizer(s, ";");
- int count = st.countTokens();
- String[] sarray = new String[count];
-
- for (int i = 0; i < count; i++)
- {
- sarray[i++] = st.nextToken();
- }
-
- return sarray;
- }
-
- public String[] testUss4(String s)
- {
- StringTokenizer st = new StringTokenizer(s, ";");
- int count = st.countTokens();
- String[] sarray = new String[count];
-
- int i = 0;
- while (st.hasMoreElements())
- {
- sarray[i++] = (String)st.nextElement();
- }
-
- return sarray;
- }
-
- public String[] testUssFP5(String s)
- {
- StringTokenizer st = new StringTokenizer(s, ";");
- int count = st.countTokens();
- String[] sarray = new String[count];
-
- int i = 0;
- while (st.hasMoreElements())
- {
- sarray[i++] = "***" + (String)st.nextElement();
- }
-
- return sarray;
- }
-
- public String[] testUssFP6(String s)
- {
- StringTokenizer st = new StringTokenizer(s, ";");
- int count = st.countTokens();
- String[] sarray = new String[count];
-
- int i = 0;
- while (st.hasMoreTokens())
- {
- String x = st.nextToken();
- if (x.equals("*"))
- x = "Star";
-
- sarray[i++] = x;
- }
-
- return sarray;
- }
-
-
-}
+import java.util.StringTokenizer;
+
+public class USS_Sample
+{
+ public String[] testUss1(String s)
+ {
+ StringTokenizer st = new StringTokenizer(s, ";");
+ int count = st.countTokens();
+ String[] sarray = new String[count];
+
+ int i = 0;
+ while (st.hasMoreTokens())
+ {
+ sarray[i] = st.nextToken();
+ i++;
+ }
+
+ return sarray;
+ }
+
+ public String[] testUss2(String s)
+ {
+ StringTokenizer st = new StringTokenizer(s, ";");
+ int count = st.countTokens();
+ String[] sarray = new String[count];
+
+ int i = 0;
+ while (st.hasMoreTokens())
+ {
+ sarray[i++] = st.nextToken();
+ }
+
+ return sarray;
+ }
+
+ public String[] testUss3(String s)
+ {
+ StringTokenizer st = new StringTokenizer(s, ";");
+ int count = st.countTokens();
+ String[] sarray = new String[count];
+
+ for (int i = 0; i < count; i++)
+ {
+ sarray[i++] = st.nextToken();
+ }
+
+ return sarray;
+ }
+
+ public String[] testUss4(String s)
+ {
+ StringTokenizer st = new StringTokenizer(s, ";");
+ int count = st.countTokens();
+ String[] sarray = new String[count];
+
+ int i = 0;
+ while (st.hasMoreElements())
+ {
+ sarray[i++] = (String)st.nextElement();
+ }
+
+ return sarray;
+ }
+
+ public String[] testUssFP5(String s)
+ {
+ StringTokenizer st = new StringTokenizer(s, ";");
+ int count = st.countTokens();
+ String[] sarray = new String[count];
+
+ int i = 0;
+ while (st.hasMoreElements())
+ {
+ sarray[i++] = "***" + (String)st.nextElement();
+ }
+
+ return sarray;
+ }
+
+ public String[] testUssFP6(String s)
+ {
+ StringTokenizer st = new StringTokenizer(s, ";");
+ int count = st.countTokens();
+ String[] sarray = new String[count];
+
+ int i = 0;
+ while (st.hasMoreTokens())
+ {
+ String x = st.nextToken();
+ if (x.equals("*"))
+ x = "Star";
+
+ sarray[i++] = x;
+ }
+
+ return sarray;
+ }
+
+
+}
Property changes on: trunk/fb-contrib/samples/USS_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/fb-contrib/samples/UTA_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UTA_Sample.java 2007-09-15 04:44:35 UTC (rev 904)
+++ trunk/fb-contrib/samples/UTA_Sample.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -1,34 +1,34 @@
-import java.util.Iterator;
-import java.util.List;
-
-public class UTA_Sample
-{
- public String[] testList1(List<String> l)
- {
- String[] data = new String[l.size()];
- for (int i = 0; i < l.size(); i++)
- data[i] = l.get(i);
-
- return data;
- }
-
- public Integer[] testList2(List<Integer> l)
- {
- int size = l.size();
- Integer[] data = new Integer[size];
- for (int i = 0; i < size; i++)
- data[i] = l.get(i);
-
- return data;
- }
-
- public Long[] testList3(List<Long> l)
- {
- Iterator<Long> it = l.iterator();
- Long[] data = new Long[l.size()];
- for (int i = 0; i < l.size(); i++)
- data[i] = it.next();
-
- return data;
- }
-}
+import java.util.Iterator;
+import java.util.List;
+
+public class UTA_Sample
+{
+ public String[] testList1(List<String> l)
+ {
+ String[] data = new String[l.size()];
+ for (int i = 0; i < l.size(); i++)
+ data[i] = l.get(i);
+
+ return data;
+ }
+
+ public Integer[] testList2(List<Integer> l)
+ {
+ int size = l.size();
+ Integer[] data = new Integer[size];
+ for (int i = 0; i < size; i++)
+ data[i] = l.get(i);
+
+ return data;
+ }
+
+ public Long[] testList3(List<Long> l)
+ {
+ Iterator<Long> it = l.iterator();
+ Long[] data = new Long[l.size()];
+ for (int i = 0; i < l.size(); i++)
+ data[i] = it.next();
+
+ return data;
+ }
+}
Property changes on: trunk/fb-contrib/samples/UTA_Sample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Property changes on: trunk/fb-contrib/samples/samples-bugs.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java 2007-09-15 18:59:26 UTC (rev 905)
@@ -0,0 +1,139 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2007 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.Code;
+import org.apache.bcel.classfile.JavaClass;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+/**
+ * looks for classes that implement Serializable and implements readObject and w...
[truncated message content] |
|
From: <dbr...@us...> - 2007-09-19 01:14:43
|
Revision: 911
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=911&view=rev
Author: dbrosius
Date: 2007-09-18 18:14:46 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
prepare for version 3.2.5
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2007-09-19 01:12:09 UTC (rev 910)
+++ trunk/fb-contrib/build.xml 2007-09-19 01:14:46 UTC (rev 911)
@@ -20,7 +20,7 @@
<property name="javac.deprecation" value="on"/>
<property name="javac.debug" value="on"/>
- <property name="fb-contrib.version" value="3.3.0"/>
+ <property name="fb-contrib.version" value="3.2.5"/>
<target name="clean" description="removes all generated collateral">
<delete dir="${classes.dir}"/>
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-09-19 01:12:09 UTC (rev 910)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-09-19 01:14:46 UTC (rev 911)
@@ -277,19 +277,23 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse"
speed="slow"
- reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" />
+ reports="SJVU_SUSPICIOUS_JDK_VERSION_USE"
+ disabled="true" />
<Detector class="com.mebigfatguy.fbcontrib.detect.UseAddAll"
speed="fast"
- reports="UAA_USE_ADD_ALL" />
+ reports="UAA_USE_ADD_ALL"
+ disabled="true" />
<Detector class="com.mebigfatguy.fbcontrib.detect.MethodReturnsConstant"
speed="fast"
- reports="MRC_METHOD_RETURNS_CONSTANT" />
+ reports="MRC_METHOD_RETURNS_CONSTANT"
+ disabled="true" />
<Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessCustomSerialization"
speed="fast"
- reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" />
+ reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION"
+ disabled="true"/>
<!-- BugPattern -->
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-09-19 01:30:47
|
Revision: 913
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=913&view=rev
Author: dbrosius
Date: 2007-09-18 18:30:49 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
go back to 3.3.0 dev
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2007-09-19 01:29:54 UTC (rev 912)
+++ trunk/fb-contrib/build.xml 2007-09-19 01:30:49 UTC (rev 913)
@@ -20,7 +20,7 @@
<property name="javac.deprecation" value="on"/>
<property name="javac.debug" value="on"/>
- <property name="fb-contrib.version" value="3.2.5"/>
+ <property name="fb-contrib.version" value="3.3.0"/>
<target name="clean" description="removes all generated collateral">
<delete dir="${classes.dir}"/>
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-09-19 01:29:54 UTC (rev 912)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-09-19 01:30:49 UTC (rev 913)
@@ -277,23 +277,19 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse"
speed="slow"
- reports="SJVU_SUSPICIOUS_JDK_VERSION_USE"
- disabled="true" />
+ reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" />
<Detector class="com.mebigfatguy.fbcontrib.detect.UseAddAll"
speed="fast"
- reports="UAA_USE_ADD_ALL"
- disabled="true" />
+ reports="UAA_USE_ADD_ALL" />
<Detector class="com.mebigfatguy.fbcontrib.detect.MethodReturnsConstant"
speed="fast"
- reports="MRC_METHOD_RETURNS_CONSTANT"
- disabled="true" />
+ reports="MRC_METHOD_RETURNS_CONSTANT" />
<Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessCustomSerialization"
speed="fast"
- reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION"
- disabled="true"/>
+ reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" />
<!-- BugPattern -->
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-01 03:27:44
|
Revision: 922
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=922&view=rev
Author: dbrosius
Date: 2007-09-30 20:27:47 -0700 (Sun, 30 Sep 2007)
Log Message:
-----------
initial checkin, new MOM detector
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/MOM_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-09-30 03:06:51 UTC (rev 921)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-10-01 03:27:47 UTC (rev 922)
@@ -291,6 +291,10 @@
speed="fast"
reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel"
+ speed="fast"
+ reports="MOM_MISLEADING_OVERLOAD_MODEL" />
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -382,4 +386,5 @@
<BugPattern abbrev="UAA" type="UAA_USE_ADD_ALL" category="STYLE" experimental="true" />
<BugPattern abbrev="MRC" type="MRC_METHOD_RETURNS_CONSTANT" category="STYLE" experimental="true" />
<BugPattern abbrev="NCS" type="NCS_NEEDLESS_CUSTOM_SERIALIZATION" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="MOM" type="MOM_MISLEADING_OVERLOAD_MODEL" category="STYLE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-09-30 03:06:51 UTC (rev 921)
+++ trunk/fb-contrib/etc/messages.xml 2007-10-01 03:27:47 UTC (rev 922)
@@ -790,6 +790,17 @@
</Details>
</Detector>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel">
+ <Details>
+ <![CDATA[
+ <p>looks for classes that define both static and instance methods with the same name.
+ As each type represents a different use model, it doesn't make sense that this name
+ would be overloaded, and will confuse users of the class.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
<!-- BugPattern -->
<BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING">
@@ -1969,6 +1980,17 @@
</Details>
</BugPattern>
+ <BugPattern type="MOM_MISLEADING_OVERLOAD_MODEL">
+ <ShortDescription>class 'overloads' a method with both instance and static versions</ShortDescription>
+ <LongDescription>class {0} 'overloads' a method with both instance and static versions</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This class 'overloads' the same method with both an instance and static version. As the use
+ of these two models is different, it will be confusing to the users of these methods.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -2036,4 +2058,5 @@
<BugCode abbrev="UAA">Use Add All</BugCode>
<BugCode abbrev="MRC">Method Returns Constant</BugCode>
<BugCode abbrev="NCS">Needless Custom Serialization</BugCode>
+ <BugCode abbrev="MOM">Misleading Overload Model</BugCode>
</MessageCollection>
\ No newline at end of file
Added: trunk/fb-contrib/samples/MOM_Sample.java
===================================================================
--- trunk/fb-contrib/samples/MOM_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/MOM_Sample.java 2007-10-01 03:27:47 UTC (rev 922)
@@ -0,0 +1,11 @@
+
+public class MOM_Sample
+{
+ public void test(int i)
+ {
+ }
+
+ public static void test(int i, int j)
+ {
+ }
+}
Property changes on: trunk/fb-contrib/samples/MOM_Sample.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java 2007-10-01 03:27:47 UTC (rev 922)
@@ -0,0 +1,69 @@
+package com.mebigfatguy.fbcontrib.detect;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.Detector;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.ba.XFactory;
+import edu.umd.cs.findbugs.visitclass.PreorderVisitor;
+
+/** looks for classes that define both static and instance methods with the same name.
+ * This 'overloading' is confusing as one method is instance based the other class based,
+ * and points to a confusion in implementation.
+ */
+public class MisleadingOverloadModel extends PreorderVisitor implements Detector
+{
+ private static enum MethodType { INSTANCE, STATIC, BOTH };
+ private BugReporter bugReporter;
+
+ /**
+ * constructs a MOM detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public MisleadingOverloadModel(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ public void visitClassContext(ClassContext classContext) {
+ Map<String, MethodType> declMethods = new HashMap<String, MethodType>();
+ JavaClass cls = classContext.getJavaClass();
+ String clsName = cls.getClassName();
+ Method[] methods = cls.getMethods();
+ for (Method m : methods) {
+ String methodName = m.getName();
+ boolean report = false;
+ MethodType newType;
+ if (m.isStatic()) {
+ report = declMethods.get(methodName) == MethodType.INSTANCE;
+ if (report)
+ newType = MethodType.BOTH;
+ else
+ newType = MethodType.STATIC;
+ } else {
+ report = declMethods.get(m.getName()) == MethodType.STATIC;
+ if (report)
+ newType = MethodType.BOTH;
+ else
+ newType = MethodType.INSTANCE;
+ }
+
+ declMethods.put(methodName, newType);
+ if (report) {
+ bugReporter.reportBug(new BugInstance(this, "MOM_MISLEADING_OVERLOAD_MODEL", NORMAL_PRIORITY)
+ .addClass(cls)
+ .addMethod(XFactory.createXMethod(clsName, m))
+ .addString(methodName));
+ }
+ }
+ }
+
+ /** implements the visitor to do nothing */
+ public void report() {
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-06 22:29:44
|
Revision: 923
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=923&view=rev
Author: dbrosius
Date: 2007-10-06 15:29:47 -0700 (Sat, 06 Oct 2007)
Log Message:
-----------
initial checkin - EXS detector - not even close to working
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/EXS_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-10-01 03:27:47 UTC (rev 922)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-10-06 22:29:47 UTC (rev 923)
@@ -295,6 +295,10 @@
speed="fast"
reports="MOM_MISLEADING_OVERLOAD_MODEL" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ExceptionSoftening"
+ speed="moderate"
+ reports="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS,EXS_EXCEPTION_SOFTENING_HAS_CHECKED,EXS_EXCEPTION_SOFTENING_NO_CHECKED" />
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -387,4 +391,7 @@
<BugPattern abbrev="MRC" type="MRC_METHOD_RETURNS_CONSTANT" category="STYLE" experimental="true" />
<BugPattern abbrev="NCS" type="NCS_NEEDLESS_CUSTOM_SERIALIZATION" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="MOM" type="MOM_MISLEADING_OVERLOAD_MODEL" category="STYLE" experimental="true" />
+ <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS" category="STYLE" experimental="true" />
+ <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_HAS_CHECKED" category="STYLE" experimental="true" />
+ <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_NO_CHECKED" category="STYLE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-10-01 03:27:47 UTC (rev 922)
+++ trunk/fb-contrib/etc/messages.xml 2007-10-06 22:29:47 UTC (rev 923)
@@ -801,6 +801,21 @@
</Details>
</Detector>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ExceptionSoftening">
+ <Details>
+ <![CDATA[
+ <p>looks for methods that catch checked exceptions, and throw unchecked
+ exceptions in their place. There are several levels of concern. Least
+ concerning are methods constrained by interface or super class contracts
+ not to throw checked exceptions but appear owned by the same author. Next
+ are methods constrained by interface or super class contracts and throw other
+ types of checked exceptions. Most egregious are method not constrained by any interface
+ or superclass contract.</p>
+ <p>It is a moderately fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
<!-- BugPattern -->
<BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING">
@@ -1991,6 +2006,44 @@
</Details>
</BugPattern>
+ <BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS">
+ <ShortDescription>constrained method converts checked exception to unchecked</ShortDescription>
+ <LongDescription>constrained method {1} converts checked exception to unchecked</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method's exception signature is constrained by an interface or super class to not throw
+ any checked exceptions. Therefore a caught checked exception was converted to an unchecked exception
+ and thrown. However it appears that the class in question is owned by the same author as the constraining
+ interface or superclass. Consider changes the signature of this method to include the checked exception.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="EXS_EXCEPTION_SOFTENING_HAS_CHECKED">
+ <ShortDescription>constrained method converts checked exception to unchecked instead of another allowable checked exception</ShortDescription>
+ <LongDescription>constrained method {1} converts checked exception to unchecked instead of another allowable checked exception</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method's exception signature is constrained by an interface of super class to not throw a
+ checked exception that was caught. Therefore this exception was converted to an unchecked exception and
+ thrown. It would probably be better to throw the closest checked exception allowed, and to annotate
+ the new exception with the original exception using the initial cause field.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CHECKED">
+ <ShortDescription>unconstrained method converts checked exception to unchecked</ShortDescription>
+ <LongDescription>unconstrained method {1} converts checked exception to unchecked</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method is not constrained by an interface or superclass, but converts a caught checked exception
+ to unchecked exception and thrown. It would be more appropriate just throw the checked exception, adding
+ the exception to the throws clause of the method.
+ ]]>
+ </Details>
+ </BugPattern>
+
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -2059,4 +2112,5 @@
<BugCode abbrev="MRC">Method Returns Constant</BugCode>
<BugCode abbrev="NCS">Needless Custom Serialization</BugCode>
<BugCode abbrev="MOM">Misleading Overload Model</BugCode>
+ <BugCode abbrev="EXS">Exception Softening</BugCode>
</MessageCollection>
\ No newline at end of file
Added: trunk/fb-contrib/samples/EXS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/EXS_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/EXS_Sample.java 2007-10-06 22:29:47 UTC (rev 923)
@@ -0,0 +1,55 @@
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.SQLException;
+
+
+public class EXS_Sample extends Super
+{
+ @Override
+ public void constrainedNone()
+ {
+ try
+ {
+ InputStream is = new FileInputStream("c:\\test.txt");
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Ooops");
+ }
+ }
+
+ @Override
+ public void constrainedNon() throws SQLException
+ {
+ try
+ {
+ InputStream is = new FileInputStream("c:\\test.txt");
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Ooops");
+ }
+ }
+
+ public void notConstrained()
+ {
+ try
+ {
+ InputStream is = new FileInputStream("c:\\test.txt");
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Ooops");
+ }
+ }
+}
+
+class Super
+{
+ public void constrainedNone()
+ {}
+
+ public void constrainedNon() throws SQLException
+ {}
+}
\ No newline at end of file
Property changes on: trunk/fb-contrib/samples/EXS_Sample.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-06 22:29:47 UTC (rev 923)
@@ -0,0 +1,182 @@
+/*
+ * fb-contrib - Auxilliary detectors for Java programs
+ * Copyright (C) 2005-2007 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 java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.CodeException;
+import org.apache.bcel.classfile.ConstantClass;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.Method;
+
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+/** looks for methods that catch checked exceptions, and throw unchecked
+ * exceptions in their place. There are several levels of concern. Least
+ * important are methods constrained by interface or super class contracts
+ * not to throw checked exceptions but appear owned by the same author. Next
+ * are methods constrained by interface or super class contracts and throw other
+ * types of checked exceptions. Lastly are method not constrained by any interface
+ * or superclass contract.
+ */
+public class ExceptionSoftening extends BytecodeScanningDetector
+{
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ private LinkedHashMap<Integer, CodeException> catchHandlerPCs;
+ private Set<CatchInfo> catchInfos;
+
+
+ /** constructs a EXS detector given the reporter to report bugs on.
+
+ * @param bugReporter the sync of bug reports
+ */
+ public ExceptionSoftening(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ /** overrides the visitor to reset the stack
+ *
+ * @param classContext the context object of the currently parsed class
+ */
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ }
+ }
+
+ /** overrides the visitor to look for methods that catch exceptions
+ *
+ * @param obj the context object of the currently parsed code block
+ */
+ @Override
+ public void visitCode(Code obj) {
+ try {
+ Method method = getMethod();
+ if (prescreen(method)) {
+ stack.resetForMethodEntry(this);
+ catchHandlerPCs = collectExceptions(obj.getExceptionTable());
+ catchInfos = new HashSet<CatchInfo>();
+ super.visitCode(obj);
+ }
+ } finally {
+ catchInfos = null;
+ catchHandlerPCs = null;
+ }
+ }
+
+ /** overrides the visitor to find catch blocks that throw runtime exceptions
+ *
+ * @param seen the opcode of the currently parsed instruction
+ */
+ @Override
+ public void sawOpcode(int seen) {
+ try {
+ stack.mergeJumps(this);
+ int nextPC = getNextPC();
+ CodeException ex = catchHandlerPCs.get(Integer.valueOf(nextPC));
+ if (ex != null) {
+ int endPC;
+ if ((seen == GOTO) || (seen == GOTO_W))
+ endPC = this.getBranchTarget();
+ else
+ endPC = Integer.MAX_VALUE;
+ ConstantPool pool = getConstantPool();
+ ConstantClass ccls = (ConstantClass)pool.getConstant(ex.getCatchType());
+ String catchSig = ccls.getBytes(pool);
+ CatchInfo ci = new CatchInfo(ex.getHandlerPC(), endPC, catchSig);
+ catchInfos.add(ci);
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ }
+ }
+
+ /**
+ * collects all the valid exception objects (ones where start and finish are before the target)
+ * and with a catch type
+ *
+ * @param exceptions the exceptions from the class file
+ * @return the filtered exceptions keyed by catch handler pc
+ */
+ private LinkedHashMap<Integer, CodeException> collectExceptions(CodeException[] exceptions) {
+ List<CodeException> filteredEx = new ArrayList<CodeException>();
+ for (CodeException ce : exceptions) {
+ if ((ce.getCatchType() != 0) && (ce.getStartPC() < ce.getEndPC()) && (ce.getEndPC() <= ce.getHandlerPC())) {
+ filteredEx.add(ce);
+ }
+ }
+
+ LinkedHashMap<Integer, CodeException> handlers = new LinkedHashMap<Integer, CodeException>();
+
+ for (CodeException ex : filteredEx) {
+ handlers.put(Integer.valueOf(ex.getHandlerPC()), ex);
+ }
+
+ return handlers;
+ }
+
+ /** returns whether a method explicitly throws an exception
+ *
+ * @param method the currently parsed method
+ * @return if the method throws an exception
+ */
+ private boolean prescreen(Method method) {
+ BitSet bytecodeSet = getClassContext().getBytecodeSet(method);
+ return (bytecodeSet != null) && (bytecodeSet.get(Constants.ATHROW));
+ }
+
+ private static class CatchInfo {
+ private int catchStart;
+ private int catchFinish;
+ private String catchSignature;
+
+ public CatchInfo(int start, int finish, String signature) {
+ catchStart = start;
+ catchFinish = finish;
+ catchSignature = signature;
+ }
+
+ public int getStart() {
+ return catchStart;
+ }
+
+ public int getFinish() {
+ return catchFinish;
+ }
+
+ public String getSignature() {
+ return catchSignature;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-08 01:34:29
|
Revision: 926
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=926&view=rev
Author: dbrosius
Date: 2007-10-07 18:34:32 -0700 (Sun, 07 Oct 2007)
Log Message:
-----------
differentiate the three types of EXS bugs. Break out similarPackages to SignatureUtils
Modified Paths:
--------------
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-10-07 23:41:34 UTC (rev 925)
+++ trunk/fb-contrib/etc/messages.xml 2007-10-08 01:34:32 UTC (rev 926)
@@ -2007,14 +2007,13 @@
</BugPattern>
<BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS">
- <ShortDescription>constrained method converts checked exception to unchecked</ShortDescription>
- <LongDescription>constrained method {1} converts checked exception to unchecked</LongDescription>
+ <ShortDescription>unconstrained method converts checked exception to unchecked</ShortDescription>
+ <LongDescription>unconstrained method {1} converts checked exception to unchecked</LongDescription>
<Details>
<![CDATA[
- <p>This method's exception signature is constrained by an interface or super class to not throw
- any checked exceptions. Therefore a caught checked exception was converted to an unchecked exception
- and thrown. However it appears that the class in question is owned by the same author as the constraining
- interface or superclass. Consider changes the signature of this method to include the checked exception.</p>
+ <p>This method is not constrained by an interface or superclass, but converts a caught checked exception
+ to unchecked exception and thrown. It would be more appropriate just throw the checked exception, adding
+ the exception to the throws clause of the method.
]]>
</Details>
</BugPattern>
@@ -2033,13 +2032,14 @@
</BugPattern>
<BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CHECKED">
- <ShortDescription>unconstrained method converts checked exception to unchecked</ShortDescription>
- <LongDescription>unconstrained method {1} converts checked exception to unchecked</LongDescription>
+ <ShortDescription>constrained method converts checked exception to unchecked</ShortDescription>
+ <LongDescription>constrained method {1} converts checked exception to unchecked</LongDescription>
<Details>
<![CDATA[
- <p>This method is not constrained by an interface or superclass, but converts a caught checked exception
- to unchecked exception and thrown. It would be more appropriate just throw the checked exception, adding
- the exception to the throws clause of the method.
+ <p>This method's exception signature is constrained by an interface or super class to not throw
+ any checked exceptions. Therefore a caught checked exception was converted to an unchecked exception
+ and thrown. However it appears that the class in question is owned by the same author as the constraining
+ interface or superclass. Consider changes the signature of this method to include the checked exception.</p>
]]>
</Details>
</BugPattern>
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2007-10-07 23:41:34 UTC (rev 925)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2007-10-08 01:34:32 UTC (rev 926)
@@ -33,6 +33,7 @@
import org.apache.bcel.generic.Type;
import com.mebigfatguy.fbcontrib.utils.Integer14;
+import com.mebigfatguy.fbcontrib.utils.SignatureUtils;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
@@ -262,7 +263,7 @@
thisClsAccessCount++;
else {
String calledPackage = getPackageName(calledClass);
- if (similarPackages(calledPackage, packageName, 2) && !generalPurpose(calledClass)) {
+ if (SignatureUtils.similarPackages(calledPackage, packageName, 2) && !generalPurpose(calledClass)) {
Set<Integer> lineNumbers = clsAccessCount.get(calledClass);
if (lineNumbers == null) {
lineNumbers = new HashSet<Integer>();
@@ -353,33 +354,4 @@
return "";
return className.substring(0, dotPos);
}
-
- /**
- * returns whether or not the two packages have the same first 'depth' parts, if they exist
- *
- * @param packName1 the first package to check
- * @param packName2 the second package to check
- * @param depth the number of package parts to check
- *
- * @return if they are similar
- */
- private boolean similarPackages(final String packName1, final String packName2, int depth) {
- if (depth == 0)
- return true;
-
- int dot1 = packName1.indexOf('.');
- int dot2 = packName2.indexOf('.');
- if (dot1 < 0)
- return (dot2 < 0);
- else if (dot2 < 0)
- return false;
-
- String s1 = packName1.substring(0, dot1);
- String s2 = packName2.substring(0, dot2);
-
- if (!s1.equals(s2))
- return false;
-
- return similarPackages(packName1.substring(dot1+1), packName2.substring(dot2+1), depth-1);
- }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-07 23:41:34 UTC (rev 925)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-08 01:34:32 UTC (rev 926)
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.BitSet;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -34,9 +35,12 @@
import org.apache.bcel.classfile.CodeException;
import org.apache.bcel.classfile.ConstantClass;
import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.ExceptionTable;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
+import com.mebigfatguy.fbcontrib.utils.SignatureUtils;
+
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
@@ -65,6 +69,7 @@
private OpcodeStack stack;
private Map<Integer, CodeException> catchHandlerPCs;
private List<CatchInfo> catchInfos;
+ private Map<String, Set<String>> constrainingInfo;
/** constructs a EXS detector given the reporter to report bugs on.
@@ -103,11 +108,13 @@
stack.resetForMethodEntry(this);
catchHandlerPCs = collectExceptions(obj.getExceptionTable());
catchInfos = new ArrayList<CatchInfo>();
+ constrainingInfo = null;
super.visitCode(obj);
}
} finally {
catchInfos = null;
catchHandlerPCs = null;
+ constrainingInfo = null;
}
}
@@ -155,10 +162,38 @@
}
if (!anyRuntimes) {
- bugReporter.reportBug(new BugInstance(this, "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+
+ if (constrainingInfo == null)
+ constrainingInfo = getConstrainingInfo(getClassContext().getJavaClass(), getMethod());
+
+ String bug = null;
+ if (constrainingInfo == null)
+ bug = "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS";
+ else if (!constrainingInfo.values().iterator().next().isEmpty())
+ bug = "EXS_EXCEPTION_SOFTENING_HAS_CHECKED";
+ else {
+ String pack1 = constrainingInfo.keySet().iterator().next();
+ String pack2 = getClassContext().getJavaClass().getClassName();
+ int dotPos = pack1.lastIndexOf('.');
+ if (dotPos >= 0)
+ pack1 = pack1.substring(0, dotPos);
+ else
+ pack1 = "";
+ dotPos = pack2.lastIndexOf('.');
+ if (dotPos >= 0)
+ pack2 = pack2.substring(0, dotPos);
+ else
+ pack2 = "";
+ if (SignatureUtils.similarPackages(pack1, pack2, 2))
+ bug = "EXS_EXCEPTION_SOFTENING_NO_CHECKED";
+ }
+
+ if (bug != null) {
+ bugReporter.reportBug(new BugInstance(this, bug, NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
}
}
@@ -235,6 +270,91 @@
return catchTypes;
}
+ /** finds the super class or interface that constrains the types of exceptions that can be thrown from the given method
+ *
+ * @param m the method to check
+ * @return a map containing the class name to a set of exceptions that constrain this method
+ */
+ public Map<String, Set<String>> getConstrainingInfo(JavaClass cls, Method m) throws ClassNotFoundException {
+ String methodName = m.getName();
+ String methodSig = m.getSignature();
+
+ {
+ //First look for the method in interfaces of the class
+ JavaClass[] infClasses = cls.getInterfaces();
+
+ for (JavaClass infCls : infClasses) {
+ Method infMethod = findMethod(infCls, methodName, methodSig);
+ if (infMethod != null) {
+ return buildConstrainingInfo(infCls, infMethod);
+ } else {
+ Map<String, Set<String>> constrainingExs = getConstrainingInfo(infCls, m);
+ if (constrainingExs != null) {
+ return constrainingExs;
+ }
+ }
+ }
+ }
+
+ {
+ //Next look at the superclass
+ JavaClass superCls = cls.getSuperClass();
+ if (superCls != null) {
+ Method superMethod = findMethod(superCls, methodName, methodSig);
+ if (superMethod != null) {
+ return buildConstrainingInfo(superCls, superMethod);
+ }
+
+ //Otherwise recursively call this on the super class
+ return getConstrainingInfo(superCls, m);
+ }
+
+ return null;
+ }
+ }
+
+ /** finds a method that matches the name and signature in the given class
+ * @param cls the class to look in
+ * @param methodName the name to look for
+ * @param methodSig the signature to look for
+ *
+ * @return the method or null
+ */
+ private Method findMethod(JavaClass cls, String methodName, String methodSig) {
+ Method[] methods = cls.getMethods();
+ for (Method method : methods) {
+ if (method.getName().equals(methodName) && method.getSignature().equals(methodSig)) {
+ return method;
+ }
+ }
+ return null;
+ }
+
+ /** returns exception names describing what exceptions are allowed to be thrown
+ *
+ * @param cls the cls to find the exceptions in
+ * @param m the method to add exceptions from
+ * @return a map with one entry of a class name to a set of exceptions that constrain what can be thrown.
+ */
+ private Map<String, Set<String>> buildConstrainingInfo(JavaClass cls, Method m) {
+ Map<String, Set<String>> constraintInfo = new HashMap<String, Set<String>>();
+ Set<String> exs = new HashSet<String>();
+ ExceptionTable et = m.getExceptionTable();
+ if (et != null) {
+ int[] indexTable = et.getExceptionIndexTable();
+ ConstantPool pool = cls.getConstantPool();
+ for (int i = 0; i < indexTable.length; i++) {
+ int index = indexTable[i];
+ if (index != 0) {
+ ConstantClass ccls = (ConstantClass)pool.getConstant(index);
+ exs.add(ccls.getBytes(pool));
+ }
+ }
+ }
+ constraintInfo.put(cls.getClassName(), exs);
+ return constraintInfo;
+ }
+
/** returns whether a method explicitly throws an exception
*
* @param method the currently parsed method
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2007-10-07 23:41:34 UTC (rev 925)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2007-10-08 01:34:32 UTC (rev 926)
@@ -38,6 +38,36 @@
return findInheritedMethod(supers, methodName, signature) != null;
}
+ /**
+ * returns whether or not the two packages have the same first 'depth' parts, if they exist
+ *
+ * @param packName1 the first package to check
+ * @param packName2 the second package to check
+ * @param depth the number of package parts to check
+ *
+ * @return if they are similar
+ */
+ public static boolean similarPackages(final String packName1, final String packName2, int depth) {
+ if (depth == 0)
+ return true;
+
+ int dot1 = packName1.indexOf('.');
+ int dot2 = packName2.indexOf('.');
+ if (dot1 < 0)
+ return (dot2 < 0);
+ else if (dot2 < 0)
+ return false;
+
+ String s1 = packName1.substring(0, dot1);
+ String s2 = packName2.substring(0, dot2);
+
+ if (!s1.equals(s2))
+ return false;
+
+ return similarPackages(packName1.substring(dot1+1), packName2.substring(dot2+1), depth-1);
+ }
+
+
private static JavaClass findInheritedMethod(JavaClass[] classes, String methodName, String signature) {
for (JavaClass cls : classes) {
if (cls != null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-11 05:57:17
|
Revision: 931
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=931&view=rev
Author: dbrosius
Date: 2007-10-10 22:57:21 -0700 (Wed, 10 Oct 2007)
Log Message:
-----------
filter out RuntimeExceptions from throws clauses when building constraining info
Modified Paths:
--------------
trunk/fb-contrib/samples/EXS_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java
Modified: trunk/fb-contrib/samples/EXS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/EXS_Sample.java 2007-10-11 03:21:15 UTC (rev 930)
+++ trunk/fb-contrib/samples/EXS_Sample.java 2007-10-11 05:57:21 UTC (rev 931)
@@ -43,6 +43,19 @@
throw new RuntimeException("Ooops");
}
}
+
+ @Override
+ public void constrainedByRuntime()
+ {
+ try
+ {
+ InputStream is = new FileInputStream("c:\\test.txt");
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Ooops");
+ }
+ }
}
class Super
@@ -52,4 +65,7 @@
public void constrainedNon() throws SQLException
{}
+
+ public void constrainedByRuntime() throws RuntimeException
+ {}
}
\ No newline at end of file
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-11 03:21:15 UTC (rev 930)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-11 05:57:21 UTC (rev 931)
@@ -344,7 +344,7 @@
* @param m the method to add exceptions from
* @return a map with one entry of a class name to a set of exceptions that constrain what can be thrown.
*/
- private Map<String, Set<String>> buildConstrainingInfo(JavaClass cls, Method m) {
+ private Map<String, Set<String>> buildConstrainingInfo(JavaClass cls, Method m) throws ClassNotFoundException {
Map<String, Set<String>> constraintInfo = new HashMap<String, Set<String>>();
Set<String> exs = new HashSet<String>();
ExceptionTable et = m.getExceptionTable();
@@ -355,7 +355,10 @@
int index = indexTable[i];
if (index != 0) {
ConstantClass ccls = (ConstantClass)pool.getConstant(index);
- exs.add(ccls.getBytes(pool));
+ String exName = ccls.getBytes(pool);
+ JavaClass exClass = Repository.lookupClass(exName);
+ if (!exClass.instanceOf(runtimeClass))
+ exs.add(ccls.getBytes(pool));
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-13 03:30:41
|
Revision: 935
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=935&view=rev
Author: dbrosius
Date: 2007-10-12 20:30:42 -0700 (Fri, 12 Oct 2007)
Log Message:
-----------
add SPP_USELESS_TRINARY to the SPP detector
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 2007-10-12 01:51:10 UTC (rev 934)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-10-13 03:30:42 UTC (rev 935)
@@ -256,7 +256,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri"
speed="fast"
- reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT" />
+ reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT,SPP_USELESS_TRINARY" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
speed="fast"
@@ -381,6 +381,7 @@
<BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" />
<BugPattern abbrev="SPP" type="SPP_INVALID_BOOLEAN_NULL_CHECK" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="SPP" type="SPP_USE_CHARAT" category="PERFORMANCE" experimental="true" />
+ <BugPattern abbrev="SPP" type="SPP_USELESS_TRINARY" category="PERFORMANCE" experimental="true" />
<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 2007-10-12 01:51:10 UTC (rev 934)
+++ trunk/fb-contrib/etc/messages.xml 2007-10-13 03:30:42 UTC (rev 935)
@@ -1869,6 +1869,17 @@
</Details>
</BugPattern>
+ <BugPattern type="SPP_USELESS_TRINARY">
+ <ShortDescription>Method uses a trinary operator to cast a boolean to true or false</ShortDescription>
+ <LongDescription>Method {1} uses a trinary operator to cast a boolean to true or false</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method tests the value of a boolean and using a trinary operator to return either true or false.
+ The trinary operator is completely unecessary, just use the original boolean value.</p>
+ ]]>
+ </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 2007-10-12 01:51:10 UTC (rev 934)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 03:30:42 UTC (rev 935)
@@ -78,4 +78,9 @@
return s.toCharArray()[0];
return ' ';
}
+
+ public boolean testUselessTrinary(boolean b)
+ {
+ return (b ? true : false);
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-12 01:51:10 UTC (rev 934)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 03:30:42 UTC (rev 935)
@@ -90,7 +90,17 @@
try {
stack.mergeJumps(this);
- if (seen == LDC2_W) {
+ if (seen == ICONST_0) {
+ byte[] bytes = getCode().getCode();
+ if (((0x00FF & bytes[lastPCs[3]]) == GOTO)
+ && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1)
+ && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ } else if (seen == LDC2_W) {
Object con = getConstantRefOperand();
if (con instanceof ConstantDouble) {
double d = ((ConstantDouble) con).getBytes();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-13 05:18:22
|
Revision: 937
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=937&view=rev
Author: dbrosius
Date: 2007-10-12 22:18:24 -0700 (Fri, 12 Oct 2007)
Log Message:
-----------
if the ICONST_1 statement is the target of a seemingly unrelated branch, it is probably caused by compiler emitted code, so don't report.
Modified Paths:
--------------
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 04:49:06 UTC (rev 936)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 05:18:24 UTC (rev 937)
@@ -83,4 +83,9 @@
{
return (b ? true : false);
}
+
+ public boolean testFPUselessTrinary(boolean a, boolean b)
+ {
+ return a || b;
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 04:49:06 UTC (rev 936)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 05:18:24 UTC (rev 937)
@@ -19,6 +19,8 @@
package com.mebigfatguy.fbcontrib.detect;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
@@ -43,6 +45,7 @@
private int lastPCs[];
private int lastOpcode;
private int lastReg;
+ private Set<Integer> branchTargets;
/**
* constructs a SPP detector given the reporter to report bugs on
@@ -57,10 +60,12 @@
try {
stack = new OpcodeStack();
lastPCs = new int[4];
+ branchTargets = new HashSet<Integer>();
super.visitClassContext(classContext);
} finally {
stack = null;
lastPCs = null;
+ branchTargets = null;
}
}
@@ -75,6 +80,7 @@
lastOpcode = -1;
lastReg = -1;
Arrays.fill(lastPCs, -1);
+ branchTargets.clear();
super.visitCode(obj);
}
@@ -90,9 +96,15 @@
try {
stack.mergeJumps(this);
+ if ((seen >= IFEQ) && (seen <= GOTO)) {
+ branchTargets.add(Integer.valueOf(getBranchTarget()));
+ }
+
+
if (seen == ICONST_0) {
byte[] bytes = getCode().getCode();
if ((lastPCs[3] != -1)
+ && (!branchTargets.contains(Integer.valueOf(lastPCs[2])))
&& ((0x00FF & bytes[lastPCs[3]]) == GOTO)
&& ((0x00FF & bytes[lastPCs[2]]) == ICONST_1)
&& ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-13 06:07:03
|
Revision: 938
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=938&view=rev
Author: dbrosius
Date: 2007-10-12 23:06:58 -0700 (Fri, 12 Oct 2007)
Log Message:
-----------
If the ICONST_1 instruction is the branch target of one or more src statements, or if the ICONST_0 is the branch target of two or more src statements, it is probably generated by the compiler so don't report.
Modified Paths:
--------------
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 05:18:24 UTC (rev 937)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 06:06:58 UTC (rev 938)
@@ -86,6 +86,9 @@
public boolean testFPUselessTrinary(boolean a, boolean b)
{
- return a || b;
+ if (a && b)
+ return a || b;
+
+ return a && b;
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 05:18:24 UTC (rev 937)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 06:06:58 UTC (rev 938)
@@ -19,7 +19,9 @@
package com.mebigfatguy.fbcontrib.detect;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.bcel.Repository;
@@ -45,7 +47,8 @@
private int lastPCs[];
private int lastOpcode;
private int lastReg;
- private Set<Integer> branchTargets;
+ /** branch targets, to a set of branch instructions */
+ private Map<Integer, Set<Integer>> branchTargets;
/**
* constructs a SPP detector given the reporter to report bugs on
@@ -60,7 +63,7 @@
try {
stack = new OpcodeStack();
lastPCs = new int[4];
- branchTargets = new HashSet<Integer>();
+ branchTargets = new HashMap<Integer, Set<Integer>>();
super.visitClassContext(classContext);
} finally {
stack = null;
@@ -97,21 +100,37 @@
stack.mergeJumps(this);
if ((seen >= IFEQ) && (seen <= GOTO)) {
- branchTargets.add(Integer.valueOf(getBranchTarget()));
+ Integer branchTarget = Integer.valueOf(getBranchTarget());
+ Set<Integer> branchInsSet = branchTargets.get(branchTarget);
+ if (branchInsSet == null)
+ {
+ branchInsSet = new HashSet<Integer>();
+ branchTargets.put(branchTarget, branchInsSet);
+ }
+ branchInsSet.add(Integer.valueOf(getPC()));
}
if (seen == ICONST_0) {
byte[] bytes = getCode().getCode();
if ((lastPCs[3] != -1)
- && (!branchTargets.contains(Integer.valueOf(lastPCs[2])))
&& ((0x00FF & bytes[lastPCs[3]]) == GOTO)
&& ((0x00FF & bytes[lastPCs[2]]) == ICONST_1)
&& ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) {
- bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ boolean bug = true;
+ Set<Integer> branchInsSet = branchTargets.get(Integer.valueOf(getPC()));
+ if (branchInsSet.size() > 1)
+ bug = false;
+ branchInsSet = branchTargets.get(Integer.valueOf(lastPCs[2]));
+ if (branchInsSet != null)
+ bug = false;
+
+ if (bug) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
} else if (seen == LDC2_W) {
Object con = getConstantRefOperand();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-10-31 05:17:02
|
Revision: 942
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=942&view=rev
Author: dbrosius
Date: 2007-10-30 22:16:52 -0700 (Tue, 30 Oct 2007)
Log Message:
-----------
don't report useless trinaries when the ifeq is on something other than a boolean
Modified Paths:
--------------
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-18 05:38:45 UTC (rev 941)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-31 05:16:52 UTC (rev 942)
@@ -91,4 +91,9 @@
return a && b;
}
+
+ public boolean testFPTrinaryOnInt(String s)
+ {
+ return (s.length() != 0);
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-18 05:38:45 UTC (rev 941)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-31 05:16:52 UTC (rev 942)
@@ -47,6 +47,7 @@
private int lastPCs[];
private int lastOpcode;
private int lastReg;
+ private boolean lastIfEqWasBoolean;
/** branch targets, to a set of branch instructions */
private Map<Integer, Set<Integer>> branchTargets;
@@ -82,6 +83,7 @@
stack.resetForMethodEntry(this);
lastOpcode = -1;
lastReg = -1;
+ lastIfEqWasBoolean = false;
Arrays.fill(lastPCs, -1);
branchTargets.clear();
super.visitCode(obj);
@@ -110,8 +112,12 @@
branchInsSet.add(Integer.valueOf(getPC()));
}
-
- if (seen == IRETURN) {
+ if (seen == IFEQ) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ lastIfEqWasBoolean = "Z".equals(itm.getElementSignature());
+ }
+ } else if ((seen == IRETURN) && lastIfEqWasBoolean) {
byte[] bytes = getCode().getCode();
if ((lastPCs[0] != -1)
&& ((0x00FF & bytes[lastPCs[3]]) == ICONST_0)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-11-02 05:00:20
|
Revision: 949
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=949&view=rev
Author: dbrosius
Date: 2007-11-01 22:00:22 -0700 (Thu, 01 Nov 2007)
Log Message:
-----------
initial checkin CFS detector, barely working
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/CFS_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2007-11-02 03:30:37 UTC (rev 948)
+++ trunk/fb-contrib/etc/findbugs.xml 2007-11-02 05:00:22 UTC (rev 949)
@@ -300,6 +300,10 @@
speed="moderate"
reports="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS,EXS_EXCEPTION_SOFTENING_HAS_CHECKED,EXS_EXCEPTION_SOFTENING_NO_CHECKED" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics"
+ speed="fast"
+ reports="CFS_CONFUSING_FUNCTION_SEMANTICS" />
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -396,4 +400,5 @@
<BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS" category="STYLE" experimental="true" />
<BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_HAS_CHECKED" category="STYLE" experimental="true" />
<BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_NO_CHECKED" category="STYLE" experimental="true" />
+ <BugPattern abbrev="CFS" type="CFS_CONFUSING_FUNCTION_SEMANTICS" category="STYLE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2007-11-02 03:30:37 UTC (rev 948)
+++ trunk/fb-contrib/etc/messages.xml 2007-11-02 05:00:22 UTC (rev 949)
@@ -584,7 +584,7 @@
<Details>
<![CDATA[
<p>looks for if/else blocks where a series of them use instanceof on the same
- variable to determine what do to. If these classes are related by inheritance,
+ variable to determine what to do. If these classes are related by inheritance,
this often is better handled through calling a single overridden method.</p>
<p>It is a moderately fast detector</p>
]]>
@@ -816,6 +816,21 @@
</Details>
</Detector>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics">
+ <Details>
+ <![CDATA[
+ <p>looks for methods that return a parameter after modifying that parameter.
+ Doing this will confuse the user of this method, as it will be assumed that the
+ passed in argument is different than the output, or at least won't be changed.
+ If the purpose of this method is just to modify the parameter, this method should
+ probably be changed to have a void return type. If you must return a variable, perhaps
+ a clone of the parameter should be returned.
+ </p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
<!-- BugPattern -->
<BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING">
@@ -2055,6 +2070,21 @@
</Details>
</BugPattern>
+ <BugPattern type="CFS_CONFUSING_FUNCTION_SEMANTICS">
+ <ShortDescription>method returns modified parameter</ShortDescription>
+ <LongDescription>method {1} returns modified parameter</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method appears to modify a parameter, and then return this parameter as the
+ methods return value. This will be confusing to callers of this method, as it won't be
+ apparent that the 'original' passed in parameter will be changed as well. If the purpose
+ of this method is to change the parameter, it would be more clear to change the method to
+ a have a void return value. If a return type is required due to interface or superclass contract,
+ perhaps a clone of the parameter should be made.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
<!-- BugCode -->
<BugCode abbrev="ISB">Inefficient String Buffering</BugCode>
@@ -2124,4 +2154,5 @@
<BugCode abbrev="NCS">Needless Custom Serialization</BugCode>
<BugCode abbrev="MOM">Misleading Overload Model</BugCode>
<BugCode abbrev="EXS">Exception Softening</BugCode>
+ <BugCode abbrev="CFS">Confusing Function Semantics</BugCode>
</MessageCollection>
\ No newline at end of file
Added: trunk/fb-contrib/samples/CFS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/CFS_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/CFS_Sample.java 2007-11-02 05:00:22 UTC (rev 949)
@@ -0,0 +1,10 @@
+import java.util.Date;
+
+public class CFS_Sample
+{
+ public Date getNextDate(Date d)
+ {
+ d.setHours(0);
+ return d;
+ }
+}
Property changes on: trunk/fb-contrib/samples/CFS_Sample.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-02 05:00:22 UTC (rev 949)
@@ -0,0 +1,199 @@
+/*
+ * fb-contrib - Auxilliary detectors for Java programs
+ * Copyright (C) 2005-2007 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 java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.Type;
+
+import com.mebigfatguy.fbcontrib.utils.Integer14;
+import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+/** looks for methods that return a parameter after making what looks like
+ * modifications to that parameter. This leads to confusing on the user of this
+ * method as it isn't obvious that the 'original' object is modified. If the
+ * point of this method is to modify the parameter, it is probably better just
+ * to have the method be a void method, to avoid confusion.
+ */
+public class ConfusingFunctionSemantics extends BytecodeScanningDetector
+{
+ private static final Set<String> knownImmutables = new HashSet<String>();
+ static {
+ knownImmutables.add("Ljava/lang/String;");
+ knownImmutables.add("Ljava/lang/Byte;");
+ knownImmutables.add("Ljava/lang/Character;");
+ knownImmutables.add("Ljava/lang/Short;");
+ knownImmutables.add("Ljava/lang/Integer;");
+ knownImmutables.add("Ljava/lang/Long;");
+ knownImmutables.add("Ljava/lang/Float;");
+ knownImmutables.add("Ljava/lang/Double;");
+ knownImmutables.add("Ljava/lang/Boolean;");
+ knownImmutables.add("Ljava/lang/Class;");
+ };
+
+ private BugReporter bugReporter;
+ private Map<Integer, ParmUsage> possibleParmRegs;
+ private OpcodeStack stack;
+
+ /**
+ * constructs a CFS detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public ConfusingFunctionSemantics(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ /** implements the visitor to initialize/destroy the possible parameter registers and opcode stack
+ *
+ * @param classContext the context object of the currently parsed class
+ */
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ possibleParmRegs = new HashMap<Integer, ParmUsage>();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ possibleParmRegs = null;
+ }
+ }
+
+ /** implements the visitor to look for any non-immutable typed parameters are assignable
+ * to the return type. If found, the method is parsed.
+ *
+ * @param obj the context object of the currently parsed code block
+ */
+ @Override
+ public void visitCode(Code obj) {
+ try {
+ Method m = getMethod();
+ String methodSignature = m.getSignature();
+ String retSignature = Type.getReturnType(methodSignature).getSignature();
+ JavaClass returnClass = null;
+ int[] parmRegs = null;
+
+ if ((retSignature.charAt(0) == 'L') && !knownImmutables.contains(retSignature)) {
+ Type[] parmTypes = Type.getArgumentTypes(methodSignature);
+ for (int p = 0; p < parmTypes.length; p++) {
+ String parmSignature = parmTypes[p].getSignature();
+ if ((parmSignature.charAt(0) == 'L') && !knownImmutables.contains(parmSignature)) {
+ if (returnClass == null) {
+ returnClass = Repository.lookupClass(retSignature.substring(1, retSignature.length() - 1));
+ parmRegs = RegisterUtils.getParameterRegisters(m);
+ }
+
+ JavaClass parmClass = Repository.lookupClass(parmSignature.substring(1, parmSignature.length() - 1));
+ if (parmClass.instanceOf(returnClass)) {
+ possibleParmRegs.put(Integer14.valueOf(parmRegs[p]), new ParmUsage());
+ }
+ }
+ }
+
+ if (possibleParmRegs.size() > 0) {
+ stack.resetForMethodEntry(this);
+ super.visitCode(obj);
+ for (Map.Entry<Integer, ParmUsage> entry : possibleParmRegs.entrySet()) {
+ Integer reg = entry.getKey();
+ ParmUsage pu = entry.getValue();
+
+ if (pu.returned && (pu.alteredPC >= 0)) {
+ bugReporter.reportBug(new BugInstance(this, "CFS_CONFUSING_FUNCTION_SEMANTICS", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this, pu.alteredPC));
+ }
+ }
+ }
+ }
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ }
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ if (possibleParmRegs.size() == 0)
+ return;
+
+ try {
+ if (seen == ARETURN) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ int reg = item.getRegisterNumber();
+ ParmUsage pu = possibleParmRegs.get(Integer14.valueOf(reg));
+ if (pu != null)
+ pu.setReturned();
+ }
+ } else if (seen == PUTFIELD) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item item = stack.getStackItem(1);
+ int reg = item.getRegisterNumber();
+ ParmUsage pu = possibleParmRegs.get(Integer14.valueOf(reg));
+ if (pu != null)
+ pu.setAlteredPC(getPC());
+ }
+ } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) {
+ String calledSig = getSigConstantOperand();
+ String calledRet = Type.getReturnType(calledSig).getSignature();
+ if ("V".equals(calledRet)) {
+ int calledObjOffset = Type.getArgumentTypes(calledSig).length;
+ if (stack.getStackDepth() >= calledObjOffset) {
+ OpcodeStack.Item item = stack.getStackItem(calledObjOffset);
+ int reg = item.getRegisterNumber();
+ ParmUsage pu = possibleParmRegs.get(Integer14.valueOf(reg));
+ if (pu != null)
+ pu.setAlteredPC(getPC());
+ }
+ }
+ }
+
+ } finally {
+ stack.sawOpcode(this, seen);
+ }
+ }
+
+ static class ParmUsage
+ {
+ boolean returned = false;
+ int alteredPC = -1;
+
+ public void setReturned() {
+ returned = true;
+ }
+
+ public void setAlteredPC(int pc) {
+ if (alteredPC < 0)
+ alteredPC = pc;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-11-03 02:52:52
|
Revision: 951
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=951&view=rev
Author: dbrosius
Date: 2007-11-02 19:52:55 -0700 (Fri, 02 Nov 2007)
Log Message:
-----------
if a store to a parameter occurs, remove that parameter from considerations
Modified Paths:
--------------
trunk/fb-contrib/samples/CFS_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java
Modified: trunk/fb-contrib/samples/CFS_Sample.java
===================================================================
--- trunk/fb-contrib/samples/CFS_Sample.java 2007-11-02 23:16:33 UTC (rev 950)
+++ trunk/fb-contrib/samples/CFS_Sample.java 2007-11-03 02:52:55 UTC (rev 951)
@@ -7,4 +7,11 @@
d.setHours(0);
return d;
}
+
+ public Date getNextDateFP(Date d)
+ {
+ d = (Date)d.clone();
+ d.setHours(0);
+ return d;
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-02 23:16:33 UTC (rev 950)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-03 02:52:55 UTC (rev 951)
@@ -163,6 +163,9 @@
if (pu != null)
pu.setAlteredPC(getPC());
}
+ } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) {
+ int reg = RegisterUtils.getAStoreReg(this, seen);
+ possibleParmRegs.remove(Integer.valueOf(reg));
} else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) {
String calledSig = getSigConstantOperand();
String calledRet = Type.getReturnType(calledSig).getSignature();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|