[Fb-contrib-commit] SF.net SVN: fb-contrib:[1767] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2014-03-18 05:52:27
|
Revision: 1767
http://sourceforge.net/p/fb-contrib/code/1767
Author: dbrosius
Date: 2014-03-18 05:52:22 +0000 (Tue, 18 Mar 2014)
Log Message:
-----------
sync from github
Modified Paths:
--------------
trunk/fb-contrib/.classpath
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/htdocs/repository.html
trunk/fb-contrib/plugin.xml
trunk/fb-contrib/pom.xml
trunk/fb-contrib/samples/LO_Sample.java
trunk/fb-contrib/samples/samples.fbp
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeclaredRuntimeException.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorMansEnum.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnusedParameter.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/AttributesUtils.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/CodeByteUtils.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/RegisterUtils.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/TernaryPatcher.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/XClassUtils.java
trunk/fb-contrib/yank.xls
Added Paths:
-----------
trunk/fb-contrib/samples/CD_Sample.java
trunk/fb-contrib/samples/MUC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/ImmutabilityType.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/MethodInfo.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CircularDependencies.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ModifyingUnmodifiableCollection.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/CollectionUtils.java
Removed Paths:
-------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/MapEntry.java
Modified: trunk/fb-contrib/.classpath
===================================================================
--- trunk/fb-contrib/.classpath 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/.classpath 2014-03-18 05:52:22 UTC (rev 1767)
@@ -12,11 +12,11 @@
<classpathentry kind="lib" path="lib/javax.servlet-api-3.1.0.jar"/>
<classpathentry kind="lib" path="lib/junit-4.11.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
- <classpathentry kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
- <classpathentry kind="lib" path="lib/findbugs-2.0.3.jar"/>
- <classpathentry kind="lib" path="lib/guava-15.0.jar"/>
+ <classpathentry kind="lib" path="lib/findbugs-2.0.3.jar" sourcepath="/home/dave/.m2/repository/com/google/code/findbugs/findbugs/2.0.3/findbugs-2.0.3-sources.jar"/>
<classpathentry kind="lib" path="lib/annotations-2.0.3.jar"/>
- <classpathentry kind="lib" path="lib/commons-lang3-3.2.jar"/>
<classpathentry kind="lib" path="lib/javax.servlet.jsp-api-2.3.1.jar"/>
+ <classpathentry kind="lib" path="lib/guava-16.0.1.jar" sourcepath="lib/guava-16.0.1-sources.jar"/>
+ <classpathentry kind="lib" path="lib/commons-lang3-3.3.jar"/>
+ <classpathentry kind="lib" path="lib/slf4j-api-1.7.6.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/build.xml 2014-03-18 05:52:22 UTC (rev 1767)
@@ -18,7 +18,7 @@
<property name="javac.deprecation" value="on" />
<property name="javac.debug" value="on" />
- <property name="fb-contrib.version" value="5.0.3" />
+ <property name="fb-contrib.version" value="5.2.0" />
<property name="sonatype.dir" value="${user.home}/.fb-contrib-${fb-contrib.version}-sonatype" />
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/etc/findbugs.xml 2014-03-18 05:52:22 UTC (rev 1767)
@@ -11,11 +11,16 @@
<Earlier class="com.mebigfatguy.fbcontrib.collect.CollectStatistics" />
<LaterCategory name="reporting" spanplugins="true" />
</SplitPass>
+ <SplitPass>
+ <Earlier class="com.mebigfatguy.fbcontrib.collect.CollectMethodsReturningImmutableCollections" />
+ <LaterCategory name="reporting" spanplugins="true" />
+ </SplitPass>
+
</OrderingConstraints>
<!-- Detectors -->
-<!-- COMMENT OUT FOR RELEASE
+<!-- COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger" speed="fast"/>
@@ -25,13 +30,11 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.StutteredMethodArguments" speed="fast" reports="SMA_STUTTERED_METHOD_ARGUMENTS" hidden="true" />
- <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.StackedTryBlocks" speed="fast" reports="STB_STACKED_TRY_BLOCKS" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.collect.CollectStatistics" speed="fast" reports="" hidden="true" />
@@ -177,7 +180,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousClusteredSessionSupport" speed="fast" reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.LoggerOddities" speed="fast" reports="LO_LOGGER_LOST_EXCEPTION_STACK_TRACE,LO_SUSPECT_LOG_CLASS,LO_SUSPECT_LOG_PARAMETER,LO_STUTTERED_MESSAGE,LO_INVALID_FORMATTING_ANCHOR,LO_INCORRECT_NUMBER_OF_ANCHOR_PARAMETERS,LO_EXCEPTION_WITH_LOGGER_PARMS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.LoggerOddities" speed="fast" reports="LO_LOGGER_LOST_EXCEPTION_STACK_TRACE,LO_SUSPECT_LOG_CLASS,LO_SUSPECT_LOG_PARAMETER,LO_STUTTERED_MESSAGE,LO_INVALID_FORMATTING_ANCHOR,LO_INCORRECT_NUMBER_OF_ANCHOR_PARAMETERS,LO_EXCEPTION_WITH_LOGGER_PARMS,LO_APPENDED_STRING_IN_FORMAT_STRING" />
<Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse" speed="fast" reports="IICU_INCORRECT_INTERNAL_CLASS_USE" />
@@ -248,19 +251,27 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.InvalidConstantArgument" speed="fast" reports="ICA_INVALID_CONSTANT_ARRAY" />
- <!-- COMMENT OUT FOR POINT RELEASE
- <Detector class="com.mebigfatguy.fbcontrib.detect.PresizeCollections" speed="fast" reports="PSC_PRESIZE_COLLECTIONS" />
+ <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.ArrayIndexOutOfBounds" speed="fast" reports="AIOB_ARRAY_INDEX_OUT_OF_BOUNDS,AIOB_ARRAY_STORE_TO_NULL_REFERENCE" />
-
<Detector class="com.mebigfatguy.fbcontrib.detect.CollectionNamingConfusion" speed="fast" reports="CNC_COLLECTION_NAMING_CONFUSION" />
<Detector class="com.mebigfatguy.fbcontrib.detect.PoorMansEnum" speed="fast" reports="PME_POOR_MANS_ENUM" />
<Detector class="com.mebigfatguy.fbcontrib.detect.UnusedParameter" speed="fast" reports="UP_UNUSED_PARAMETER" />
- COMMENT OUT FOR POINT RELEASE -->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CircularDependencies" speed="moderate" reports="CD_CIRCULAR_DEPENDENCY"/>
+
+ <Detector class="com.mebigfatguy.fbcontrib.collect.CollectMethodsReturningImmutableCollections" speed="fast" reports="" hidden="true" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ModifyingUnmodifiableCollection" speed="fast" reports="MUC_MODIFYING_UNMODIFIABLE_COLLECTION"/>
+
+ <!-- COMMENT OUT FOR POINT RELEASE -->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PresizeCollections" speed="fast" reports="PSC_PRESIZE_COLLECTIONS" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ArrayIndexOutOfBounds" speed="fast" reports="AIOB_ARRAY_INDEX_OUT_OF_BOUNDS,AIOB_ARRAY_STORE_TO_NULL_REFERENCE" />
+
+ <!-- COMMENT OUT FOR POINT RELEASE -->
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -396,6 +407,7 @@
<BugPattern abbrev="LO" type="LO_INVALID_FORMATTING_ANCHOR" category="CORRECTNESS" />
<BugPattern abbrev="LO" type="LO_INCORRECT_NUMBER_OF_ANCHOR_PARAMETERS" category="CORRECTNESS" />
<BugPattern abbrev="LO" type="LO_EXCEPTION_WITH_LOGGER_PARMS" category="CORRECTNESS" />
+ <BugPattern abbrev="LO" type="LO_APPENDED_STRING_IN_FORMAT_STRING" category="PERFORMANCE" />
<BugPattern abbrev="IICU" type="IICU_INCORRECT_INTERNAL_CLASS_USE" category="CORRECTNESS" />
<BugPattern abbrev="DSOC" type="DSOC_DUBIOUS_SET_OF_COLLECTIONS" category="PERFORMANCE" />
<BugPattern abbrev="BED" type="BED_BOGUS_EXCEPTION_DECLARATION" category="CORRECTNESS" />
@@ -410,11 +422,11 @@
<BugPattern abbrev="OC" type="OC_OVERZEALOUS_CASTING" category="CORRECTNESS" />
<BugPattern abbrev="PDP" type="PDP_POORLY_DEFINED_PARAMETER" category="CORRECTNESS" />
<BugPattern abbrev="NSE" type="NSE_NON_SYMMETRIC_EQUALS" category="CORRECTNESS" />
- <BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT" category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT" category="CORRECTNESS" />
+ <BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" category="CORRECTNESS" />
<BugPattern abbrev="NFF" type="NFF_NON_FUNCTIONAL_FIELD" category="CORRECTNESS" />
- <BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_FIELD_GUARD" category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_LOCAL_GUARD" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_FIELD_GUARD" category="CORRECTNESS" />
+ <BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_LOCAL_GUARD" category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_RUNTIME_EXIT_OR_HALT" category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_RUNFINALIZATION" category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_INETADDRESS_GETLOCALHOST" category="CORRECTNESS" />
@@ -437,10 +449,10 @@
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_LOCAL" category="CORRECTNESS" />
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_FIELD" category="CORRECTNESS" />
<BugPattern abbrev="UVA" type="UVA_USE_VAR_ARGS" category="STYLE" />
- <BugPattern abbrev="PUS" type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="SEC" type="SEC_SIDE_EFFECT_CONSTRUCTOR" category="STYLE" experimental="true" />
- <BugPattern abbrev="SGSU" type="SGSU_SUSPICIOUS_GETTER_SETTER_USE" category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="LGO" type="LGO_LINGERING_GRAPHICS_OBJECT" category="PERFORMANCE" experimental="true" />
+ <BugPattern abbrev="PUS" type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" category="CORRECTNESS" />
+ <BugPattern abbrev="SEC" type="SEC_SIDE_EFFECT_CONSTRUCTOR" category="STYLE" />
+ <BugPattern abbrev="SGSU" type="SGSU_SUSPICIOUS_GETTER_SETTER_USE" category="CORRECTNESS" />
+ <BugPattern abbrev="LGO" type="LGO_LINGERING_GRAPHICS_OBJECT" category="PERFORMANCE" />
<BugPattern abbrev="STB" type="STB_STACKED_TRY_BLOCKS" category="STYLE" experimental="true" />
<BugPattern abbrev="CEBE" type="CEBE_COMMONS_EQUALS_BUILDER_ISEQUALS" category="CORRECTNESS" />
<BugPattern abbrev="CHTH" type="CHTH_COMMONS_HASHCODE_BUILDER_TOHASHCODE" category="CORRECTNESS" />
@@ -454,10 +466,12 @@
<BugPattern abbrev="PSC" type="PSC_PRESIZE_COLLECTIONS" category="PERFORMANCE" />
<BugPattern abbrev="UMTP" type="UMTP_UNBOUND_METHOD_TEMPLATE_PARAMETER" category="CORRECTNESS" />
<BugPattern abbrev="NPMC" type="NPMC_NON_PRODUCTIVE_METHOD_CALL" category="CORRECTNESS" />
- <BugPattern abbrev="AIOB" type="AIOB_ARRAY_INDEX_OUT_OF_BOUNDS" category="CORRECTNESS" />
- <BugPattern abbrev="AIOB" type="AIOB_ARRAY_STORE_TO_NULL_REFERENCE" category="CORRECTNESS" />
- <BugPattern abbrev="ICA" type="ICA_INVALID_CONSTANT_ARGUMENT" category="CORRECTNESS" />
- <BugPattern abbrev="CNC" type="CNC_COLLECTION_NAMING_CONFUSION" category="STYLE" />
- <BugPattern abbrev="PME" type="PME_POOR_MANS_ENUM" category="STYLE" />
- <BugPattern abbrev="UP" type="UP_UNUSED_PARAMETER" category="STYLE" />
+ <BugPattern abbrev="AIOB" type="AIOB_ARRAY_INDEX_OUT_OF_BOUNDS" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="AIOB" type="AIOB_ARRAY_STORE_TO_NULL_REFERENCE" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="ICA" type="ICA_INVALID_CONSTANT_ARGUMENT" category="CORRECTNESS" />
+ <BugPattern abbrev="CNC" type="CNC_COLLECTION_NAMING_CONFUSION" category="STYLE" experimental="true" />
+ <BugPattern abbrev="PME" type="PME_POOR_MANS_ENUM" category="STYLE" experimental="true" />
+ <BugPattern abbrev="UP" type="UP_UNUSED_PARAMETER" category="STYLE" experimental="true" />
+ <BugPattern abbrev="CD" type="CD_CIRCULAR_DEPENDENCY" category="CORRECTNESS" />
+ <BugPattern abbrev="MUC" type="MUC_MODIFYING_UNMODIFIABLE_COLLECTION" category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/etc/messages.xml 2014-03-18 05:52:22 UTC (rev 1767)
@@ -20,6 +20,14 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.collect.CollectMethodsReturningImmutableCollections">
+ <Details>
+ <![CDATA[
+ <p>Collects method calls that may return immutable collections</p>
+ ]]>
+ </Details>
+ </Detector>
<Detector class="com.mebigfatguy.fbcontrib.detect.InefficientStringBuffering">
<Details>
@@ -1381,6 +1389,25 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CircularDependencies">
+ <Details>
+ <![CDATA[
+ <p>This detector looks circular dependencies among classes. </p>
+ <p>It is a moderately fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ModifyingUnmodifiableCollection">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for code that attempts to modify a collection that is or may be
+ defined as immutable. Doing so will cause exceptions at runtime.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger">
<Details></Details>
@@ -3102,6 +3129,19 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="LO_APPENDED_STRING_IN_FORMAT_STRING">
+ <ShortDescription>Method passes a concatenated string to Slf4j's format string</ShortDescription>
+ <LongDescription>Method {1} passes a concatenated string to Slf4j's format string</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method uses an slf4j logger to log a string, where the first (format) string is created using concatenation.
+ You should use {} markers to inject dynamic content into the string, so that String building is delayed until the
+ actual log string is needed. If the log level is high enough that this log statement isn't used, then the appends
+ will never be executed.
+ ]]>
+ </Details>
+ </BugPattern>'
<BugPattern type="IICU_INCORRECT_INTERNAL_CLASS_USE">
<ShortDescription>Class relies on internal API classes</ShortDescription>
@@ -3878,6 +3918,32 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="CD_CIRCULAR_DEPENDENCY">
+ <ShortDescription>Test for circular dependencies among classes</ShortDescription>
+ <LongDescription>Class {0} has a circular dependency with other classes</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>
+ This class has a circular dependency with other classes. This makes building these classes
+ difficult, as each is dependent on the other to build correctly. Consider using interfaces
+ to break the hard dependency.
+ </p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="MUC_MODIFYING_UNMODIFIABLE_COLLECTION">
+ <ShortDescription>This method attempts to modify collection that appears to possibly be immutable</ShortDescription>
+ <LongDescription>This method {1} attempts to modify collection that appears to possibly be immutable</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method attempts to modify a collection that it got from a source that could potentially have created an
+ immutable collection, thru Arrays.asList, Collections.unmodifiableXXX, or one of guava's methods. Doing so will cause
+ an exception, as these collections are not mutable.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3996,4 +4062,6 @@
<BugCode abbrev="CNC">Collection Naming Confusion</BugCode>
<BugCode abbrev="PME">Poor Mans Enum</BugCode>
<BugCode abbrev="UP">Unused Parameter</BugCode>
+ <BugCode abbrev="CD">Circular Dependencies</BugCode>
+ <BugCode abbrev="MUC">Modifying Unmodifiable Collection</BugCode>
</MessageCollection>
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/htdocs/index.shtml 2014-03-18 05:52:22 UTC (rev 1767)
@@ -68,14 +68,14 @@
</li>
</ul>
</p>
- <p style="font-weight: bold;">The latest version of fb-contrib is 5.0.3 available for download
- <a href="http://sourceforge.net/projects/fb-contrib/files/Current/fb-contrib-5.0.3.jar/download">here</a>.</p>
+ <p style="font-weight: bold;">The latest version of fb-contrib is 5.2.0 available for download
+ <a href="http://sourceforge.net/projects/fb-contrib/files/Current/fb-contrib-5.2.0.jar/download">here</a>.</p>
</div>
<hr/>
- <img id="git_image" src="flip2.gif" onClick="toggleBlock('git', 'git_image');" align="top"/>
+ <img id="git_image" src="flip1.gif" onClick="toggleBlock('git', 'git_image');" align="top"/>
Detectors added in git<br/>
- <div id="git" style="display:block;">
+ <div id="git" style="display:none;">
<ul>
<li><b>[STB] Stacked Try Blocks</b><br/>
Looks for two or more try catch blocks that are consecutive and catch the
@@ -88,16 +88,23 @@
to be big enough. This just causes unneeded reallocations putting strain
on the garbage collector.
</li>
- <li><b>[AIOB] Array Index Out of Bounds</b><br/>
- Looks for questionable load/stores to array elements.<ul>
- <li>
- Looks for accesses to array elements using literal values that are known to be outside the bounds of the array.
- This mistake will cause an ArrayIndexOutOfBoundsException to occur at runtime.</li>
- <li>
- Looks for stores to array elements where the array itself appears to have not been allocated.
- </li>
- </ul>
- </li>
+ <li><b>[AIOB] Array Index Out of Bounds</b><br/>
+ Looks for questionable load/stores to array elements.<ul>
+ <li>
+ Looks for accesses to array elements using literal values that are known to be outside the bounds of the array.
+ This mistake will cause an ArrayIndexOutOfBoundsException to occur at runtime.</li>
+ <li>
+ Looks for stores to array elements where the array itself appears to have not been allocated.
+ </li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ <hr/>
+ <img id="v5_2_0_image" src="flip2.gif" onClick="toggleBlock('v5_2_0', 'v5_2_0_image');" align="top"/>
+ Detectors added in v5.2.0<br/>
+ <div id="git" style="display:block;">
+ <ul>
<li><b>[CNC] Collection Naming Confusion</b><br/>
Looks for fields and local variables that have Map, Set, List in their names
but the variable is a collection of a different basic type.
@@ -110,6 +117,14 @@
Looks for private or static methods that have parameters that aren't used. These parameters
can be removed.
</li>
+ <li><b>[CD] Circular Dependencies</b><br/>
+ Looks for class dependencies that where two or more classes rely on each other, either directly or indirectly.
+ This often signifies an improper data model. Consider using interfaces to break this closed loop.
+ </li>
+ <li><b>[MUC] Modifying Unmodifiable Collection</b><br/>
+ Looks for code that attempts to modify a collection that is or may be
+ defined as immutable. or instance, being returned from Arrays.asList(). Doing so will cause exceptions at runtime.
+ </li>
</ul>
</div>
<hr/>
Modified: trunk/fb-contrib/htdocs/repository.html
===================================================================
--- trunk/fb-contrib/htdocs/repository.html 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/htdocs/repository.html 2014-03-18 05:52:22 UTC (rev 1767)
@@ -22,7 +22,7 @@
<table style="margin-left: 40px; background-color: #A0A0FF; padding: 20px; border-width: 1px; border-style: outset; border-color: #000000;">
<tr><td><b>GroupId:</b></td><td>com.mebigfatguy.fb-contrib</td></tr>
<tr><td><b>ArtifactId:</b></td><td>fb-contrib</td></tr>
- <tr><td><b>Version:</b></td><td>5.0.3</td></tr>
+ <tr><td><b>Version:</b></td><td>5.2.0</td></tr>
</table>
</div>
Modified: trunk/fb-contrib/plugin.xml
===================================================================
--- trunk/fb-contrib/plugin.xml 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/plugin.xml 2014-03-18 05:52:22 UTC (rev 1767)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
-<plugin>
+<plugin id="fb-contrib" name="fb-contrib" version="5.2.0">
<extension point="edu.umd.cs.findbugs.plugin.eclipse.findbugsPlugins">
<findbugsPlugin fbPluginId="com.mebigfatguy.fbcontrib" libraryPath="."></findbugsPlugin>
</extension>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/pom.xml 2014-03-18 05:52:22 UTC (rev 1767)
@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>5.0.3</version>
+ <version>5.2.0</version>
<parent>
<groupId>org.sonatype.oss</groupId>
Added: trunk/fb-contrib/samples/CD_Sample.java
===================================================================
--- trunk/fb-contrib/samples/CD_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/CD_Sample.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -0,0 +1,24 @@
+
+public class CD_Sample {
+ Child c = new Child();;
+
+ public void cdTest() {
+ c.childTest();
+ }
+}
+
+class Child {
+ SubChild sc = new SubChild();
+
+ public void childTest() {
+ sc.subChildTest();
+ }
+}
+
+class SubChild {
+ CD_Sample cds = new CD_Sample();
+
+ public void subChildTest() {
+ cds.toString();
+ }
+}
Property changes on: trunk/fb-contrib/samples/CD_Sample.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/fb-contrib/samples/LO_Sample.java
===================================================================
--- trunk/fb-contrib/samples/LO_Sample.java 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/samples/LO_Sample.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -41,6 +41,14 @@
public void testInvalidSLF4jParm() {
l3.error("This is a problem {0}", "hello");
}
+
+ public void testLogAppending(String s) {
+ try {
+ l3.info("Got an error with: " + s);
+ } catch (Exception e) {
+ l3.warn("Go a bad error with: " + s, e);
+ }
+ }
public void testWrongNumberOfParms() {
l3.error("This is a problem {}", "hello", "hello");
Added: trunk/fb-contrib/samples/MUC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/MUC_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/MUC_Sample.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -0,0 +1,45 @@
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import java.util.Collections;
+
+
+public class MUC_Sample {
+
+ public void testMUC() {
+ List<String> l = getImmutableList();
+
+ l.add("Uhoh");
+ }
+
+ public void testPossiblyMUC() {
+ Set<String> s = getPossiblyImmutableSet(Math.random() > 0.5);
+
+ s.add("Yowsers");
+ }
+
+ public void testMUCChained() {
+ List<String> l = getImmutableListChained();
+
+ l.add("Uhoh");
+ }
+
+ public List<String> getImmutableList() {
+ return Arrays.asList("foo");
+ }
+
+ public Set<String> getPossiblyImmutableSet(boolean b) {
+ if (b)
+ return Collections.unmodifiableSet(new HashSet<String>());
+
+ return new HashSet<String>();
+ }
+
+ public List<String> getImmutableListChained() {
+ return getImmutableList();
+ }
+
+
+}
Property changes on: trunk/fb-contrib/samples/MUC_Sample.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/fb-contrib/samples/samples.fbp
===================================================================
--- trunk/fb-contrib/samples/samples.fbp 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/samples/samples.fbp 2014-03-18 05:52:22 UTC (rev 1767)
@@ -1,16 +1,15 @@
<Project projectName="sample">
- <Jar>./././././.</Jar>
- <AuxClasspathEntry>././../lib/backport-util-concurrent-3.1.jar</AuxClasspathEntry>
- <AuxClasspathEntry>././../lib/commons-collections-3.2.1.jar</AuxClasspathEntry>
- <AuxClasspathEntry>././../lib/javax.servlet-api-3.1.0.jar</AuxClasspathEntry>
- <AuxClasspathEntry>././../lib/junit-4.11.jar</AuxClasspathEntry>
- <AuxClasspathEntry>././../lib/log4j-1.2.17-sources.jar</AuxClasspathEntry>
- <AuxClasspathEntry>././../lib/log4j-1.2.17.jar</AuxClasspathEntry>
- <AuxClasspathEntry>././../lib/slf4j-api-1.7.5.jar</AuxClasspathEntry>
- <AuxClasspathEntry>./../lib/guava-15.0.jar</AuxClasspathEntry>
- <AuxClasspathEntry>../lib/commons-lang3-3.2.jar</AuxClasspathEntry>
- <AuxClasspathEntry>../lib/javax.servlet.jsp-api-2.3.1.jar</AuxClasspathEntry>
- <SrcDir>./././././.</SrcDir>
+ <Jar>././.</Jar>
+ <AuxClasspathEntry>./../lib/backport-util-concurrent-3.1.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./../lib/commons-collections-3.2.1.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./../lib/guava-16.0.1.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./../lib/javax.servlet-api-3.1.0.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./../lib/javax.servlet.jsp-api-2.3.1.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./../lib/junit-4.11.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./../lib/log4j-1.2.17.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>../lib/commons-lang3-3.3.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>../lib/slf4j-api-1.7.6.jar</AuxClasspathEntry>
+ <SrcDir>././.</SrcDir>
<SuppressionFilter>
<LastVersion value="-1" relOp="NEQ"/>
</SuppressionFilter>
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/FBContrib.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -1,6 +1,6 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
- * Copyright (C) 2005-2013 Dave Brosius
+ * Copyright (C) 2005-2014 Dave Brosius
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -28,7 +28,7 @@
* @param args standard command line args
*/
public static void main(final String[] args) {
- JOptionPane.showMessageDialog( null, "To use fb-contrib, copy this jar file into your local FindBugs plugin directory, and use FindBugs as usual.\n\nfb-contrib is a trademark of MeBigFatGuy.com\nFindBugs is a trademark of the University of Maryland", "fb-contrib: copyright 2005-2013", JOptionPane.INFORMATION_MESSAGE);
+ JOptionPane.showMessageDialog( null, "To use fb-contrib, copy this jar file into your local FindBugs plugin directory, and use FindBugs as usual.\n\nfb-contrib is a trademark of MeBigFatGuy.com\nFindBugs is a trademark of the University of Maryland", "fb-contrib: copyright 2005-2014", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -0,0 +1,200 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2014 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.collect;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.Type;
+
+import com.mebigfatguy.fbcontrib.utils.CollectionUtils;
+
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.NonReportingDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.OpcodeStack.CustomUserValue;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+/**
+ * collects methods that return a collection that could be created thru an immutable method
+ * such as Arrays.aslist, etc.
+ */
+@CustomUserValue
+public class CollectMethodsReturningImmutableCollections extends BytecodeScanningDetector implements NonReportingDetector {
+
+ private static Set<String> IMMUTABLE_PRODUCING_METHODS = new HashSet<String>();
+ static {
+ IMMUTABLE_PRODUCING_METHODS.add("com/google/common/Collect/Maps.immutableEnumMap");
+ IMMUTABLE_PRODUCING_METHODS.add("com/google/common/Collect/Maps.unmodifiableMap");
+ IMMUTABLE_PRODUCING_METHODS.add("com/google/common/Collect/Sets.immutableEnumSet");
+ IMMUTABLE_PRODUCING_METHODS.add("com/google/common/Collect/Sets.immutableCopy");
+ IMMUTABLE_PRODUCING_METHODS.add("java/util/Arrays.asList");
+ IMMUTABLE_PRODUCING_METHODS.add("java/util/Collections.unmodifiableCollection");
+ IMMUTABLE_PRODUCING_METHODS.add("java/util/Collections.unmodifiableSet");
+ IMMUTABLE_PRODUCING_METHODS.add("java/util/Collections.unmodifiableSortedSet");
+ IMMUTABLE_PRODUCING_METHODS.add("java/util/Collections.unmodifiableMap");
+ IMMUTABLE_PRODUCING_METHODS.add("java/util/Collections.unmodifiableList");
+ IMMUTABLE_PRODUCING_METHODS.add("edu/emory/mathcs/backport/java/util/Arrays.asList");
+ IMMUTABLE_PRODUCING_METHODS.add("edu/emory/mathcs/backport/java/util/Collections.unmodifiableCollection");
+ IMMUTABLE_PRODUCING_METHODS.add("edu/emory/mathcs/backport/java/util/Collections.unmodifiableSet");
+ IMMUTABLE_PRODUCING_METHODS.add("edu/emory/mathcs/backport/java/util/Collections.unmodifiableSortedSet");
+ IMMUTABLE_PRODUCING_METHODS.add("edu/emory/mathcs/backport/java/util/Collections.unmodifiableMap");
+ IMMUTABLE_PRODUCING_METHODS.add("edu/emory/mathcs/backport/java/util/Collections.unmodifiableList");
+ }
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ private String clsName;
+ private ImmutabilityType imType;
+
+ /**
+ * constructs a CMRIC detector given the reporter to report bugs on
+ *
+ * @param bugReporter
+ * the sync of bug reports
+ */
+ public CollectMethodsReturningImmutableCollections(BugReporter reporter) {
+ bugReporter = reporter;
+ }
+
+ public void visitClassContext(ClassContext context) {
+ try {
+ stack = new OpcodeStack();
+ clsName = context.getJavaClass().getClassName();
+ super.visitClassContext(context);
+ } finally {
+ stack = null;
+ }
+ }
+
+ /**
+ * overrides the visitor to reset the stack for the new method, then checks if the immutability field is set to immutable
+ * and if so reports it
+ *
+ * @param obj the context object of the currently parsed method
+ */
+ public void visitCode(Code obj) {
+ try {
+ String signature = Type.getReturnType(getMethod().getSignature()).getSignature();
+ if (signature.startsWith("L") && CollectionUtils.isListSetMap(signature.substring(1, signature.length() - 1))) {
+ stack.resetForMethodEntry(this);
+ imType = ImmutabilityType.UNKNOWN;
+ super.visitCode(obj);
+
+ if ((imType == ImmutabilityType.IMMUTABLE) || (imType == ImmutabilityType.POSSIBLY_IMMUTABLE)) {
+ Method m = getMethod();
+ Statistics.getStatistics().addImmutabilityStatus(clsName, m.getName(), m.getSignature(), imType);
+ }
+ }
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ }
+ }
+
+ /**
+ * overrides the visitor to look for calls to static methods that are known to return immutable collections
+ * It records those variabls, and documents if what the method returns is one of those objects.
+ */
+ public void sawOpcode(int seen) {
+ ImmutabilityType seenImmutable = null;
+ try {
+ stack.precomputation(this);
+
+ switch (seen) {
+ case INVOKESTATIC: {
+ String className = getClassConstantOperand();
+ String methodName = getNameConstantOperand();
+
+ if (IMMUTABLE_PRODUCING_METHODS.contains(className + '.' + methodName)) {
+ seenImmutable = ImmutabilityType.IMMUTABLE;
+ break;
+ }
+ }
+ //$FALL-THROUGH$
+ case INVOKEINTERFACE:
+ case INVOKESPECIAL:
+ case INVOKEVIRTUAL: {
+ String className = getClassConstantOperand();
+ String methodName = getNameConstantOperand();
+ String signature = getSigConstantOperand();
+
+ MethodInfo mi = Statistics.getStatistics().getMethodStatistics(className, methodName, signature);
+ seenImmutable = mi.getImmutabilityType();
+ if (seenImmutable == ImmutabilityType.UNKNOWN)
+ seenImmutable = null;
+ }
+ break;
+
+ case ARETURN: {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ ImmutabilityType type = (ImmutabilityType) item.getUserValue();
+ if (type == null)
+ type = ImmutabilityType.UNKNOWN;
+
+ switch (imType) {
+ case UNKNOWN:
+
+ switch (type) {
+ case IMMUTABLE:
+ imType = ImmutabilityType.IMMUTABLE;
+ break;
+ case POSSIBLY_IMMUTABLE:
+ imType = ImmutabilityType.POSSIBLY_IMMUTABLE;
+ break;
+ default:
+ imType = ImmutabilityType.MUTABLE;
+ break;
+ }
+ break;
+
+ case IMMUTABLE:
+ if (type != ImmutabilityType.IMMUTABLE) {
+ imType = ImmutabilityType.POSSIBLY_IMMUTABLE;
+ }
+ break;
+
+ case POSSIBLY_IMMUTABLE:
+ break;
+
+ case MUTABLE:
+ if (type == ImmutabilityType.IMMUTABLE) {
+ imType = ImmutabilityType.POSSIBLY_IMMUTABLE;
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (seenImmutable != null) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(seenImmutable);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -41,7 +41,7 @@
byte[] code = obj.getCode();
if (code != null) {
super.visitCode(obj);
- Statistics.getStatistics().addMethodStatistics(getClassName(), getMethodName(), getMethodSig(), new Statistics.MethodInfo(code.length, numMethodCalls));
+ Statistics.getStatistics().addMethodStatistics(getClassName(), getMethodName(), getMethodSig(), obj.getLength(), numMethodCalls);
}
}
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/ImmutabilityType.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/ImmutabilityType.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/ImmutabilityType.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -0,0 +1,23 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2014 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.collect;
+
+public enum ImmutabilityType {
+ UNKNOWN, IMMUTABLE, POSSIBLY_IMMUTABLE, MUTABLE
+};
\ No newline at end of file
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/ImmutabilityType.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/MethodInfo.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/MethodInfo.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/MethodInfo.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -0,0 +1,57 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2014 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.collect;
+
+public class MethodInfo {
+
+ private short numMethodBytes;
+ private byte numMethodCalls;
+ private byte immutabilityOrdinal;
+
+ public int getNumBytes() {
+ return 0x0000FFFF & numMethodBytes;
+ }
+
+ public void setNumBytes(int numBytes) {
+ numMethodBytes = (short) numBytes;
+ }
+
+ public int getNumMethodCalls() {
+ return 0x000000FF & numMethodCalls;
+ }
+
+ public void setNumMethodCalls(int numCalls) {
+ if (numCalls > 255) {
+ numCalls = 255;
+ }
+ numMethodCalls = (byte) numCalls;
+ }
+
+ public ImmutabilityType getImmutabilityType() {
+ return ImmutabilityType.values()[immutabilityOrdinal];
+ }
+
+ public void setImmutabilityType(ImmutabilityType imType) {
+ immutabilityOrdinal = (byte) imType.ordinal();
+ }
+
+ public String toString() {
+ return "NumMethodBytes: " + getNumBytes() + " NumMethodCalls: " + getNumMethodCalls() + " ImmutabilityType: " + getImmutabilityType();
+ }
+}
\ No newline at end of file
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/MethodInfo.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -1,6 +1,6 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
- * Copyright (C) 2005-2013 Dave Brosius
+ * Copyright (C) 2005-2014 Dave Brosius
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -30,11 +30,12 @@
public class Statistics {
private static Statistics statistics = new Statistics();
+ private static final MethodInfo NOT_FOUND_METHOD_INFO = new MethodInfo();
- private Map<Long, Long> methodStatistics = new HashMap<Long, Long>();
+ private Map<Long, MethodInfo> methodStatistics = new HashMap<Long, MethodInfo>();
+
private Statistics() {
-
}
public static Statistics getStatistics() {
@@ -45,20 +46,23 @@
methodStatistics.clear();
}
- public void addMethodStatistics(String className, String methodName, String signature, MethodInfo methodInfo) {
+ public void addMethodStatistics(String className, String methodName, String signature, int numBytes, int numMethodCalls) {
Long key = getKey(className, methodName, signature);
- if (methodStatistics.containsKey(key))
- methodStatistics.put(key, getValue(new MethodInfo()));
- else
- methodStatistics.put(getKey(className, methodName, signature), getValue(methodInfo));
+ MethodInfo mi = methodStatistics.get(key);
+ if (mi == null) {
+ mi = new MethodInfo();
+ methodStatistics.put(key, mi);
+ }
+
+ mi.setNumBytes(numBytes);
+ mi.setNumMethodCalls(numMethodCalls);
}
public MethodInfo getMethodStatistics(String className, String methodName, String signature) {
- Long v = methodStatistics.get(getKey(className, methodName, signature));
- if (v == null)
- return new MethodInfo();
- else
- return buildMethodInfo(v);
+ MethodInfo mi = methodStatistics.get(getKey(className, methodName, signature));
+ if (mi == null)
+ return NOT_FOUND_METHOD_INFO;
+ return mi;
}
private Long getKey(String className, String methodName, String signature) {
@@ -69,35 +73,15 @@
hashCode |= signature.hashCode();
return Long.valueOf(hashCode);
}
-
- private Long getValue(MethodInfo methodInfo) {
- long value = methodInfo.numBytes;
- value <<= 32;
- value |= methodInfo.numMethodCalls;
- return Long.valueOf(value);
- }
-
- private MethodInfo buildMethodInfo(Long value) {
- MethodInfo mi = new MethodInfo();
- long v = value.longValue();
- mi.numBytes = (int)(v >>> 32);
- mi.numMethodCalls = (int)(v & 0x7FFFFFFF);
- return mi;
- }
-
- public static class MethodInfo
- {
- public int numBytes;
- public int numMethodCalls;
-
- public MethodInfo() {
- numBytes = 0;
- numMethodCalls = 0;
- }
-
- public MethodInfo(int bytes, int calls) {
- numBytes = bytes;
- numMethodCalls = calls;
- }
- }
+
+ public void addImmutabilityStatus(String className, String methodName, String signature, ImmutabilityType imType) {
+ Long key = getKey(className, methodName, signature);
+ MethodInfo mi = methodStatistics.get(key);
+ if (mi == null) {
+ mi = new MethodInfo();
+ methodStatistics.put(key, mi);
+ }
+
+ mi.setImmutabilityType(imType);
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -67,6 +67,12 @@
}
+ /**
+ * constructs a BED detector given the reporter to report bugs on
+ *
+ * @param bugReporter
+ * the sync of bug reports
+ */
@Override
public void visitClassContext(ClassContext classContext) {
try {
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CircularDependencies.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CircularDependencies.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CircularDependencies.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -0,0 +1,208 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2014 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.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.bcel.classfile.JavaClass;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+
+/**
+ * looks for classes that have dependencies on each other in a circular way.
+ * Class initialization can be compromised in this scenario, and usually points to
+ * a bad data model. Consider using interfaces to break this hard circular dependency.
+ */
+public class CircularDependencies extends BytecodeScanningDetector {
+ private Map<String, Set<String>> dependencyGraph = null;
+
+ private BugReporter bugReporter;
+
+ private String clsName;
+
+ /**
+ * constructs a CD detector given the reporter to report bugs on
+ *
+ * @param bugReporter
+ * the sync of bug reports
+ */
+ public CircularDependencies(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ this.dependencyGraph = new HashMap<String, Set<String>>();
+ }
+
+ @Override
+ public void visit(JavaClass obj) {
+ clsName = obj.getClassName();
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ if ((seen == INVOKESPECIAL) || (seen == INVOKESTATIC) || (seen == INVOKEVIRTUAL)) {
+ String refClsName = getClassConstantOperand();
+ refClsName = refClsName.replace('/', '.');
+ if (refClsName.startsWith("java"))
+ return;
+
+ if (clsName.equals(refClsName))
+ return;
+
+ if (clsName.startsWith(refClsName) && (refClsName.indexOf('$') >= 0))
+ return;
+
+ if (refClsName.startsWith(clsName) && (clsName.indexOf('$') >= 0))
+ return;
+
+ Set<String> dependencies = dependencyGraph.get(clsName);
+ if (dependencies == null) {
+ dependencies = new HashSet<String>();
+ dependencyGraph.put(clsName, dependencies);
+ }
+
+ dependencies.add(refClsName);
+ }
+ }
+
+ @Override
+ public void report() {
+ removeDependencyLeaves();
+
+ LoopFinder lf = new LoopFinder();
+
+ while (dependencyGraph.size() > 0) {
+ String className = dependencyGraph.keySet().iterator().next();
+ Set<String> loop = lf.findLoop(dependencyGraph, className);
+ boolean pruneLeaves;
+ if (loop != null) {
+ BugInstance bug = new BugInstance(this, "CD_CIRCULAR_DEPENDENCY", NORMAL_PRIORITY);
+ for (String loopCls : loop) {
+ bug.addClass(loopCls);
+ }
+ bugReporter.reportBug(bug);
+ pruneLeaves = removeLoopLinks(loop);
+ } else {
+ dependencyGraph.remove(className);
+ pruneLeaves = true;
+ }
+ if (pruneLeaves)
+ removeDependencyLeaves();
+ }
+
+ dependencyGraph.clear();
+ }
+
+ private void removeDependencyLeaves() {
+ boolean changed = true;
+ while (changed) {
+ changed = false;
+ Iterator<Set<String>> it = dependencyGraph.values().iterator();
+ while (it.hasNext()) {
+ Set<String> dependencies = it.next();
+
+ boolean foundClass = false;
+ Iterator<String> dit = dependencies.iterator();
+ while (dit.hasNext()) {
+ foundClass = dependencyGraph.containsKey(dit.next());
+ if (!foundClass) {
+ dit.remove();
+ changed = true;
+ }
+ }
+ if (dependencies.isEmpty()) {
+ it.remove();
+ changed = true;
+ }
+ }
+ }
+ }
+
+ private boolean removeLoopLinks(Set<String> loop) {
+ Set<String> dependencies = null;
+ for (String className : loop) {
+ if (dependencies != null)
+ dependencies.remove(className);
+ dependencies = dependencyGraph.get(className);
+ }
+ if (dependencies != null)
+ dependencies.remove(loop.iterator().next());
+
+ boolean removedClass = false;
+ Iterator<String> cIt = loop.iterator();
+ while (cIt.hasNext()) {
+ String className = cIt.next();
+ dependencies = dependencyGraph.get(className);
+ if (dependencies.isEmpty()) {
+ cIt.remove();
+ removedClass = true;
+ }
+ }
+ return removedClass;
+ }
+
+ static class LoopFinder {
+ private Map<String, Set<String>> dGraph = null;
+
+ private String startClass = null;
+
+ private Set<String> visited = null;
+
+ private Set<String> loop = null;
+
+ public Set<String> findLoop(Map<String, Set<String>> dependencyGraph, String startCls) {
+ dGraph = dependencyGraph;
+ startClass = startCls;
+ visited = new HashSet<String>();
+ loop = new LinkedHashSet<String>();
+ if (findLoop(startClass))
+ return loop;
+ return null;
+ }
+
+ private boolean findLoop(String curClass) {
+ if (curClass.contains("$"))
+ return false;
+
+ Set<String> dependencies = dGraph.get(curClass);
+ if (dependencies == null)
+ return false;
+
+ visited.add(curClass);
+ loop.add(curClass);
+ for (String depClass : dependencies) {
+ if (depClass.equals(startClass))
+ return true;
+
+ if (visited.contains(depClass))
+ continue;
+
+ if (findLoop(depClass))
+ return true;
+ }
+ loop.remove(curClass);
+ return false;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CircularDependencies.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -178,5 +178,10 @@
this.register = register;
this.appendInvoked = appendInvoked;
}
+
+ @Override
+ public String toString() {
+ return "register: " + register + " appendInvoked: " + appendInvoked;
+ }
}
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeclaredRuntimeException.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeclaredRuntimeException.java 2014-02-17 21:28:00 UTC (rev 1766)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeclaredRuntimeException.java 2014-03-18 05:52:22 UTC (rev 1767)
@@ -42,24 +42,26 @@
public class DeclaredRuntimeException extends PreorderVisitor implements Detector
{
private final BugReporter bugReporter;
- private static final Set<String> runtimeExceptions = new HashSet<String>();
private static JavaClass runtimeExceptionClass;
static {
try {
runtimeExceptionClass = Repository.lookupClass("java.lang.RuntimeException");
- runtimeExceptions.add("java.lang.RuntimeException");
} catch (ClassNotFoundException cnfe) {
runtimeExceptionClass = null;
}
}
+ private final Set<String> runtimeExceptions = new HashSet<String>();
+
+
/**
* constructs a DRE detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
*/
public DeclaredRuntimeException(final BugReporter bugReporter) {
this.bugReporter = bugReporter;
+ runtimeExceptions.add("java.lang.RuntimeException");
}
/**
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
===================================================================
--- trunk/fb-contrib/src/com/mebi...
[truncated message content] |