fb-contrib-commit Mailing List for fb-contrib (Page 12)
Brought to you by:
dbrosius
You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(56) |
Oct
(60) |
Nov
(58) |
Dec
(89) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(66) |
Feb
(55) |
Mar
(85) |
Apr
(115) |
May
(35) |
Jun
(28) |
Jul
(3) |
Aug
(48) |
Sep
(37) |
Oct
(22) |
Nov
(14) |
Dec
(66) |
| 2007 |
Jan
(45) |
Feb
(63) |
Mar
(10) |
Apr
(1) |
May
(1) |
Jun
(12) |
Jul
|
Aug
|
Sep
(25) |
Oct
(21) |
Nov
(39) |
Dec
|
| 2008 |
Jan
(7) |
Feb
|
Mar
(26) |
Apr
(5) |
May
(2) |
Jun
(32) |
Jul
(9) |
Aug
(10) |
Sep
|
Oct
(3) |
Nov
(1) |
Dec
|
| 2009 |
Jan
(10) |
Feb
(31) |
Mar
(32) |
Apr
(35) |
May
(25) |
Jun
|
Jul
(31) |
Aug
(10) |
Sep
(95) |
Oct
(35) |
Nov
(10) |
Dec
(34) |
| 2010 |
Jan
(90) |
Feb
(4) |
Mar
(7) |
Apr
(20) |
May
(20) |
Jun
(13) |
Jul
(7) |
Aug
(18) |
Sep
(25) |
Oct
(4) |
Nov
(16) |
Dec
(2) |
| 2011 |
Jan
(1) |
Feb
|
Mar
(11) |
Apr
(3) |
May
(2) |
Jun
(26) |
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
| 2012 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(14) |
Nov
(3) |
Dec
(4) |
| 2013 |
Jan
(3) |
Feb
(2) |
Mar
(1) |
Apr
(4) |
May
|
Jun
(1) |
Jul
(3) |
Aug
|
Sep
|
Oct
(4) |
Nov
(3) |
Dec
(3) |
| 2014 |
Jan
(4) |
Feb
(2) |
Mar
(4) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
| 2016 |
Jan
(2) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
(2) |
Nov
(7) |
Dec
|
| 2017 |
Jan
(1) |
Feb
|
Mar
(4) |
Apr
(5) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(3) |
| 2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(5) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <dbr...@us...> - 2010-06-05 23:55:52
|
Revision: 1565
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1565&view=rev
Author: dbrosius
Date: 2010-06-05 23:55:43 +0000 (Sat, 05 Jun 2010)
Log Message:
-----------
get ready for the 4.4.0 release
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/htdocs/mbfg_menu.shtml
trunk/fb-contrib/pom.xml
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/build.xml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -20,7 +20,7 @@
<property name="javac.deprecation" value="on"/>
<property name="javac.debug" value="on"/>
- <property name="fb-contrib.version" value="4.3.0"/>
+ <property name="fb-contrib.version" value="4.4.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 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -113,9 +113,10 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.CustomBuiltXML"
speed="fast" reports="CBX_CUSTOM_BUILT_XML" />
+<!--
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedSynchronizedBlock"
speed="fast" reports="BSB_BLOATED_SYNCHRONIZED_BLOCK" hidden="true" />
-
+-->
<Detector class="com.mebigfatguy.fbcontrib.detect.ConstantListIndex"
speed="fast" reports="CLI_CONSTANT_LIST_INDEX" />
@@ -279,14 +280,14 @@
<Detector
class="com.mebigfatguy.fbcontrib.detect.DeprecatedTypesafeEnumPattern"
speed="fast" reports="DTEP_DEPRECATED_TYPESAFE_ENUM_PATTERN" />
-
+<!--
<Detector class="com.mebigfatguy.fbcontrib.detect.StutteredMethodArguments"
speed="fast" reports="SMA_STUTTERED_METHOD_ARGUMENTS" hidden="true" />
+-->
<Detector class="com.mebigfatguy.fbcontrib.detect.TristateBooleanPattern"
speed="fast" reports="TBP_TRISTATE_BOOLEAN_PATTERN" />
-
<Detector
class="com.mebigfatguy.fbcontrib.detect.SuspiciousUninitializedArray"
speed="fast" reports="SUA_SUSPICIOUS_UNINITIALIZED_ARRAY" />
@@ -306,16 +307,18 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NonSymmetricEquals"
speed="fast" reports="NSE_NON_SYMMETRIC_EQUALS" />
+<!--
<Detector
class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment"
speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" />
-
+ -->
+
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField"
speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
-
+<!--
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard"
speed="fast" hidden="true" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
-
+-->
<Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods"
speed="fast"
reports="MDM_RUNTIME_EXIT_OR_HALT,MDM_RUNFINALIZATION,MDM_BIGDECIMAL_EQUALS,MDM_INETADDRESS_GETLOCALHOST,MDM_PROMISCUOUS_SERVERSOCKET,MDM_RANDOM_SEED,MDM_SECURERANDOM_CTOR,MDM_SECURERANDOM_GETSEED,MDM_THREAD_PRIORITIES,MDM_THREAD_YIELD,MDM_WAIT_WITHOUT_TIMEOUT,MDM_THREAD_FAIRNESS,MDM_REENTRANTLOCK_HELDBY,MDM_STRING_BYTES_ENCODING,MDM_SETDEFAULTLOCALE" />
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -51,9 +51,9 @@
<a href="bugdescriptions.html">Bug Descriptions</a>
<!--#include virtual="mbfg_menu.shtml" -->
<hr/>
- <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
+ <img id="svn_image" src="flip1.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
Detectors added in svn<br/>
- <div id="svn" style="display:block;">
+ <div id="svn" style="display:none">
<ul>
<li><b>[CVAA] ContraVariant Array Assignment</b><br/>
Looks for contravariant array assignments. Since arrays are mutable data structures, their use
@@ -66,6 +66,13 @@
check. Instead it references another object of the same type. It is likely that null
check is being done on the wrong variable, either because of a copy/paste error,
or a change in implementation.</li>
+ </ul>
+ </div>
+ <hr/>
+ <img id="v4_4_0_image" src="flip2.gif" onClick="toggleBlock('v4_4_0', 'v4_4_0_image');" align="top"/>
+ Detectors added in v4.4.0<br/>
+ <div id="v4_4_0" style="display:block;">
+ <ul>
<li><b>[ROOM] Reflection on Object Methods</b><br/>
Looks for method calls through reflection on methods found in java.lang.Object.
As these methods are always available, there's no reason to do this.</li>
Modified: trunk/fb-contrib/htdocs/mbfg_menu.shtml
===================================================================
--- trunk/fb-contrib/htdocs/mbfg_menu.shtml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/htdocs/mbfg_menu.shtml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -10,7 +10,8 @@
<li><a href="http://pixelle.sf.net">Pixelle</a></li>
<li><a href="http://polycasso.sf.net">Polycasso</a></li>
<li><a href="http://schemalizer.sf.net">Schemalizer</a></li>
- <li><a href="http://tomailer.sf.net">ToMailer</a></li>
+ <li><a href="http://tomailer.sf.net">ToMailer</a></li>
+ <li><a href="http://jd4a.sf.net">JavaDoc for Android</a></li>
<li><a href="http://www.heartofgoldfarm.com">Heart of Gold Farm</a></li>
</ul>
</div>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/pom.xml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>4.3.0-SNAPSHOT</version>
+ <version>4.4.0-SNAPSHOT</version>
<name>FindBugs Contrib plugin library</name>
<description>An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.</description>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-25 03:30:29
|
Revision: 1564
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1564&view=rev
Author: dbrosius
Date: 2010-05-25 03:30:23 +0000 (Tue, 25 May 2010)
Log Message:
-----------
always report UVA as LOW
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-25 03:27:51 UTC (rev 1563)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-25 03:30:23 UTC (rev 1564)
@@ -82,7 +82,7 @@
}
super.visitMethod(obj);
- bugReporter.reportBug(new BugInstance(this, "UVA_USE_VAR_ARGS", (types.length == 1) ? NORMAL_PRIORITY : LOW_PRIORITY)
+ bugReporter.reportBug(new BugInstance(this, "UVA_USE_VAR_ARGS", LOW_PRIORITY)
.addClass(this)
.addMethod(this));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-25 03:27:57
|
Revision: 1563
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1563&view=rev
Author: dbrosius
Date: 2010-05-25 03:27:51 +0000 (Tue, 25 May 2010)
Log Message:
-----------
document UVA
Modified Paths:
--------------
trunk/fb-contrib/htdocs/index.shtml
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-05-20 01:46:12 UTC (rev 1562)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-05-25 03:27:51 UTC (rev 1563)
@@ -83,6 +83,10 @@
Looks for allocations and initializations of java collections, but that are never
read from or accessed to gain information. This represents a collection of no use, and most probably
can be removed. It is similar to a dead local store.</li>
+ <li><b>[UVA] Use Var Args</b><br/>
+ Looks for definitions of methods that have an array as the last parameter.
+ Since this class is compiled with java 1.5 or better, it would be more flexible for clients of this
+ method to define this parameter as a vararg parameter.</li>
</ul>
</div>
<hr/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-20 01:46:19
|
Revision: 1562
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1562&view=rev
Author: dbrosius
Date: 2010-05-20 01:46:12 +0000 (Thu, 20 May 2010)
Log Message:
-----------
don't report if the non var args parm is similar to the would be varargs parm
Modified Paths:
--------------
trunk/fb-contrib/samples/UVA_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
Modified: trunk/fb-contrib/samples/UVA_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UVA_Sample.java 2010-05-19 13:06:39 UTC (rev 1561)
+++ trunk/fb-contrib/samples/UVA_Sample.java 2010-05-20 01:46:12 UTC (rev 1562)
@@ -7,12 +7,9 @@
public void testNormalUVA(String[] foo)
{}
- public void testLowUVA1(int boo, int[] hoo)
+ public void testLowUVA1(int boo, String[] hoo)
{}
- public void testLowUVA2(int boo, String hoo, Date[] woo)
- {}
-
public static void testStaticUVA(Date[] d)
{}
@@ -28,6 +25,12 @@
public void fpNotAtEnd(String[] foo, int bar)
{}
+ public void fpAlreadyVarArg(String...darnit)
+ {}
+
+ public void fpSimilarVarArg(String info, String...data)
+ {}
+
@Override
public <T> T[] toArray(T[] a)
{
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 13:06:39 UTC (rev 1561)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-20 01:46:12 UTC (rev 1562)
@@ -56,7 +56,7 @@
}
Type[] types = obj.getArgumentTypes();
- if ((types.length == 0) || (types.length > 3)) {
+ if ((types.length == 0) || (types.length > 2)) {
return;
}
@@ -69,10 +69,8 @@
return;
}
- for (int i = 0; i < types.length - 1; i++) {
- if (types[i].getSignature().startsWith("[")) {
- return;
- }
+ if (hasSimilarParms(types)) {
+ return;
}
if (obj.isStatic() && "main".equals(obj.getName()) && "([Ljava/lang/String;)V".equals(obj.getSignature())) {
@@ -97,6 +95,28 @@
public void report() {
}
+ private boolean hasSimilarParms(Type[] argTypes) {
+
+ for (int i = 0; i < argTypes.length - 1; i++) {
+ if (argTypes[i].getSignature().startsWith("[")) {
+ return true;
+ }
+ }
+
+ String baseType = argTypes[argTypes.length-1].getSignature();
+ while (baseType.startsWith("[")) {
+ baseType = baseType.substring(1);
+ }
+
+ for (int i = 0; i < argTypes.length - 1; i++) {
+ if (argTypes[i].getSignature().equals(baseType)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private boolean isInherited(Method m) throws ClassNotFoundException {
JavaClass[] infs = javaClass.getAllInterfaces();
for (JavaClass inf : infs) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-19 13:06:47
|
Revision: 1561
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1561&view=rev
Author: dbrosius
Date: 2010-05-19 13:06:39 +0000 (Wed, 19 May 2010)
Log Message:
-----------
if it's already a vararg, don't report duh!
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 05:35:24 UTC (rev 1560)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 13:06:39 UTC (rev 1561)
@@ -60,6 +60,10 @@
return;
}
+ if ((obj.getAccessFlags() & Constants.ACC_VARARGS) != 0) {
+ return;
+ }
+
String lastParmSig = types[types.length-1].getSignature();
if (!lastParmSig.startsWith("[") || lastParmSig.startsWith("[[")) {
return;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-19 05:35:30
|
Revision: 1560
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1560&view=rev
Author: dbrosius
Date: 2010-05-19 05:35:24 +0000 (Wed, 19 May 2010)
Log Message:
-----------
don't report multi array parmed methods
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 05:31:14 UTC (rev 1559)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 05:35:24 UTC (rev 1560)
@@ -65,6 +65,12 @@
return;
}
+ for (int i = 0; i < types.length - 1; i++) {
+ if (types[i].getSignature().startsWith("[")) {
+ return;
+ }
+ }
+
if (obj.isStatic() && "main".equals(obj.getName()) && "([Ljava/lang/String;)V".equals(obj.getSignature())) {
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-19 05:31:20
|
Revision: 1559
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1559&view=rev
Author: dbrosius
Date: 2010-05-19 05:31:14 +0000 (Wed, 19 May 2010)
Log Message:
-----------
new detector UVA
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/UVA_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-05-11 03:50:30 UTC (rev 1558)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-05-19 05:31:14 UTC (rev 1559)
@@ -335,6 +335,10 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection"
speed="fast"
reports="WOC_WRITE_ONLY_COLLECTION_LOCAL,WOC_WRITE_ONLY_COLLECTION_FIELD" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs"
+ speed="fast"
+ reports="UVA_USE_VAR_ARGS" />
<!-- BugPattern -->
@@ -635,4 +639,6 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_FIELD"
category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="UVA" type="UVA_USE_VAR_ARGS"
+ category="STYLE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-05-11 03:50:30 UTC (rev 1558)
+++ trunk/fb-contrib/etc/messages.xml 2010-05-19 05:31:14 UTC (rev 1559)
@@ -1145,6 +1145,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for definitions of methods that have an array as the last parameter.
+ Since this class is compiled with java 1.5 or better, it would be more flexible for clients of this
+ method to define this parameter as a vararg parameter</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -3142,6 +3153,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="UVA_USE_VAR_ARGS">
+ <ShortDescription>Method defines parameter list with array as last argument, rather than vararg</ShortDescription>
+ <LongDescription>Method {1} defines parameter list with array as last argument, rather than vararg</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method defines a parameter list that ends with an array. As this class is compiled with
+ Java 1.5 or better, this parameter could be defined as a vararg parameter instead, which can be
+ more convienent for client developers to use. This is not a bug, per se, just an improvement.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3239,4 +3262,5 @@
<BugCode abbrev="IPU">Improper Properties use</BugCode>
<BugCode abbrev="PCAIL">Possible Constant Allocation In Loop</BugCode>
<BugCode abbrev="WOC">Write Only Collection</BugCode>
+ <BugCode abbrev="UVA">Use Var Args</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/UVA_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UVA_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/UVA_Sample.java 2010-05-19 05:31:14 UTC (rev 1559)
@@ -0,0 +1,36 @@
+import java.util.ArrayList;
+import java.util.Date;
+
+
+public class UVA_Sample<T> extends ArrayList<T>
+{
+ public void testNormalUVA(String[] foo)
+ {}
+
+ public void testLowUVA1(int boo, int[] hoo)
+ {}
+
+ public void testLowUVA2(int boo, String hoo, Date[] woo)
+ {}
+
+ public static void testStaticUVA(Date[] d)
+ {}
+
+ public void fpNoParms()
+ {}
+
+ public void fpHasOtherArrayUVA1(String[] one, int[] two)
+ {}
+
+ public void fpTooManyArgs(int i, char j, long k, String[] moo)
+ {}
+
+ public void fpNotAtEnd(String[] foo, int bar)
+ {}
+
+ @Override
+ public <T> T[] toArray(T[] a)
+ {
+ return null;
+ }
+}
Property changes on: trunk/fb-contrib/samples/UVA_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 05:31:14 UTC (rev 1559)
@@ -0,0 +1,118 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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.Constants;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.Type;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.Detector;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.visitclass.PreorderVisitor;
+
+public class UseVarArgs extends PreorderVisitor implements Detector
+{
+ private BugReporter bugReporter;
+ private JavaClass javaClass;
+
+ public UseVarArgs(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ javaClass = classContext.getJavaClass();
+ if (javaClass.getMajor() >= Constants.MAJOR_1_5) {
+ javaClass.accept(this);
+ }
+ } finally {
+ javaClass = null;
+ }
+ }
+
+ public void visitMethod(Method obj) {
+ try {
+ if (obj.isSynthetic()) {
+ return;
+ }
+
+ Type[] types = obj.getArgumentTypes();
+ if ((types.length == 0) || (types.length > 3)) {
+ return;
+ }
+
+ String lastParmSig = types[types.length-1].getSignature();
+ if (!lastParmSig.startsWith("[") || lastParmSig.startsWith("[[")) {
+ return;
+ }
+
+ if (obj.isStatic() && "main".equals(obj.getName()) && "([Ljava/lang/String;)V".equals(obj.getSignature())) {
+ return;
+ }
+
+ if (!obj.isPrivate() && !obj.isStatic() && isInherited(obj)) {
+ return;
+ }
+
+ super.visitMethod(obj);
+ bugReporter.reportBug(new BugInstance(this, "UVA_USE_VAR_ARGS", (types.length == 1) ? NORMAL_PRIORITY : LOW_PRIORITY)
+ .addClass(this)
+ .addMethod(this));
+
+
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ }
+ }
+
+ public void report() {
+ }
+
+ private boolean isInherited(Method m) throws ClassNotFoundException {
+ JavaClass[] infs = javaClass.getAllInterfaces();
+ for (JavaClass inf : infs) {
+ if (hasMethod(inf, m))
+ return true;
+ }
+
+ JavaClass[] sups = javaClass.getSuperClasses();
+ for (JavaClass sup : sups) {
+ if (hasMethod(sup, m))
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean hasMethod(JavaClass c, Method candidateMethod) {
+ String name = candidateMethod.getName();
+ String sig = candidateMethod.getSignature();
+
+ for (Method method : c.getMethods()) {
+ if (!method.isStatic() && method.getName().equals(name) && method.getSignature().equals(sig)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-11 03:50:37
|
Revision: 1558
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1558&view=rev
Author: dbrosius
Date: 2010-05-11 03:50:30 +0000 (Tue, 11 May 2010)
Log Message:
-----------
oops, inverted logic
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-09 22:30:37 UTC (rev 1557)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-11 03:50:30 UTC (rev 1558)
@@ -211,7 +211,7 @@
clearUserValue(item);
} else if (!"clone".equals(name)) {
Type t = Type.getReturnType(sig);
- if ((t != Type.VOID) && nextOpIsPop()) {
+ if ((t != Type.VOID) && !nextOpIsPop()) {
clearUserValue(item);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-09 22:30:43
|
Revision: 1557
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1557&view=rev
Author: dbrosius
Date: 2010-05-09 22:30:37 +0000 (Sun, 09 May 2010)
Log Message:
-----------
npe check
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-09 22:19:35 UTC (rev 1556)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-09 22:30:37 UTC (rev 1557)
@@ -303,9 +303,11 @@
case GETSTATIC:
XField field = getXFieldOperand();
- String fieldName = field.getName();
- if (fieldWOCollections.containsKey(fieldName)) {
- userObject = fieldName;
+ if (field != null) {
+ String fieldName = field.getName();
+ if (fieldWOCollections.containsKey(fieldName)) {
+ userObject = fieldName;
+ }
}
break;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-09 22:19:41
|
Revision: 1556
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1556&view=rev
Author: dbrosius
Date: 2010-05-09 22:19:35 +0000 (Sun, 09 May 2010)
Log Message:
-----------
don't rely on getNextOpCode as it's fairly new
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-09 06:34:10 UTC (rev 1555)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-09 22:19:35 UTC (rev 1556)
@@ -211,7 +211,7 @@
clearUserValue(item);
} else if (!"clone".equals(name)) {
Type t = Type.getReturnType(sig);
- if ((t != Type.VOID) && (getNextOpcode() != POP)) {
+ if ((t != Type.VOID) && nextOpIsPop()) {
clearUserValue(item);
}
}
@@ -320,6 +320,11 @@
}
}
+ private boolean nextOpIsPop() {
+ int nextPC = getNextPC();
+ return getCode().getCode()[nextPC] == POP;
+ }
+
private void clearUserValue(OpcodeStack.Item item) {
Object uo = item.getUserValue();
if (uo instanceof Integer) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-09 06:34:16
|
Revision: 1555
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1555&view=rev
Author: dbrosius
Date: 2010-05-09 06:34:10 +0000 (Sun, 09 May 2010)
Log Message:
-----------
fix html
Modified Paths:
--------------
trunk/fb-contrib/htdocs/index.shtml
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-05-09 06:29:31 UTC (rev 1554)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-05-09 06:34:10 UTC (rev 1555)
@@ -51,9 +51,9 @@
<a href="bugdescriptions.html">Bug Descriptions</a>
<!--#include virtual="mbfg_menu.shtml" -->
<hr/>
- <img id="svn_image" src="flip1.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
+ <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
Detectors added in svn<br/>
- <div id="svn" style="display:none;">
+ <div id="svn" style="display:block;">
<ul>
<li><b>[CVAA] ContraVariant Array Assignment</b><br/>
Looks for contravariant array assignments. Since arrays are mutable data structures, their use
@@ -86,9 +86,9 @@
</ul>
</div>
<hr/>
- <img id="v4_2_0_image" src="flip2.gif" onClick="toggleBlock('v4_2_0', 'v4_2_0_image');" align="top"/>
+ <img id="v4_2_0_image" src="flip1.gif" onClick="toggleBlock('v4_2_0', 'v4_2_0_image');" align="top"/>
Detectors added in v4.2.0<br/>
- <div id="v4_2_0" style="display:block;">
+ <div id="v4_2_0" style="display:none;">
<ul>
<li><b>[PDP] Poorly Defined Parameter</b><br/>
Looks for non derivable methods that declare parameters and then cast those
@@ -118,7 +118,7 @@
</ul>
<ul>
<li><span style="color: #0000FF;">Maven pom file contributed by Grzegorz Slowikowski - THANKS!</span></li>
- <ul>
+ </ul>
</div>
<hr/>
<img id="v4_0_0_image" src="flip1.gif" onClick="toggleBlock('v4_0_0', 'v4_0_0_image');" align="top"/>
@@ -234,7 +234,7 @@
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.</b><br/>
+ or superclass contract.<br/>
</ul>
</div>
<hr/>
@@ -286,7 +286,7 @@
<li><b>[PIS] Possible Incomplete Synchronization</b><br/>
Looks for classes that don't handle serialization of parent class member fields
when the class in question is serializable but is derived from non serializable
- classes.</b><br/>
+ classes.<br/>
</ul>
</div>
<hr/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-09 06:29:38
|
Revision: 1554
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1554&view=rev
Author: dbrosius
Date: 2010-05-09 06:29:31 +0000 (Sun, 09 May 2010)
Log Message:
-----------
document PCAIL and WOC
Modified Paths:
--------------
trunk/fb-contrib/htdocs/index.shtml
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-05-08 22:44:03 UTC (rev 1553)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-05-09 06:29:31 UTC (rev 1554)
@@ -75,6 +75,14 @@
String only collection, putting other types in the Properties object is incorrect,
and takes advantage of a poor design decision by the original Properties class
designers to derive from Hashtable, rather than using aggregation.</li>
+ <li><b>[PCAIL] Possible Constant Allocation in Loop</b><br/>
+ Looks for allocations of objects using the default constructor in a loop, where
+ the object allocated is never assigned to any object that is used outside the loop.
+ It is possible that this allocation can be done outside the loop to avoid excessive garbage.</li>
+ <li><b>[WOC] Write Only Collection</b><br/>
+ Looks for allocations and initializations of java collections, but that are never
+ read from or accessed to gain information. This represents a collection of no use, and most probably
+ can be removed. It is similar to a dead local store.</li>
</ul>
</div>
<hr/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 22:44:09
|
Revision: 1553
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1553&view=rev
Author: dbrosius
Date: 2010-05-08 22:44:03 +0000 (Sat, 08 May 2010)
Log Message:
-----------
handle PUTSTATIC, GETSTATIC
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 21:34:19 UTC (rev 1552)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 22:44:03 UTC (rev 1553)
@@ -290,6 +290,24 @@
}
}
break;
+
+ case PUTSTATIC:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ Object uo = item.getUserValue();
+ if (!(uo instanceof Boolean)) {
+ clearUserValue(item);
+ }
+ }
+ break;
+
+ case GETSTATIC:
+ XField field = getXFieldOperand();
+ String fieldName = field.getName();
+ if (fieldWOCollections.containsKey(fieldName)) {
+ userObject = fieldName;
+ }
+ break;
}
} finally {
stack.sawOpcode(this, seen);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 21:34:26
|
Revision: 1552
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1552&view=rev
Author: dbrosius
Date: 2010-05-08 21:34:19 +0000 (Sat, 08 May 2010)
Log Message:
-----------
improve WOC handling of collections that are fields
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/WOC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-05-08 21:34:19 UTC (rev 1552)
@@ -334,7 +334,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection"
speed="fast"
- reports="WOC_WRITE_ONLY_COLLECTION" />
+ reports="WOC_WRITE_ONLY_COLLECTION_LOCAL,WOC_WRITE_ONLY_COLLECTION_FIELD" />
<!-- BugPattern -->
@@ -631,6 +631,8 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="PCAIL" type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP"
category="PERFORMANCE" experimental="true" />
- <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION"
+ <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_LOCAL"
category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_FIELD"
+ category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/etc/messages.xml 2010-05-08 21:34:19 UTC (rev 1552)
@@ -3119,7 +3119,7 @@
</Details>
</BugPattern>
- <BugPattern type="WOC_WRITE_ONLY_COLLECTION">
+ <BugPattern type="WOC_WRITE_ONLY_COLLECTION_LOCAL">
<ShortDescription>Method creates and initializes a collection but never reads or gains information from it</ShortDescription>
<LongDescription>Method {1} creates and initializes a collection but never reads or gains information from it</LongDescription>
<Details>
@@ -3130,6 +3130,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="WOC_WRITE_ONLY_COLLECTION_FIELD">
+ <ShortDescription>Class creates and initializes a collection but never reads or gains information from it</ShortDescription>
+ <LongDescription>Class {0} creates and initializes a collection but never reads or gains information from it</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This class creates and initializes a collection as a field but then never access this collection
+ to gain information, or fetch items from the collection. It is likely that this collection
+ is left over from a past effort, and can be removed.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
Modified: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 21:34:19 UTC (rev 1552)
@@ -10,12 +10,16 @@
public class WOC_Sample
{
private Set<String> memberSet = new HashSet<String>();
+ private Set<String> fpSet;
public void testWOCSimple()
{
Set<String> s = new HashSet<String>();
s.add("Foo");
memberSet.add("fee");
+ if (fpSet.retainAll(new HashSet<String>())) {
+ System.out.println("woops");
+ }
}
public Map<String, String> testFPWOCReturn()
@@ -23,6 +27,7 @@
Map<String, String> m = new HashMap<String, String>();
m.put("Foo", "Bar");
memberSet.add("fi");
+ fpSet = new HashSet<String>();
return m;
}
@@ -31,6 +36,7 @@
Map<String, String> m = new HashMap<String, String>();
m.put("Foo", "Bar");
memberSet.add("fo");
+ fpSet.add("boo");
helper(0, m);
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 21:34:19 UTC (rev 1552)
@@ -19,20 +19,24 @@
package com.mebigfatguy.fbcontrib.detect;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
-import org.apache.bcel.Constants;
import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.Field;
import org.apache.bcel.generic.Type;
import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
@@ -41,7 +45,6 @@
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
-import edu.umd.cs.findbugs.OpcodeStack.Item;
import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XField;
@@ -50,6 +53,12 @@
private static Set<String> collectionClasses = new HashSet<String>();
static
{
+ collectionClasses.add(Set.class.getName());
+ collectionClasses.add(Map.class.getName());
+ collectionClasses.add(List.class.getName());
+ collectionClasses.add(SortedSet.class.getName());
+ collectionClasses.add(SortedMap.class.getName());
+ collectionClasses.add(Collection.class.getName());
collectionClasses.add(HashSet.class.getName());
collectionClasses.add(TreeSet.class.getName());
collectionClasses.add(LinkedHashSet.class.getName());
@@ -91,8 +100,8 @@
private OpcodeStack stack;
/** register to first allocation PC */
private Map<Integer, Integer> localWOCollections;
- /** field to first allocation PC */
- private Map<String, Integer> fieldWOCollections;
+ /** fieldname to field sig */
+ private Map<String, String> fieldWOCollections;
/**
@@ -112,13 +121,18 @@
try {
stack = new OpcodeStack();
localWOCollections = new HashMap<Integer, Integer>();
- fieldWOCollections = new HashMap<String, Integer>();
+ fieldWOCollections = new HashMap<String, String>();
super.visitClassContext(classContext);
- for (Integer pc : fieldWOCollections.values()) {
- bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
- .addClass(this)
- .addSourceLine(this, pc.intValue()));
+ if (fieldWOCollections.size() > 0) {
+ String clsName = classContext.getJavaClass().getClassName();
+ for (Map.Entry<String, String> entry : fieldWOCollections.entrySet()) {
+ String fieldName = entry.getKey();
+ String signature = entry.getValue();
+ bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION_FIELD", NORMAL_PRIORITY)
+ .addClass(this)
+ .addField(clsName, fieldName, signature, false));
+ }
}
} finally {
stack = null;
@@ -126,6 +140,19 @@
fieldWOCollections = null;
}
}
+
+ @Override
+ public void visitField(Field obj) {
+ if (obj.isPrivate()) {
+ String sig = obj.getSignature();
+ if (sig.startsWith("L")) {
+ String type = sig.substring(1, sig.length() - 1).replace('/', '.');
+ if (collectionClasses.contains(type)) {
+ fieldWOCollections.put(obj.getName(), obj.getSignature());
+ }
+ }
+ }
+ }
/**
* overrides the visitor reset the stack
@@ -139,8 +166,7 @@
super.visitCode(obj);
for (Integer pc : localWOCollections.values()) {
- bugReporter.reportBug(new BugInstance(this,
-"WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
+ bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION_LOCAL", NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
.addSourceLine(this, pc.intValue()));
@@ -246,20 +272,8 @@
if (stack.getStackDepth() > 1) {
OpcodeStack.Item item = stack.getStackItem(0);
Object uo = item.getUserValue();
- if (uo != null) {
- if (uo instanceof Boolean) {
- Item fieldItem = stack.getStackItem(1);
- boolean storedInThis = fieldItem.getRegisterNumber() == 0;
- if (storedInThis) {
- XField field = getXFieldOperand();
- if ((field.getAccessFlags() & Constants.ACC_PRIVATE) != 0) {
- String fieldName = field.getName();
- fieldWOCollections.put(fieldName, getPC());
- }
- }
- } else {
- clearUserValue(item);
- }
+ if (!(uo instanceof Boolean)) {
+ clearUserValue(item);
}
}
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 04:30:21
|
Revision: 1551
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1551&view=rev
Author: dbrosius
Date: 2010-05-08 04:30:13 +0000 (Sat, 08 May 2010)
Log Message:
-----------
add check for code that does IINC in MRC
Modified Paths:
--------------
trunk/fb-contrib/samples/MRC_Sample.java
Modified: trunk/fb-contrib/samples/MRC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/MRC_Sample.java 2010-05-08 04:24:49 UTC (rev 1550)
+++ trunk/fb-contrib/samples/MRC_Sample.java 2010-05-08 04:30:13 UTC (rev 1551)
@@ -69,4 +69,11 @@
return count;
}
+
+ private int fpInc()
+ {
+ int i = 0;
+ i++;
+ return i;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 04:24:55
|
Revision: 1550
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1550&view=rev
Author: dbrosius
Date: 2010-05-08 04:24:49 +0000 (Sat, 08 May 2010)
Log Message:
-----------
PCAIL
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java 2010-05-08 04:18:29 UTC (rev 1549)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java 2010-05-08 04:24:49 UTC (rev 1550)
@@ -186,7 +186,7 @@
allocations.remove(allocation);
storedAllocations.remove(reg);
} else {
- sawAllocationNumber = allocation.intValue();
+ sawAllocationNumber = allocation;
sawAllocation = true;
}
}
@@ -217,7 +217,7 @@
if (sawAllocation) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
- item.setUserValue(Integer.valueOf(sawAllocationNumber));
+ item.setUserValue(sawAllocationNumber);
}
if (seen == INVOKESPECIAL)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 04:18:36
|
Revision: 1549
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1549&view=rev
Author: dbrosius
Date: 2010-05-08 04:18:29 +0000 (Sat, 08 May 2010)
Log Message:
-----------
report field WOC -- altho probably not as likely to catch as the allocation has to preceed the other uses.
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 04:17:41 UTC (rev 1548)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 04:18:29 UTC (rev 1549)
@@ -1,17 +1,17 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* Copyright (C) 2005-2010 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
@@ -52,16 +52,16 @@
{
collectionClasses.add(HashSet.class.getName());
collectionClasses.add(TreeSet.class.getName());
- collectionClasses.add(LinkedHashSet.class.getName());
+ collectionClasses.add(LinkedHashSet.class.getName());
collectionClasses.add(HashMap.class.getName());
collectionClasses.add(TreeMap.class.getName());
collectionClasses.add(Hashtable.class.getName());
- collectionClasses.add(LinkedHashMap.class.getName());
+ collectionClasses.add(LinkedHashMap.class.getName());
collectionClasses.add(Vector.class.getName());
collectionClasses.add(ArrayList.class.getName());
collectionClasses.add(LinkedList.class.getName());
}
-
+
private static Set<String> writeMethods = new HashSet<String>();
static
{
@@ -86,15 +86,15 @@
writeMethods.add("setSize");
writeMethods.add("trimToSize");
}
-
- private BugReporter bugReporter;
+
+ private final BugReporter bugReporter;
private OpcodeStack stack;
/** register to first allocation PC */
private Map<Integer, Integer> localWOCollections;
/** field to first allocation PC */
private Map<String, Integer> fieldWOCollections;
-
-
+
+
/**
* constructs a WOC detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
@@ -104,7 +104,7 @@
}
/**
* overrides the visitor to initialize and tear down the opcode stack
- *
+ *
* @param classContext the context object of the currently parsed class
*/
@Override
@@ -114,16 +114,22 @@
localWOCollections = new HashMap<Integer, Integer>();
fieldWOCollections = new HashMap<String, Integer>();
super.visitClassContext(classContext);
+
+ for (Integer pc : fieldWOCollections.values()) {
+ bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
+ .addClass(this)
+ .addSourceLine(this, pc.intValue()));
+ }
} finally {
stack = null;
localWOCollections = null;
fieldWOCollections = null;
}
}
-
+
/**
* overrides the visitor reset the stack
- *
+ *
* @param obj the context object of the currently parsed code block
*/
@Override
@@ -131,25 +137,27 @@
stack.resetForMethodEntry(this);
localWOCollections.clear();
super.visitCode(obj);
-
+
for (Integer pc : localWOCollections.values()) {
- bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
+ bugReporter.reportBug(new BugInstance(this,
+"WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
.addSourceLine(this, pc.intValue()));
}
}
-
+
/**
- * overrides the visitor to look for uses of collections where the only access to
+ * overrides the visitor to look for uses of collections where the only
+access to
* to the collection is to write to it
- *
+ *
* @param seen the opcode of the currently visited instruction
*/
@Override
public void sawOpcode(int seen) {
Object userObject = null;
-
+
try {
switch (seen) {
case INVOKESPECIAL:
@@ -157,11 +165,13 @@
if ("<init>".equals(methodName)) {
String clsName = getClassConstantOperand().replace('/', '.');
if (collectionClasses.contains(clsName))
- userObject = Boolean.TRUE;
+ {
+ userObject = Boolean.TRUE;
+ }
}
processMethodParms();
break;
-
+
case INVOKEINTERFACE:
case INVOKEVIRTUAL:
String sig = getSigConstantOperand();
@@ -173,23 +183,28 @@
String name = getNameConstantOperand();
if (!writeMethods.contains(name)) {
clearUserValue(item);
+ } else if (!"clone".equals(name)) {
+ Type t = Type.getReturnType(sig);
+ if ((t != Type.VOID) && (getNextOpcode() != POP)) {
+ clearUserValue(item);
+ }
}
}
}
processMethodParms();
break;
-
+
case INVOKESTATIC:
processMethodParms();
break;
-
+
case ARETURN:
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
clearUserValue(item);
}
break;
-
+
case ASTORE_0:
case ASTORE_1:
case ASTORE_2:
@@ -208,7 +223,7 @@
}
}
break;
-
+
case ALOAD_0:
case ALOAD_1:
case ALOAD_2:
@@ -219,7 +234,14 @@
userObject = Integer.valueOf(reg);
}
break;
-
+
+ case AASTORE:
+ if (stack.getStackDepth() >= 3) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ clearUserValue(item);
+ }
+ break;
+
case PUTFIELD:
if (stack.getStackDepth() > 1) {
OpcodeStack.Item item = stack.getStackItem(0);
@@ -228,7 +250,7 @@
if (uo instanceof Boolean) {
Item fieldItem = stack.getStackItem(1);
boolean storedInThis = fieldItem.getRegisterNumber() == 0;
- if (storedInThis) {
+ if (storedInThis) {
XField field = getXFieldOperand();
if ((field.getAccessFlags() & Constants.ACC_PRIVATE) != 0) {
String fieldName = field.getName();
@@ -241,7 +263,7 @@
}
}
break;
-
+
case GETFIELD:
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
@@ -265,7 +287,7 @@
}
}
}
-
+
private void clearUserValue(OpcodeStack.Item item) {
Object uo = item.getUserValue();
if (uo instanceof Integer) {
@@ -275,7 +297,7 @@
}
item.setUserValue(null);
}
-
+
private void processMethodParms() {
String sig = getSigConstantOperand();
int numParms = Type.getArgumentTypes(sig).length;
@@ -286,3 +308,5 @@
}
}
}
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 04:17:47
|
Revision: 1548
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1548&view=rev
Author: dbrosius
Date: 2010-05-08 04:17:41 +0000 (Sat, 08 May 2010)
Log Message:
-----------
add test for field collections
Modified Paths:
--------------
trunk/fb-contrib/samples/WOC_Sample.java
Modified: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 04:05:14 UTC (rev 1547)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 04:17:41 UTC (rev 1548)
@@ -9,16 +9,20 @@
public class WOC_Sample
{
+ private Set<String> memberSet = new HashSet<String>();
+
public void testWOCSimple()
{
Set<String> s = new HashSet<String>();
- s.add("Foo");
+ s.add("Foo");
+ memberSet.add("fee");
}
public Map<String, String> testFPWOCReturn()
{
Map<String, String> m = new HashMap<String, String>();
m.put("Foo", "Bar");
+ memberSet.add("fi");
return m;
}
@@ -26,6 +30,7 @@
{
Map<String, String> m = new HashMap<String, String>();
m.put("Foo", "Bar");
+ memberSet.add("fo");
helper(0, m);
}
@@ -34,6 +39,7 @@
Set<String> s = new LinkedHashSet<String>();
s.add("foo");
Set<String> c = s;
+ memberSet.add("fum");
}
public void testFPWOCInArray()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 04:05:20
|
Revision: 1547
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1547&view=rev
Author: dbrosius
Date: 2010-05-08 04:05:14 +0000 (Sat, 08 May 2010)
Log Message:
-----------
add a test for when a 'write' method returns a value that is looked at
Modified Paths:
--------------
trunk/fb-contrib/samples/WOC_Sample.java
Modified: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 01:06:00 UTC (rev 1546)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 04:05:14 UTC (rev 1547)
@@ -1,6 +1,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
@@ -42,6 +43,18 @@
Object[] o = new Object[] { v };
}
+ public void testFPWOCUseReturnVal()
+ {
+ LinkedList<String> l = new LinkedList<String>();
+ l.add("Foo");
+ l.add("Bar");
+
+ if (l.remove("Foo"))
+ {
+ System.out.println("Dont' report");
+ }
+ }
+
private void helper(int i, Map<String, String> x)
{
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 01:06:07
|
Revision: 1546
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1546&view=rev
Author: dbrosius
Date: 2010-05-08 01:06:00 +0000 (Sat, 08 May 2010)
Log Message:
-----------
add another fp with putting a WOC into an array element
Modified Paths:
--------------
trunk/fb-contrib/samples/WOC_Sample.java
Modified: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java 2010-05-07 08:30:28 UTC (rev 1545)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 01:06:00 UTC (rev 1546)
@@ -3,6 +3,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+import java.util.Vector;
public class WOC_Sample
@@ -34,6 +35,13 @@
Set<String> c = s;
}
+ public void testFPWOCInArray()
+ {
+ Vector<Integer> v = new Vector<Integer>();
+ v.addElement(Integer.valueOf(0));
+ Object[] o = new Object[] { v };
+ }
+
private void helper(int i, Map<String, String> x)
{
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-07 08:30:34
|
Revision: 1545
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1545&view=rev
Author: dbrosius
Date: 2010-05-07 08:30:28 +0000 (Fri, 07 May 2010)
Log Message:
-----------
initial checkin, new WOC detector
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/WOC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-04-24 01:53:11 UTC (rev 1544)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-05-07 08:30:28 UTC (rev 1545)
@@ -331,6 +331,10 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop"
speed="fast"
reports="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection"
+ speed="fast"
+ reports="WOC_WRITE_ONLY_COLLECTION" />
<!-- BugPattern -->
@@ -627,4 +631,6 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="PCAIL" type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP"
category="PERFORMANCE" experimental="true" />
+ <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION"
+ category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-04-24 01:53:11 UTC (rev 1544)
+++ trunk/fb-contrib/etc/messages.xml 2010-05-07 08:30:28 UTC (rev 1545)
@@ -1134,6 +1134,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for allocations and initializations of java collections, but that are never
+ read from or accessed to gain information. This represents a collection of no use, and most probably
+ can be removed. It is similar to a dead local store.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -3107,6 +3118,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="WOC_WRITE_ONLY_COLLECTION">
+ <ShortDescription>Method creates and initializes a collection but never reads or gains information from it</ShortDescription>
+ <LongDescription>Method {1} creates and initializes a collection but never reads or gains information from it</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates and initializes a collection but then never access this collection
+ to gain information, or fetch items from the collection. It is likely that this collection
+ is left over from a past effort, and can be removed.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3203,4 +3226,5 @@
<BugCode abbrev="ROOM">Reflection on Object Methods</BugCode>
<BugCode abbrev="IPU">Improper Properties use</BugCode>
<BugCode abbrev="PCAIL">Possible Constant Allocation In Loop</BugCode>
+ <BugCode abbrev="WOC">Write Only Collection</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2010-05-07 08:30:28 UTC (rev 1545)
@@ -0,0 +1,40 @@
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public class WOC_Sample
+{
+ public void testWOCSimple()
+ {
+ Set<String> s = new HashSet<String>();
+ s.add("Foo");
+ }
+
+ public Map<String, String> testFPWOCReturn()
+ {
+ Map<String, String> m = new HashMap<String, String>();
+ m.put("Foo", "Bar");
+ return m;
+ }
+
+ public void testFPWOCAsParm()
+ {
+ Map<String, String> m = new HashMap<String, String>();
+ m.put("Foo", "Bar");
+ helper(0, m);
+ }
+
+ public void testFPWOCCopy()
+ {
+ Set<String> s = new LinkedHashSet<String>();
+ s.add("foo");
+ Set<String> c = s;
+ }
+
+ private void helper(int i, Map<String, String> x)
+ {
+ }
+}
Property changes on: trunk/fb-contrib/samples/WOC_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-07 08:30:28 UTC (rev 1545)
@@ -0,0 +1,288 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.generic.Type;
+
+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.OpcodeStack.Item;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.ba.XField;
+
+public class WriteOnlyCollection extends BytecodeScanningDetector {
+
+ private static Set<String> collectionClasses = new HashSet<String>();
+ static
+ {
+ collectionClasses.add(HashSet.class.getName());
+ collectionClasses.add(TreeSet.class.getName());
+ collectionClasses.add(LinkedHashSet.class.getName());
+ collectionClasses.add(HashMap.class.getName());
+ collectionClasses.add(TreeMap.class.getName());
+ collectionClasses.add(Hashtable.class.getName());
+ collectionClasses.add(LinkedHashMap.class.getName());
+ collectionClasses.add(Vector.class.getName());
+ collectionClasses.add(ArrayList.class.getName());
+ collectionClasses.add(LinkedList.class.getName());
+ }
+
+ private static Set<String> writeMethods = new HashSet<String>();
+ static
+ {
+ writeMethods.add("add");
+ writeMethods.add("addAll");
+ writeMethods.add("addElement");
+ writeMethods.add("addFirst");
+ writeMethods.add("addLast");
+ writeMethods.add("clear");
+ writeMethods.add("clone");
+ writeMethods.add("ensureCapacity");
+ writeMethods.add("insertElementAt");
+ writeMethods.add("put");
+ writeMethods.add("putAll");
+ writeMethods.add("remove");
+ writeMethods.add("removeAll");
+ writeMethods.add("removeElement");
+ writeMethods.add("removeElementAt");
+ writeMethods.add("removeRange");
+ writeMethods.add("set");
+ writeMethods.add("setElementAt");
+ writeMethods.add("setSize");
+ writeMethods.add("trimToSize");
+ }
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ /** register to first allocation PC */
+ private Map<Integer, Integer> localWOCollections;
+ /** field to first allocation PC */
+ private Map<String, Integer> fieldWOCollections;
+
+
+ /**
+ * constructs a WOC detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public WriteOnlyCollection(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+ /**
+ * overrides the visitor to initialize and tear down the opcode stack
+ *
+ * @param classContext the context object of the currently parsed class
+ */
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ localWOCollections = new HashMap<Integer, Integer>();
+ fieldWOCollections = new HashMap<String, Integer>();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ localWOCollections = null;
+ fieldWOCollections = null;
+ }
+ }
+
+ /**
+ * overrides the visitor reset the stack
+ *
+ * @param obj the context object of the currently parsed code block
+ */
+ @Override
+ public void visitCode(Code obj) {
+ stack.resetForMethodEntry(this);
+ localWOCollections.clear();
+ super.visitCode(obj);
+
+ for (Integer pc : localWOCollections.values()) {
+ bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this, pc.intValue()));
+ }
+ }
+
+ /**
+ * overrides the visitor to look for uses of collections where the only access to
+ * to the collection is to write to it
+ *
+ * @param seen the opcode of the currently visited instruction
+ */
+ @Override
+ public void sawOpcode(int seen) {
+ Object userObject = null;
+
+ try {
+ switch (seen) {
+ case INVOKESPECIAL:
+ String methodName = getNameConstantOperand();
+ if ("<init>".equals(methodName)) {
+ String clsName = getClassConstantOperand().replace('/', '.');
+ if (collectionClasses.contains(clsName))
+ userObject = Boolean.TRUE;
+ }
+ processMethodParms();
+ break;
+
+ case INVOKEINTERFACE:
+ case INVOKEVIRTUAL:
+ String sig = getSigConstantOperand();
+ int numParms = Type.getArgumentTypes(sig).length;
+ if (stack.getStackDepth() > numParms) {
+ OpcodeStack.Item item = stack.getStackItem(numParms);
+ Object uo = item.getUserValue();
+ if (uo != null) {
+ String name = getNameConstantOperand();
+ if (!writeMethods.contains(name)) {
+ clearUserValue(item);
+ }
+ }
+ }
+ processMethodParms();
+ break;
+
+ case INVOKESTATIC:
+ processMethodParms();
+ break;
+
+ case ARETURN:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ clearUserValue(item);
+ }
+ break;
+
+ case ASTORE_0:
+ case ASTORE_1:
+ case ASTORE_2:
+ case ASTORE_3:
+ case ASTORE:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ Object uo = item.getUserValue();
+ if (uo != null) {
+ if (uo instanceof Boolean) {
+ int reg = RegisterUtils.getAStoreReg(this, seen);
+ localWOCollections.put(reg, Integer.valueOf(getPC()));
+ } else {
+ clearUserValue(item);
+ }
+ }
+ }
+ break;
+
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3:
+ case ALOAD:
+ int reg = RegisterUtils.getALoadReg(this, seen);
+ if (localWOCollections.containsKey(Integer.valueOf(reg))) {
+ userObject = Integer.valueOf(reg);
+ }
+ break;
+
+ case PUTFIELD:
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ Object uo = item.getUserValue();
+ if (uo != null) {
+ if (uo instanceof Boolean) {
+ Item fieldItem = stack.getStackItem(1);
+ boolean storedInThis = fieldItem.getRegisterNumber() == 0;
+ if (storedInThis) {
+ XField field = getXFieldOperand();
+ if ((field.getAccessFlags() & Constants.ACC_PRIVATE) != 0) {
+ String fieldName = field.getName();
+ fieldWOCollections.put(fieldName, getPC());
+ }
+ }
+ } else {
+ clearUserValue(item);
+ }
+ }
+ }
+ break;
+
+ case GETFIELD:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (item.getRegisterNumber() == 0) {
+ XField field = getXFieldOperand();
+ String fieldName = field.getName();
+ if (fieldWOCollections.containsKey(fieldName)) {
+ userObject = fieldName;
+ }
+ }
+ }
+ break;
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (userObject != null) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(userObject);
+ }
+ }
+ }
+ }
+
+ private void clearUserValue(OpcodeStack.Item item) {
+ Object uo = item.getUserValue();
+ if (uo instanceof Integer) {
+ localWOCollections.remove(uo);
+ } else if (uo instanceof String) {
+ fieldWOCollections.remove(uo);
+ }
+ item.setUserValue(null);
+ }
+
+ private void processMethodParms() {
+ String sig = getSigConstantOperand();
+ int numParms = Type.getArgumentTypes(sig).length;
+ if (stack.getStackDepth() >= numParms) {
+ for (int i = 0; i < numParms; i++) {
+ clearUserValue(stack.getStackItem(i));
+ }
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-04-24 01:53:17
|
Revision: 1544
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1544&view=rev
Author: dbrosius
Date: 2010-04-24 01:53:11 +0000 (Sat, 24 Apr 2010)
Log Message:
-----------
typo s/b java/awt/Component
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-04-04 16:34:42 UTC (rev 1543)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-04-24 01:53:11 UTC (rev 1544)
@@ -60,7 +60,7 @@
clsNFException = cnfe;
}
try {
- componentClass = Repository.lookupClass("javax/awt/Component");
+ componentClass = Repository.lookupClass("java/awt/Component");
} catch (ClassNotFoundException cnfe) {
componentClass = null;
clsNFException = cnfe;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-04-04 16:34:48
|
Revision: 1543
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1543&view=rev
Author: dbrosius
Date: 2010-04-04 16:34:42 +0000 (Sun, 04 Apr 2010)
Log Message:
-----------
add check for calling java.lang.reflect.Array methods on non arrays
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-04-04 16:34:08 UTC (rev 1542)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-04-04 16:34:42 UTC (rev 1543)
@@ -399,6 +399,28 @@
}
}
}
+ } else if ("java/lang/reflect/Array".equals(className)) {
+ int offset = -1;
+ if ("getLength".equals(methodName)) {
+ offset = 0;
+ } else if (methodName.startsWith("get")) {
+ offset = 1;
+ } else if (methodName.startsWith("set")) {
+ offset = 2;
+ }
+ if (offset >= 0) {
+ if (stack.getStackDepth() > offset) {
+ OpcodeStack.Item item = stack.getStackItem(offset);
+ String sig = item.getSignature();
+ if ((sig.charAt(0) != '[') && !"Ljava/lang/Object;".equals(sig)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_NON_ARRAY_PARM", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+
}
} else if (seen == INVOKEVIRTUAL) {
String className = getClassConstantOperand();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-04-04 16:34:15
|
Revision: 1542
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1542&view=rev
Author: dbrosius
Date: 2010-04-04 16:34:08 +0000 (Sun, 04 Apr 2010)
Log Message:
-----------
add test case for calling java.lang.reflect.Array methods on non arrays
Modified Paths:
--------------
trunk/fb-contrib/samples/SPP_Sample.java
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2010-04-04 08:40:57 UTC (rev 1541)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2010-04-04 16:34:08 UTC (rev 1542)
@@ -1,5 +1,7 @@
import java.io.Serializable;
+import java.lang.reflect.Array;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Date;
@@ -301,4 +303,15 @@
System.arraycopy(copy, 0, input, 0, copy.length);
}
+
+ public void testArray()
+ {
+ List<String> notAnArray = new ArrayList<String>();
+
+ Array.getLength(notAnArray);
+
+ Array.getBoolean(notAnArray, 0);
+
+ Array.setInt(notAnArray, 0, 1);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-04-04 08:41:04
|
Revision: 1541
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1541&view=rev
Author: dbrosius
Date: 2010-04-04 08:40:57 +0000 (Sun, 04 Apr 2010)
Log Message:
-----------
don't report when two allocations are stored in the same reg
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java 2010-04-04 08:27:25 UTC (rev 1540)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java 2010-04-04 08:40:57 UTC (rev 1541)
@@ -152,6 +152,10 @@
if (storedAllocations.values().contains(allocation)) {
allocations.remove(allocation);
storedAllocations.remove(reg);
+ } else if (storedAllocations.containsKey(reg)) {
+ allocations.remove(allocation);
+ allocation = storedAllocations.remove(reg);
+ allocations.remove(allocation);
} else {
storedAllocations.put(reg, allocation);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|