[Fb-contrib-commit] SF.net SVN: fb-contrib:[1791] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2016-04-18 22:19:59
|
Revision: 1791 http://sourceforge.net/p/fb-contrib/code/1791 Author: dbrosius Date: 2016-04-18 22:19:54 +0000 (Mon, 18 Apr 2016) Log Message: ----------- sync from github Modified Paths: -------------- trunk/fb-contrib/.classpath trunk/fb-contrib/build.xml trunk/fb-contrib/etc/bugrank.txt trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/htdocs/index.shtml trunk/fb-contrib/htdocs/mbfg_menu.shtml trunk/fb-contrib/htdocs/repository.html trunk/fb-contrib/pom.xml trunk/fb-contrib/samples/BAS_Sample.java trunk/fb-contrib/samples/CD_Sample.java trunk/fb-contrib/samples/IMC_Sample.java trunk/fb-contrib/samples/UTAO_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/Debug.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/OCSDebugger.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayBasedCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BackportReusePublicIdentifiers.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BogusExceptionDeclaration.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CharsetIssues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CircularDependencies.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CloneUsability.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CollectionNamingConfusion.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConflatingResourcesAndFiles.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConflictingTimeUnits.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingArrayAsList.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContainsBasedConditional.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeprecatedTypesafeEnumPattern.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousSetOfCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FloatingPointLoops.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/HangingExecutors.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IOIssues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ImmatureClass.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ImproperPropertiesUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InappropriateToStringUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InconsistentKeyNameCasing.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InheritanceTypeChecking.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JPAIssues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LingeringGraphicsObjects.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LiteralStringComparison.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalTypeDetector.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MissingMethodsDetector.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ModifyingUnmodifiableCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MoreDumbMethods.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonFunctionalField.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonProductiveMethodCall.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonSymmetricEquals.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OrphanedDOMNode.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyPermissiveMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PartiallyConstructedObjectAccess.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorMansEnum.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleConstantAllocationInLoop.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleIncompleteSerialization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleUnsuspectedSerialization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PresizeCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpuriousThreadStates.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StackedTryBlocks.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StringifiedTypes.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousClusteredSessionSupport.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousLoopSearch.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousUninitializedArray.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousWaitOnConcurrentObject.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TristateBooleanPattern.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnboundMethodTemplateParameter.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnitTestAssertionOddities.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryNewNullCheck.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnusedParameter.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/BugType.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/FQMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/QMethod.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/ToString.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/UnmodifiableSet.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/XClassUtils.java Modified: trunk/fb-contrib/.classpath =================================================================== --- trunk/fb-contrib/.classpath 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/.classpath 2016-04-18 22:19:54 UTC (rev 1791) @@ -31,5 +31,6 @@ <classpathentry kind="lib" path="lib/javax.persistence-2.1.1.jar"/> <classpathentry kind="lib" path="lib/commons-io-1.3.2.jar" sourcepath="lib/sources/commons-io-1.3.2-sources.jar"/> <classpathentry kind="lib" path="lib/mockito-all-2.0.2-beta.jar"/> + <classpathentry combineaccessrules="false" kind="src" path="/findbugs"/> <classpathentry kind="output" path="target/classes/main"/> </classpath> Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/build.xml 2016-04-18 22:19:54 UTC (rev 1791) @@ -28,7 +28,7 @@ <property name="javac.deprecation" value="on" /> <property name="javac.debug" value="on" /> - <property name="fb-contrib.version" value="6.6.0" /> + <property name="fb-contrib.version" value="6.6.1" /> <property name="sonatype.dir" value="${user.home}/.fb-contrib-${fb-contrib.version}-sonatype" /> Modified: trunk/fb-contrib/etc/bugrank.txt =================================================================== --- trunk/fb-contrib/etc/bugrank.txt 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/etc/bugrank.txt 2016-04-18 22:19:54 UTC (rev 1791) @@ -65,6 +65,7 @@ +2 BugPattern IMC_IMMATURE_CLASS_NO_HASHCODE +0 BugPattern IMC_IMMATURE_CLASS_NO_PACKAGE +2 BugPattern IMC_IMMATURE_CLASS_NO_TOSTRING ++0 BugPattern IMC_IMMATURE_CLASS_PRINTSTACKTRACE +0 BugPattern IOI_COPY_WITH_READER +0 BugPattern IOI_DOUBLE_BUFFER_COPY +0 BugPattern IPU_IMPROPER_PROPERTIES_USE Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/etc/findbugs.xml 2016-04-18 22:19:54 UTC (rev 1791) @@ -285,7 +285,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.StringifiedTypes" speed="fast" reports="STT_STRING_PARSING_A_FIELD,STT_TOSTRING_STORED_IN_FIELD" /> - <Detector class="com.mebigfatguy.fbcontrib.detect.ImmatureClass" speed="moderate" reports="IMC_IMMATURE_CLASS_NO_EQUALS,IMC_IMMATURE_CLASS_NO_HASHCODE,IMC_IMMATURE_CLASS_NO_PACKAGE,IMC_IMMATURE_CLASS_NO_TOSTRING,IMC_IMMATURE_CLASS_IDE_GENERATED_PARAMETER_NAMES" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.ImmatureClass" speed="moderate" reports="IMC_IMMATURE_CLASS_NO_EQUALS,IMC_IMMATURE_CLASS_NO_HASHCODE,IMC_IMMATURE_CLASS_NO_PACKAGE,IMC_IMMATURE_CLASS_NO_TOSTRING,IMC_IMMATURE_CLASS_IDE_GENERATED_PARAMETER_NAMES,IMC_IMMATURE_CLASS_PRINTSTACKTRACE" /> <Detector class="com.mebigfatguy.fbcontrib.detect.JAXRSIssues" speed="fast" reports="JXI_GET_ENDPOINT_CONSUMES_CONTENT,JXI_INVALID_CONTEXT_PARAMETER_TYPE,JXI_PARM_PARAM_NOT_FOUND_IN_PATH,JXI_UNDEFINED_PARAMETER_SOURCE_IN_ENDPOINT" /> @@ -545,6 +545,7 @@ <BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_NO_HASHCODE" category="STYLE" /> <BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_NO_PACKAGE" category="STYLE" /> <BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_NO_TOSTRING" category="STYLE" /> + <BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_PRINTSTACKTRACE" category="STYLE" /> <BugPattern abbrev="JXI" type="JXI_GET_ENDPOINT_CONSUMES_CONTENT" category="CORRECTNESS" /> <BugPattern abbrev="JXI" type="JXI_INVALID_CONTEXT_PARAMETER_TYPE" category="CORRECTNESS" /> <BugPattern abbrev="JXI" type="JXI_PARM_PARAM_NOT_FOUND_IN_PATH" category="CORRECTNESS" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/etc/messages.xml 2016-04-18 22:19:54 UTC (rev 1791) @@ -1535,7 +1535,10 @@ <p>Looks for classes that are not fully complete from a usability point of view. Making them more difficult to use than it should be. Things such as <ul> + <li>Using the default package</li> + <li>Missing hashCode/equals</li> <li>Missing toString() method</li> + <li>Using autogenerated parameter names</li> </ul> </p> <p>It is a moderately fast detector.</p> @@ -5032,7 +5035,7 @@ <![CDATA[ <p>This method fetches a resource from a URL, and uses the File API to manipulate it. If this resource is a classpath resource, it will work if the resource is a file in a directory. If however the file is inside a JAR file - this will fail. Use the URL.openStream API instead to access the data of the classpath resource. + this will fail. To avoid this confusing inconsistency, use the URL.openStream API instead to access the data of the classpath resource. </p> ]]> </Details> @@ -5083,8 +5086,8 @@ <LongDescription>Class {0} does not implement a toString method</LongDescription> <Details> <![CDATA[ - <p>This class which has instance fields has no toString() method, which will make debugging with this - class more difficult than it could be. Consider adding a method. Using libraries like commons-lang3 + <p>This class, which has instance fields, has no toString() method which will make debugging with this + class more difficult than it could be. Consider adding a toString() method. Using libraries like commons-lang3 ToStringBuilder makes this process easy. </p> ]]> @@ -5104,6 +5107,18 @@ </Details> </BugPattern> + <BugPattern type="IMC_IMMATURE_CLASS_PRINTSTACKTRACE"> + <ShortDescription>Method prints the stack trace to the console</ShortDescription> + <LongDescription>Method {1} prints the stack trace to the console</LongDescription> + <Details> + <![CDATA[ + <p>This method prints a stack trace to the console. This is non configurable, and causes an + application to look unprofessional. Switch to using loggers so that users can control what + is logged and where. + ]]> + </Details> + </BugPattern> + <BugPattern type="JXI_GET_ENDPOINT_CONSUMES_CONTENT"> <ShortDescription>JAX-RS Method implements a GET request but consumes input</ShortDescription> <LongDescription>JAX-RS Method {1} implements a GET request but consumes input</LongDescription> @@ -5247,7 +5262,7 @@ <Details> <![CDATA[ <p>This method declares that it either rolls back or does not rollback a transaction based on an - expected transaction being thrown. However this exception can not be thrown from this method, and so the + expected exception being thrown. However this exception, nor any derived exceptions can not be thrown from this method, and so the annotation is useless.</p> ]]> </Details> @@ -5260,9 +5275,9 @@ <![CDATA[ <p>This method builds a conditional expression, for example, in an if or while statement where the expressions contain both simple local variable comparisons, as well as comparisons on method calls. The expression orders these so that the method calls - come before the simple local variable call comparisons. This causes method calls to be executed in conditions when they + come before the simple local variable comparisons. This causes method calls to be executed in conditions when they do not need to be, and thus potentially causes a lot of code to be executed for nothing. By ordering the expressions so that - the simple conditions contains local variable conditions are first, you eliminate this waste. This assumes that the method + the simple conditions containing local variable conditions are first, you eliminate this waste. This assumes that the method calls do not have side effects. If the method do have side effects, it is probably a better idea to pull these calls out of the condition and execute them first, assigning a value to a local variable. In this way you give a hint that the call may have side effects.</p> Modified: trunk/fb-contrib/htdocs/index.shtml =================================================================== --- trunk/fb-contrib/htdocs/index.shtml 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/htdocs/index.shtml 2016-04-18 22:19:54 UTC (rev 1791) @@ -68,7 +68,7 @@ </li> </ul> </p> - <p style="font-weight: bold;">The latest version of fb-contrib is 6.6.0 available for download + <p style="font-weight: bold;">The latest version of fb-contrib is 6.6.1 available for download <a href="http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22fb-contrib%22">here</a>.</p> <p style="font-weight: bold;">This version requires FindBugs 3.0.1 or better</p> <p style="font-weight: bold;">Please note that active development for this project is now done on Modified: trunk/fb-contrib/htdocs/mbfg_menu.shtml =================================================================== --- trunk/fb-contrib/htdocs/mbfg_menu.shtml 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/htdocs/mbfg_menu.shtml 2016-04-18 22:19:54 UTC (rev 1791) @@ -2,8 +2,10 @@ <a id="mbfg_menu" href="#" >Other MeBigFatGuy Projects</a> <div id="mbfg_projects"> <ul> + <li><a href="https://github.com/mebigfatguy/deadmethods">DeadMethods</a></li> + <li><a href="https://github.com/mebigfatguy/hashshmash">HashShmash</a></li> <li><a href="http://beansource.sf.net">Beansource</a></li> - <li><a href="http://fb-contrib.sf.net">FB-Contrib</a></li> + <li><a href="https://github.com/mebigfatguy/fb-contrib">FB-Contrib</a></li> <li><a href="http://mongobrowser.sf.net">MongoBrowser</a></li> <li><a href="http://mysfstats.sf.net">MySFStats</a></li> <li><a href="http://patchanim.sf.net">PatchAnim</a></li> @@ -12,7 +14,6 @@ <li><a href="http://schemalizer.sf.net">Schemalizer</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://damus.sf.net">Damus</a></li> <li><a href="http://www.heartofgoldfarm.com">Heart of Gold Farm</a></li> </ul> </div> Modified: trunk/fb-contrib/htdocs/repository.html =================================================================== --- trunk/fb-contrib/htdocs/repository.html 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/htdocs/repository.html 2016-04-18 22:19:54 UTC (rev 1791) @@ -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>6.6.0</td></tr> + <tr><td><b>Version:</b></td><td>6.6.1</td></tr> </table> </div> Modified: trunk/fb-contrib/pom.xml =================================================================== --- trunk/fb-contrib/pom.xml 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/pom.xml 2016-04-18 22:19:54 UTC (rev 1791) @@ -8,7 +8,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>com.mebigfatguy.fb-contrib</groupId> <artifactId>fb-contrib</artifactId> - <version>6.6.0</version> + <version>6.6.1</version> <prerequisites> <maven>2.2.1</maven> @@ -140,10 +140,29 @@ <version>3.0.0</version> <scope>provided</scope> </dependency> + <dependency><scope>test</scope><groupId>backport-util-concurrent</groupId><artifactId>backport-util-concurrent</artifactId><version>3.1</version></dependency> + <dependency><scope>test</scope><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>17.0</version></dependency> + <dependency><scope>test</scope><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.6</version></dependency> + <dependency><scope>test</scope><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency> + <dependency><scope>test</scope><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>3.2.1</version></dependency> + <dependency><scope>test</scope><groupId>javax.persistence</groupId><artifactId>persistence-api</artifactId><version>1.0.2</version></dependency> + <dependency><scope>test</scope><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency> + <dependency><scope>test</scope><groupId>javax.servlet.jsp</groupId><artifactId>javax.servlet.jsp-api</artifactId><version>2.3.1</version></dependency> + <dependency><scope>test</scope><groupId>javax.ws.rs</groupId><artifactId>jsr311-api</artifactId><version>1.1.1</version></dependency> + <dependency><scope>test</scope><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency> + <dependency><scope>test</scope><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency> + <dependency><scope>test</scope><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.3</version></dependency> + <dependency><scope>test</scope><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.3.4</version></dependency> + <dependency><scope>test</scope><groupId>org.apache.httpcomponents</groupId><artifactId>httpcore</artifactId><version>4.3.2</version></dependency> + <dependency><scope>test</scope><groupId>org.mockito</groupId><artifactId>mockito-all</artifactId><version>1.10.19</version></dependency> + <dependency><scope>test</scope><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.7</version></dependency> + <dependency><scope>test</scope><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>4.2.4.RELEASE</version></dependency> + <dependency><scope>test</scope><groupId>org.testng</groupId><artifactId>testng</artifactId><version>6.9.10</version></dependency> </dependencies> <build> <sourceDirectory>${basedir}/src</sourceDirectory> + <testSourceDirectory>${basedir}/samples</testSourceDirectory> <outputDirectory>${basedir}/target/classes/main</outputDirectory> <resources> <resource> @@ -221,6 +240,9 @@ <configuration> <excludeFilterFile>etc/findbugs-exclude.xml</excludeFilterFile> <effort>Max</effort> + <plugins> + <plugin><groupId>com.mebigfatguy.fb-contrib</groupId><artifactId>fb-contrib</artifactId><version>${project.version}</version></plugin> + </plugins> </configuration> <executions> <execution> Modified: trunk/fb-contrib/samples/BAS_Sample.java =================================================================== --- trunk/fb-contrib/samples/BAS_Sample.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/samples/BAS_Sample.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -123,7 +123,17 @@ System.out.println(h); } } + + public void tstFPRefChangeThruMethodChain(Holder h1, Holder h2, boolean b) { + String h = h1.toString().trim(); + h1 = h2; + + if (b) { + System.out.println(h); + } + } + public void testFPSrcOverwrite(int src, boolean b) { int d = src; src = 0; Modified: trunk/fb-contrib/samples/CD_Sample.java =================================================================== --- trunk/fb-contrib/samples/CD_Sample.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/samples/CD_Sample.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -61,3 +61,21 @@ return data; } } + +class GitHubIssue101 { + protected void onCreate(final String savedInstanceState) { + final Intent intent = new Intent(ChildWithUsedClassObj.class); + startActivity(intent); + } + + private void startActivity(Intent i) { + } +} + +class ChildWithUsedClassObj extends GitHubIssue101 { +} + +class Intent { + Intent(Class c) { + } +} Modified: trunk/fb-contrib/samples/IMC_Sample.java =================================================================== --- trunk/fb-contrib/samples/IMC_Sample.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/samples/IMC_Sample.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -1,3 +1,7 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -21,6 +25,14 @@ @SuperSecret private String dontReportMe; } + + public void psf(File f) { + try (InputStream is = new FileInputStream(f)) { + is.read(); + } catch (IOException e) { + e.printStackTrace(); + } + } } class IMCFPHasAToString { Modified: trunk/fb-contrib/samples/UTAO_Sample.java =================================================================== --- trunk/fb-contrib/samples/UTAO_Sample.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/samples/UTAO_Sample.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -1,6 +1,7 @@ import org.junit.Assert; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import junit.framework.TestCase; @@ -103,7 +104,7 @@ } class TestNG { - @org.testng.annotations.Test + @org.testng.annotations.Test(enabled = false) public void nada() { } @@ -178,7 +179,7 @@ org.testng.Assert.assertEquals(boo, 20, 0); } - @org.testng.annotations.Test(expectedExceptions = RuntimeException.class) + @org.testng.annotations.Test(expectedExceptions = RuntimeException.class, enabled = false) public void fpNoAssertsWithNGExpects() { throw new RuntimeException(); } @@ -197,9 +198,55 @@ realObject = new Object(); } - @org.testng.annotations.Test + @org.testng.annotations.Test(enabled = false) public void fpShouldNotEqualMockObject() { org.testng.Assert.assertNotEquals(realObject, mockObject); } } + +class GitHubIssue109 { + private static final String UUID = "some uuid"; + + @Mock + private Repo repository; + @Mock + private Object domainObject; + + @org.testng.annotations.Test + public void shouldReturnDomainObjectForUuid() throws Exception { + MockitoAnnotations.initMocks(this); + + StrutsAction action = new StrutsAction(repository); + Mockito.when(repository.findByUuid(UUID)).thenReturn(domainObject); + + action.setUuid(UUID); + org.testng.Assert.assertEquals(action.execute(), Action.SUCCESS); + // this assertion triggers the detector + Assert.assertEquals(action.getDomainObject(), domainObject); + } + + enum Action { + SUCCESS, FAILURE + }; + + class StrutsAction { + public StrutsAction(Object repo) { + } + + public Object execute() { + return null; + } + + public Object getDomainObject() { + return null; + } + + void setUuid(String uuid) { + } + } + + interface Repo { + Object findByUuid(String uuid); + } +} Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectMethodsReturningImmutableCollections.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -1,17 +1,17 @@ /* * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2016 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 @@ -36,8 +36,7 @@ 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. + * 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 { @@ -70,7 +69,7 @@ /** * constructs a CMRIC detector given the reporter to report bugs on - * + * * @param reporter * the sync of bug reports */ @@ -90,9 +89,8 @@ } /** - * 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 - * + * 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 */ @@ -116,9 +114,8 @@ } /** - * overrides the visitor to look for calls to static methods that are known - * to return immutable collections It records those variables, and documents - * if what the method returns is one of those objects. + * overrides the visitor to look for calls to static methods that are known to return immutable collections It records those variables, and documents if + * what the method returns is one of those objects. */ @Override public void sawOpcode(int seen) { @@ -127,83 +124,87 @@ stack.precomputation(this); switch (seen) { - case INVOKESTATIC: { - String className = getClassConstantOperand(); - String methodName = getNameConstantOperand(); + case INVOKESTATIC: { + String className = getClassConstantOperand(); + String methodName = getNameConstantOperand(); - if (IMMUTABLE_PRODUCING_METHODS.contains(className + '.' + methodName)) { - seenImmutable = ImmutabilityType.IMMUTABLE; + 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: { + processARreturn(); break; } + default: + 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; + } finally { + stack.sawOpcode(this, seen); + if ((seenImmutable != null) && (stack.getStackDepth() > 0)) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(seenImmutable); } - break; + } + } - case ARETURN: { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - ImmutabilityType type = (ImmutabilityType) item.getUserValue(); - if (type == null) - type = ImmutabilityType.UNKNOWN; + private void processARreturn() { + 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 (imType) { + case UNKNOWN: - switch (type) { + switch (type) { case IMMUTABLE: imType = ImmutabilityType.IMMUTABLE; - break; + break; case POSSIBLY_IMMUTABLE: imType = ImmutabilityType.POSSIBLY_IMMUTABLE; - break; + break; default: imType = ImmutabilityType.MUTABLE; - break; - } break; + } + break; - case IMMUTABLE: - if (type != ImmutabilityType.IMMUTABLE) { - imType = ImmutabilityType.POSSIBLY_IMMUTABLE; - } - break; + case IMMUTABLE: + if (type != ImmutabilityType.IMMUTABLE) { + imType = ImmutabilityType.POSSIBLY_IMMUTABLE; + } + break; - case POSSIBLY_IMMUTABLE: - break; + case POSSIBLY_IMMUTABLE: + break; - case MUTABLE: - if (type == ImmutabilityType.IMMUTABLE) { - imType = ImmutabilityType.POSSIBLY_IMMUTABLE; - } - break; + case MUTABLE: + if (type == ImmutabilityType.IMMUTABLE) { + imType = ImmutabilityType.POSSIBLY_IMMUTABLE; } - } break; } - default: - break; - } - - } finally { - stack.sawOpcode(this, seen); - if (seenImmutable != null) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - item.setUserValue(seenImmutable); - } - } } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -36,11 +36,11 @@ public class CollectStatistics extends BytecodeScanningDetector implements NonReportingDetector { private static final Set<String> COMMON_METHOD_SIGS = UnmodifiableSet.create( //@formatter:off - "\\<init\\>\\(\\)V", - "toString\\(\\)Ljava/lang/String;", - "hashCode\\(\\)I", - "clone\\(\\).*", - "values\\(\\).*", + "\\<init\\>\\(\\)V", + "toString\\(\\)Ljava/lang/String;", + "hashCode\\(\\)I", + "clone\\(\\).*", + "values\\(\\).*", "main\\(\\[Ljava/lang/String;\\)V" //@formatter:on ); @@ -56,7 +56,7 @@ public void visitClassContext(ClassContext classContext) { JavaClass cls = classContext.getJavaClass(); AnnotationEntry[] annotations = cls.getAnnotationEntries(); - classHasAnnotation = (annotations != null) && (annotations.length > 0); + classHasAnnotation = annotations != null && annotations.length > 0; super.visitClassContext(classContext); } @@ -73,7 +73,7 @@ int accessFlags = method.getAccessFlags(); MethodInfo mi = Statistics.getStatistics().addMethodStatistics(clsName, getMethodName(), getMethodSig(), accessFlags, obj.getLength(), numMethodCalls); - if (clsName.contains("$") || ((accessFlags & (ACC_ABSTRACT | ACC_INTERFACE | ACC_ANNOTATION)) != 0)) { + if (clsName.contains("$") || (accessFlags & (ACC_ABSTRACT | ACC_INTERFACE | ACC_ANNOTATION)) != 0) { mi.addCallingAccess(Constants.ACC_PUBLIC); } else if ((accessFlags & Constants.ACC_PRIVATE) == 0) { if (isAssociationedWithAnnotations(method)) { @@ -111,6 +111,6 @@ } AnnotationEntry[] annotations = m.getAnnotationEntries(); - return (annotations != null) && (annotations.length > 0); + return annotations != null && annotations.length > 0; } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/Debug.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/Debug.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/Debug.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -33,7 +33,8 @@ static { try { out = new PrintStream( - new BufferedOutputStream(new FileOutputStream(new File(System.getProperty("java.io.tmpdir"), "fb-contrib.txt").getPath(), true)), false, StandardCharsets.UTF_8.name()); + new BufferedOutputStream(new FileOutputStream(new File(System.getProperty("java.io.tmpdir"), "fb-contrib.txt").getPath(), true)), false, + StandardCharsets.UTF_8.name()); out.println("===== fb-contrib console ====="); } catch (IOException e) { throw new RuntimeException(e); @@ -53,17 +54,16 @@ /** * Like println, but will print PC, if it's passed in - * - * e.g. Debug.println(getPC(), "Hello world"); will print [PC:42] Hello - * world - * + * + * e.g. Debug.println(getPC(), "Hello world"); will print [PC:42] Hello world + * * @param pc * the program counter * @param obj * the object to output */ public static void println(int pc, Object obj) { - out.printf("[PC:%d] %s%n", pc, obj); + out.printf("[PC:%d] %s%n", Integer.valueOf(pc), obj); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/OCSDebugger.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/OCSDebugger.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/debug/OCSDebugger.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -43,12 +43,14 @@ private PrintWriter pw = null; public OCSDebugger(@SuppressWarnings("unused") BugReporter bugReporter) { + // no bugs are reported, so not storing the bugReporter } @Override public void visitClassContext(ClassContext classContext) { - if ((OUTPUT_FILE_NAME != null) && (METHOD_DESC != null)) + if (OUTPUT_FILE_NAME != null && METHOD_DESC != null) { super.visitClassContext(classContext); + } } @Override @@ -63,6 +65,7 @@ super.visitCode(obj); } catch (IOException e) { + // ignore } finally { pw.close(); pw = null; @@ -74,6 +77,7 @@ public void sawOpcode(int seen) { stack.precomputation(this); stack.sawOpcode(this, seen); - pw.println(String.format("After executing: %-16s at PC: %-5d Stack Size: %-3d", Constants.OPCODE_NAMES[getOpcode()], getPC(), stack.getStackDepth())); + pw.println(String.format("After executing: %-16s at PC: %-5d Stack Size: %-3d", Constants.OPCODE_NAMES[getOpcode()], Integer.valueOf(getPC()), + Integer.valueOf(stack.getStackDepth()))); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -50,7 +50,7 @@ /** * constructs a AFBR detector given the reporter to report bugs on. - * + * * @param bugReporter * the sync of bug reports */ @@ -98,7 +98,7 @@ CodeException[] exc = obj.getExceptionTable(); if (exc != null) { for (CodeException ce : exc) { - if ((ce.getCatchType() == 0) && (ce.getStartPC() == ce.getHandlerPC())) { + if (ce.getCatchType() == 0 && ce.getStartPC() == ce.getHandlerPC()) { fbInfo.add(new FinallyBlockInfo(ce.getStartPC())); } } @@ -146,7 +146,7 @@ } } - if ((seen == ATHROW) && (loadedReg == fbi.exReg)) { + if (seen == ATHROW && loadedReg == fbi.exReg) { fbInfo.remove(0); sawOpcode(seen); return; @@ -155,22 +155,20 @@ else loadedReg = -1; - if (((seen >= IRETURN) && (seen <= RETURN)) || (seen == ATHROW)) { + if (seen >= IRETURN && seen <= RETURN || seen == ATHROW) { bugReporter.reportBug(new BugInstance(this, BugType.AFBR_ABNORMAL_FINALLY_BLOCK_RETURN.name(), NORMAL_PRIORITY).addClass(this).addMethod(this) .addSourceLine(this)); fbInfo.remove(0); - } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE) || (seen == INVOKESPECIAL) || (seen == INVOKESTATIC)) { + } else if (seen == INVOKEVIRTUAL || seen == INVOKEINTERFACE || seen == INVOKESPECIAL || seen == INVOKESTATIC) { try { JavaClass cls = Repository.lookupClass(getClassConstantOperand()); Method m = findMethod(cls, getNameConstantOperand(), getSigConstantOperand()); if (m != null) { ExceptionTable et = m.getExceptionTable(); - if ((et != null) && (et.getLength() > 0)) { - if (!catchBlockInFinally(fbi)) { - bugReporter.reportBug(new BugInstance(this, BugType.AFBR_ABNORMAL_FINALLY_BLOCK_RETURN.name(), LOW_PRIORITY).addClass(this) - .addMethod(this).addSourceLine(this)); - fbInfo.remove(0); - } + if (et != null && et.getLength() > 0 && !catchBlockInFinally(fbi)) { + bugReporter.reportBug(new BugInstance(this, BugType.AFBR_ABNORMAL_FINALLY_BLOCK_RETURN.name(), LOW_PRIORITY).addClass(this) + .addMethod(this).addSourceLine(this)); + fbInfo.remove(0); } } } catch (ClassNotFoundException cnfe) { @@ -216,15 +214,16 @@ private boolean catchBlockInFinally(FinallyBlockInfo fBlockInfo) { CodeException[] catchExceptions = getCode().getExceptionTable(); - if ((catchExceptions == null) || (catchExceptions.length == 0)) + if (catchExceptions == null || catchExceptions.length == 0) { return false; + } int pc = getPC(); for (CodeException ex : catchExceptions) { - if ((ex.getStartPC() <= pc) && (ex.getEndPC() >= pc)) { - if (ex.getStartPC() >= fBlockInfo.startPC) { - return true; - } + if (ex.getStartPC() <= pc + && ex.getEndPC() >= pc + && ex.getStartPC() >= fBlockInfo.startPC) { + return true; } } @@ -256,4 +255,4 @@ return ToString.build(this); } } -} \ No newline at end of file +} Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -1,17 +1,17 @@ /* * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2016 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 @@ -63,7 +63,7 @@ /** * constructs a ACEM detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ @@ -73,7 +73,7 @@ /** * overrides the visitor to check for abstract classes. - * + * * @param classContext * the context object that holds the JavaClass being parsed */ @@ -84,7 +84,7 @@ if (cls.isAbstract()) { interfaceMethods = collectInterfaceMethods(cls); super.visitClassContext(classContext); - } + } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } finally { @@ -94,7 +94,7 @@ /** * overrides the visitor to grab the method name and reset the state. - * + * * @param obj * the method being parsed */ @@ -106,7 +106,7 @@ /** * overrides the visitor to filter out constructors. - * + * * @param obj * the code to parse */ @@ -114,7 +114,7 @@ public void visitCode(Code obj) { if (Values.CONSTRUCTOR.equals(methodName) || Values.STATIC_INITIALIZER.equals(methodName)) return; - + if (!interfaceMethods.contains(new QMethod(methodName, getMethod().getSignature()))) { super.visitCode(obj); } @@ -123,7 +123,7 @@ /** * overrides the visitor to look for empty methods or simple exception * throwers. - * + * * @param seen * the opcode currently being parsed */ @@ -139,7 +139,7 @@ } else if (seen == NEW) { String newClass = getClassConstantOperand(); JavaClass exCls = Repository.lookupClass(newClass); - if ((EXCEPTION_CLASS != null) && exCls.instanceOf(EXCEPTION_CLASS)) + if (EXCEPTION_CLASS != null && exCls.instanceOf(EXCEPTION_CLASS)) state = State.SAW_NEW; else state = State.SAW_DONE; @@ -155,14 +155,14 @@ break; case SAW_DUP: - if (((seen == LDC) || (seen == LDC_W)) && (getConstantRefOperand() instanceof ConstantString)) + if ((seen == LDC || seen == LDC_W) && getConstantRefOperand() instanceof ConstantString) state = State.SAW_LDC; else state = State.SAW_DONE; break; case SAW_LDC: - if ((seen == INVOKESPECIAL) && Values.CONSTRUCTOR.equals(getNameConstantOperand())) + if (seen == INVOKESPECIAL && Values.CONSTRUCTOR.equals(getNameConstantOperand())) state = State.SAW_INVOKESPECIAL; else state = State.SAW_DONE; @@ -184,7 +184,7 @@ state = State.SAW_DONE; } } - + private Set<QMethod> collectInterfaceMethods(JavaClass cls) throws ClassNotFoundException { Set<QMethod> methods = new HashSet<QMethod>(); for (JavaClass inf : cls.getAllInterfaces()) { @@ -192,7 +192,7 @@ methods.add(new QMethod(m.getName(), m.getSignature())); } } - + return methods; } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayBasedCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayBasedCollections.java 2016-01-25 22:44:19 UTC (rev 1790) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayBasedCollections.java 2016-04-18 22:19:54 UTC (rev 1791) @@ -1,17 +1,17 @@ /* * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2016 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 @@ -34,10 +34,8 @@ import edu.umd.cs.findbugs.ba.ClassContext; /** - * looks for methods that use arrays for items in the keyset of a map, or as an - * element of a set, or in a list when using the contains method. Since arrays - * do not, and cannot define an equals method, reference equality is used for - * these collections, which is probably not desired. + * looks for methods that use arrays for items in the keyset of a map, or as an element of a set, or in a list when using the contains method. Since arrays do + * not, and cannot define an equals method, reference equality is used for these collections, which is probably not desired. */ public class ArrayBasedCollections extends BytecodeScanningDetector { private BugReporter bugReporter; @@ -49,7 +47,7 @@ /** * constructs a ABC detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ @@ -59,7 +57,7 @@ /** * implement the visitor to report bugs if no Tree comparators were found - * + * * @param classContext * the context object for the class currently being parsed */ @@ -92,7 +90,7 @@ /** * implements the visitor to reset the stack of opcodes - * + * * @param obj * the context object for the currently parsed code block */ @@ -103,9 +101,8 @@ } /** - * implements the visitor to find accesses to maps, sets and lists using - * arrays - * + * implements the visitor to find accesses to maps, sets and lists using arrays + * * @param seen * the currently visitor opcode */ @@ -115,68 +112,78 @@ stack.precomputation(this); if (seen == INVOKEINTERFACE) { - String className = getClassConstantOperand(); - String methodName = getNameConstantOperand(); - String methodSig = getSigConstantOperand(); - boolean found = false; - List<BugInstance> bugList = null; + processInvokeInterface(); - if ("java/util/Map".equals(className) && "put".equals(methodName) - && "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;".equals(methodSig)) { - if (stack.getStackDepth() > 1) { - OpcodeStack.Item itm = stack.getStackItem(1); - String pushedSig = itm.getSignature(); - if ((pushedSig.length() > 0) && (pushedSig.charAt(0) == '[')) { - bugList = mapBugs; - found = true; - } - } - } else if ("java/util/Set".equals(className) && "add".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSig)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - String pushedSig = itm.getSignature(); - if (pushedSig.charAt(0) == '[') { - bugList = setBugs; - found = true; - } - } - } else if ("java/util/List".equals(className) && "contains".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSig)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - String pushedSig = itm.getSignature(); - if (pushedSig.charAt(0) == '[') - found = true; - } - } + } else if (seen == INVOKESPECIAL) { + processInvokeSpecial(); + } + } finally { + stack.sawOpcode(this, seen); + } + } - if (found) { - BugInstance bi = new BugInstance(this, BugType.ABC_ARRAY_BASED_COLLECTIONS.name(), NORMAL_PRIORITY).addClass(this).addMethod(this) - .addSourceLine(this); - if (bugList != null) - bugList.add(bi); - else - bugReporter.reportBug(bi); + private void processInvokeInterface() { + String className = getClassConstantOperand(); + String methodName = getNameConstantOperand(); + String methodSig = getSigConstantOperand(); + boolean found = false; + List<BugInstance> bugList = null; + + if ("java/util/Map".equals(className) && "put".equals(methodName) && "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;".equals(methodSig)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); + String pushedSig = itm.getSignature(); + if ((pushedSig.length() > 0) && (pushedSig.charAt(0) == '[')) { + bugList = mapBugs; + found = true; } + } + } else if ("java/util/Set".equals(className) && "add".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSig)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + String pushedSig = itm.getSignature(); + if (pushedSig.charAt(0) == '[') { + bugList = setBugs; + found = true; + } + } + } else if ("java/util/List".equals(className) && "contains".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSig) + && (stack.getStackDepth() > 0)) { + OpcodeStack.Item itm = stack.getStackItem(0); + String pushedSig = itm.getSignature(); + if (pushedSig.charAt(0) == '[') { + found = true; + } + } - } else if (seen == INVOKESPECIAL) { - String className = getClassConstantOperand(); - String methodName = getNameConstantOperand(); - String sig = getSigConstantOperand(); + if (found) { + BugInstance bi = new BugInstance(this, BugType.ABC_ARRAY_BASED_COLLECTIONS.name(), N... [truncated message content] |