[Fb-contrib-commit] SF.net SVN: fb-contrib:[1793] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2016-07-24 19:20:43
|
Revision: 1793 http://sourceforge.net/p/fb-contrib/code/1793 Author: dbrosius Date: 2016-07-24 19:20:39 +0000 (Sun, 24 Jul 2016) Log Message: ----------- sync from github Modified Paths: -------------- trunk/fb-contrib/.classpath trunk/fb-contrib/build.properties 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/pom.xml trunk/fb-contrib/samples/BAS_Sample.java trunk/fb-contrib/samples/FCBL_Sample.java trunk/fb-contrib/samples/LEST_Sample.java trunk/fb-contrib/samples/LO_Sample.java trunk/fb-contrib/samples/PRMC_Sample.java trunk/fb-contrib/samples/SLS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/MethodInfo.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/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/ClassEnvy.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/CompareClassNameEquals.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConflatingResourcesAndFiles.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/CopiedOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.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/ExceptionSoftening.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FloatingPointLoops.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IOIssues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InvalidConstantArgument.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JAXRSIssues.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/LiteralStringComparison.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/MisleadingOverloadModel.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonFunctionalField.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonProductiveMethodCall.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/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/PossiblyRedundantMethodCalls.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RuntimeExceptionDeclared.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.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/SuboptimalExpressionOrder.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousUninitializedArray.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/Unjitable.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/BugType.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/CollectionUtils.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/FQMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/OpcodeUtils.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Values.java Added Paths: ----------- trunk/fb-contrib/samples/BL_Sample.java trunk/fb-contrib/samples/DMC_Sample.java trunk/fb-contrib/samples/FCD_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BuryingLogic.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousMapCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FindCircularDependencies.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/UnmodifiableList.java Removed Paths: ------------- trunk/fb-contrib/samples/CD_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CircularDependencies.java Modified: trunk/fb-contrib/.classpath =================================================================== --- trunk/fb-contrib/.classpath 2016-04-18 22:22:52 UTC (rev 1792) +++ trunk/fb-contrib/.classpath 2016-07-24 19:20:39 UTC (rev 1793) @@ -15,7 +15,7 @@ <classpathentry kind="lib" path="lib/httpclient-cache-4.3.4.jar"/> <classpathentry kind="lib" path="lib/httpcore-4.3.2.jar"/> <classpathentry kind="lib" path="lib/httpclient-4.3.4.jar"/> - <classpathentry kind="lib" path="lib/annotations-3.0.0.jar"/> + <classpathentry kind="lib" path="lib/annotations-3.0.0.jar" sourcepath="/home/dave/.m2/repository/com/google/code/findbugs/annotations/3.0.0/annotations-3.0.0-sources.jar"/> <classpathentry kind="lib" path="lib/asm-debug-all-5.0.2.jar" sourcepath="/home/dave/.m2/repository/org/ow2/asm/asm-debug-all/5.0.2/asm-debug-all-5.0.2-sources.jar"/> <classpathentry kind="lib" path="lib/bcel-findbugs-6.0.jar" sourcepath="lib/sources/bcel-findbugs-6.0-sources.jar"> <attributes> Modified: trunk/fb-contrib/build.properties =================================================================== --- trunk/fb-contrib/build.properties 2016-04-18 22:22:52 UTC (rev 1792) +++ trunk/fb-contrib/build.properties 2016-07-24 19:20:39 UTC (rev 1793) @@ -1,4 +1,4 @@ -jdk14.home=C:/j2sdk1.4.2_13 + bin.includes = plugin.xml,\ META-INF/,\ . Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2016-04-18 22:22:52 UTC (rev 1792) +++ trunk/fb-contrib/build.xml 2016-07-24 19:20:39 UTC (rev 1793) @@ -28,7 +28,7 @@ <property name="javac.deprecation" value="on" /> <property name="javac.debug" value="on" /> - <property name="fb-contrib.version" value="6.6.1" /> + <property name="fb-contrib.version" value="6.7.0-SNAPSHOT" /> <property name="sonatype.dir" value="${user.home}/.fb-contrib-${fb-contrib.version}-sonatype" /> @@ -39,10 +39,10 @@ <target name="infra_jars" description="pull jars needed to build fb-contrib to ${user.dir}/.ant/lib"> <mkdir dir="${user.home}/.ant/lib" /> - <get src="http://repo1.maven.org/maven2/com/mebigfatguy/yank/yank/1.4.0/yank-1.4.0.jar" dest="${user.home}/.ant/lib"/> + <get src="http://repo1.maven.org/maven2/com/mebigfatguy/yank/yank/1.6.1/yank-1.6.1.jar" dest="${user.home}/.ant/lib"/> <get src="https://bitbucket.org/kjlubick/bugrankcheckstyle/downloads/bug-rank-check-style-1.0.0.jar" dest="${user.home}/.ant/lib"/> <get src="http://repo1.maven.org/maven2/com/mebigfatguy/vcsversion/vcsversion/0.4.0/vcsversion-0.4.0.jar" dest="${user.home}/.ant/lib"/> - <get src="http://repo1.maven.org/maven2/com/mebigfatguy/fb-delta/fb-delta/0.2.0/fb-delta-0.2.0.jar" dest="${user.home}/.ant/lib" ignoreerrors="true"/> + <get src="http://repo1.maven.org/maven2/com/mebigfatguy/fb-delta/fb-delta/0.4.1/fb-delta-0.4.1.jar" dest="${user.home}/.ant/lib" ignoreerrors="true"/> </target> <target name="yank" xmlns:yank="antlib:com.mebigfatguy.yank" unless="no.yank"> @@ -179,7 +179,7 @@ <attribute name="Require-Bundle" value="edu.umd.cs.findbugs.plugin.eclipse" /> <attribute name="Bundle-ActivationPolicy" value="lazy" /> <attribute name="Export-Package" value="com.mebigfatguy.fbcontrib, com.mebigfatguy.fbcontrib.collect, com.mebigfatguy.fbcontrib.detect, com.mebigfatguy.fbcontrib.debug, com.mebigfatguy.fbcontrib.utils" /> - <attribute name="Import-Package" value="edu.umd.cs.findbugs, edu.umd.cs.findbugs.ba, edu.umd.cs.findbugs.bcel, edu.umd.cs.findbugs.visitclass, org.apache.bcel, org.apache.bcel.classfile, org.apache.bcel.generic" /> + <attribute name="Import-Package" value="edu.umd.cs.findbugs, edu.umd.cs.findbugs.ba, edu.umd.cs.findbugs.ba.generic, edu.umd.cs.findbugs.bcel, edu.umd.cs.findbugs.visitclass, edu.umd.cs.findbugs.internalAnnotations, org.apache.bcel, org.apache.bcel.classfile, org.apache.bcel.generic" /> </manifest> </jar> </target> Modified: trunk/fb-contrib/etc/bugrank.txt =================================================================== --- trunk/fb-contrib/etc/bugrank.txt 2016-04-18 22:22:52 UTC (rev 1792) +++ trunk/fb-contrib/etc/bugrank.txt 2016-07-24 19:20:39 UTC (rev 1793) @@ -8,6 +8,7 @@ +0 BugPattern BAS_BLOATED_ASSIGNMENT_SCOPE +0 BugPattern BED_BOGUS_EXCEPTION_DECLARATION +0 BugPattern BED_HIERARCHICAL_EXCEPTION_DECLARATION ++0 BugPattern BL_BURYING_LOGIC +0 BugPattern BRPI_BACKPORT_REUSE_PUBLIC_IDENTIFIERS +2 BugPattern BSB_BLOATED_SYNCHRONIZED_BLOCK +0 BugPattern CAAL_CONFUSING_ARRAY_AS_LIST @@ -16,7 +17,6 @@ +0 BugPattern CBX_CUSTOM_BUILT_XML +0 BugPattern CCNE_COMPARE_CLASS_EQUALS_NAME +2 BugPattern CC_CYCLOMATIC_COMPLEXITY -+2 BugPattern CD_CIRCULAR_DEPENDENCY +0 BugPattern CEBE_COMMONS_EQUALS_BUILDER_ISEQUALS +0 BugPattern CEBE_COMMONS_EQUAL_BUILDER_TOEQUALS +2 BugPattern CE_CLASS_ENVY @@ -39,6 +39,7 @@ +0 BugPattern CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT +0 BugPattern DDC_DOUBLE_DATE_COMPARISON +0 BugPattern DLC_DUBIOUS_LIST_COLLECTION ++0 BugPattern DMC_DUBIOUS_MAP_COLLECTION +0 BugPattern DRE_DECLARED_RUNTIME_EXCEPTION +0 BugPattern DSOC_DUBIOUS_SET_OF_COLLECTIONS +0 BugPattern DTEP_DEPRECATED_TYPESAFE_ENUM_PATTERN @@ -49,6 +50,7 @@ +0 BugPattern EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS +0 BugPattern EXS_EXCEPTION_SOFTENING_RETURN_FALSE +0 BugPattern FCBL_FIELD_COULD_BE_LOCAL ++2 BugPattern FCD_FIND_CIRCULAR_DEPENDENCY +0 BugPattern FPL_FLOATING_POINT_LOOPS +6 BugPattern FP_FINAL_PARAMETERS +0 BugPattern HCP_HTTP_REQUEST_RESOURCES_NOT_FREED_FIELD @@ -94,6 +96,7 @@ +0 BugPattern LO_EXCEPTION_WITH_LOGGER_PARMS +0 BugPattern LO_INCORRECT_NUMBER_OF_ANCHOR_PARAMETERS +0 BugPattern LO_INVALID_FORMATTING_ANCHOR ++0 BugPattern LO_INVALID_STRING_FORMAT_NOTATION +0 BugPattern LO_LOGGER_LOST_EXCEPTION_STACK_TRACE +0 BugPattern LO_STUTTERED_MESSAGE +0 BugPattern LO_SUSPECT_LOG_CLASS Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2016-04-18 22:22:52 UTC (rev 1792) +++ trunk/fb-contrib/etc/findbugs.xml 2016-07-24 19:20:39 UTC (rev 1793) @@ -20,7 +20,7 @@ <!-- Detectors --> -<!-- COMMENT OUT FOR RELEASE +<!-- COMMENT OUT FOR RELEASE --> <Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger" speed="fast"/> @@ -30,7 +30,7 @@ <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" /> @@ -176,7 +176,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,LO_APPENDED_STRING_IN_FORMAT_STRING" /> + <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,LO_INVALID_STRING_FORMAT_NOTATION" /> <Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse" speed="fast" reports="IICU_INCORRECT_INTERNAL_CLASS_USE" /> @@ -255,7 +255,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.UnusedParameter" speed="fast" reports="UP_UNUSED_PARAMETER" /> - <Detector class="com.mebigfatguy.fbcontrib.detect.CircularDependencies" speed="moderate" reports="CD_CIRCULAR_DEPENDENCY"/> + <Detector class="com.mebigfatguy.fbcontrib.detect.FindCircularDependencies" speed="moderate" reports="FCD_FIND_CIRCULAR_DEPENDENCY"/> <Detector class="com.mebigfatguy.fbcontrib.collect.CollectMethodsReturningImmutableCollections" speed="fast" reports="" hidden="true" /> @@ -298,6 +298,11 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.IOIssues" speed="fast" reports="IOI_DOUBLE_BUFFER_COPY,IOI_COPY_WITH_READER"/> <!-- COMMENT OUT FOR POINT RELEASE --> + + <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousMapCollection" speed="fast" reports="DMC_DUBIOUS_MAP_COLLECTION"/> + + <Detector class="com.mebigfatguy.fbcontrib.detect.BuryingLogic" speed="fast" reports="BL_BURYING_LOGIC"/> + <!-- COMMENT OUT FOR POINT RELEASE --> <!-- BugPattern --> @@ -458,6 +463,7 @@ <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="LO" type="LO_INVALID_STRING_FORMAT_NOTATION" category="CORRECTNESS" /> <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" /> @@ -522,7 +528,7 @@ <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="CD" type="CD_CIRCULAR_DEPENDENCY" category="CORRECTNESS" /> + <BugPattern abbrev="FCD" type="FCD_FIND_CIRCULAR_DEPENDENCY" category="CORRECTNESS" /> <BugPattern abbrev="MUC" type="MUC_MODIFYING_UNMODIFIABLE_COLLECTION" category="CORRECTNESS" /> <BugPattern abbrev="UJM" type="UJM_UNJITABLE_METHOD" category="PERFORMANCE" /> <BugPattern abbrev="HES" type="HES_EXECUTOR_NEVER_SHUTDOWN" category="CORRECTNESS" /> @@ -550,15 +556,17 @@ <BugPattern abbrev="JXI" type="JXI_INVALID_CONTEXT_PARAMETER_TYPE" category="CORRECTNESS" /> <BugPattern abbrev="JXI" type="JXI_PARM_PARAM_NOT_FOUND_IN_PATH" category="CORRECTNESS" /> <BugPattern abbrev="JXI" type="JXI_UNDEFINED_PARAMETER_SOURCE_IN_ENDPOINT" category="CORRECTNESS" /> - <BugPattern abbrev="JPAI" type="JPAI_TRANSACTION_ON_NON_PUBLIC_METHOD" category="CORRECTNESS" experimental="true"/> - <BugPattern abbrev="JPAI" type="JPAI_HC_EQUALS_ON_MANAGED_ENTITY" category="CORRECTNESS" experimental="true"/> - <BugPattern abbrev="JPAI" type="JPAI_NON_PROXIED_TRANSACTION_CALL" category="CORRECTNESS" experimental="true"/> - <BugPattern abbrev="JPAI" type="JPAI_INEFFICIENT_EAGER_FETCH" category="CORRECTNESS" experimental="true"/> - <BugPattern abbrev="JPAI" type="JPAI_IGNORED_MERGE_RESULT" category="CORRECTNESS" experimental="true"/> - <BugPattern abbrev="JPAI" type="JPAI_NON_SPECIFIED_TRANSACTION_EXCEPTION_HANDLING" category="CORRECTNESS" experimental="true"/> - <BugPattern abbrev="JPAI" type="JPAI_UNNECESSARY_TRANSACTION_EXCEPTION_HANDLING" category="CORRECTNESS" experimental="true"/> - <BugPattern abbrev="SEO" type="SEO_SUBOPTIMAL_EXPRESSION_ORDER" category="PERFORMANCE" experimental="true"/> - <BugPattern abbrev="IOI" type="IOI_DOUBLE_BUFFER_COPY" category="PERFORMANCE" experimental="true"/> - <BugPattern abbrev="IOI" type="IOI_COPY_WITH_READER" category="PERFORMANCE" experimental="true"/> + <BugPattern abbrev="JPAI" type="JPAI_TRANSACTION_ON_NON_PUBLIC_METHOD" category="CORRECTNESS"/> + <BugPattern abbrev="JPAI" type="JPAI_HC_EQUALS_ON_MANAGED_ENTITY" category="CORRECTNESS"/> + <BugPattern abbrev="JPAI" type="JPAI_NON_PROXIED_TRANSACTION_CALL" category="CORRECTNESS"/> + <BugPattern abbrev="JPAI" type="JPAI_INEFFICIENT_EAGER_FETCH" category="CORRECTNESS"/> + <BugPattern abbrev="JPAI" type="JPAI_IGNORED_MERGE_RESULT" category="CORRECTNESS"/> + <BugPattern abbrev="JPAI" type="JPAI_NON_SPECIFIED_TRANSACTION_EXCEPTION_HANDLING" category="CORRECTNESS"/> + <BugPattern abbrev="JPAI" type="JPAI_UNNECESSARY_TRANSACTION_EXCEPTION_HANDLING" category="CORRECTNESS"/> + <BugPattern abbrev="SEO" type="SEO_SUBOPTIMAL_EXPRESSION_ORDER" category="PERFORMANCE"/> + <BugPattern abbrev="IOI" type="IOI_DOUBLE_BUFFER_COPY" category="PERFORMANCE"/> + <BugPattern abbrev="IOI" type="IOI_COPY_WITH_READER" category="PERFORMANCE"/> + <BugPattern abbrev="DMC" type="DMC_DUBIOUS_MAP_COLLECTION" category="CORRECTNESS" experimental="true"/> + <BugPattern abbrev="BL" type="BL_BURYING_LOGIC" category="STYLE" experimental="true" /> </FindbugsPlugin> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2016-04-18 22:22:52 UTC (rev 1792) +++ trunk/fb-contrib/etc/messages.xml 2016-07-24 19:20:39 UTC (rev 1793) @@ -36,7 +36,7 @@ <![CDATA[ <p>Looks for appending strings inside of calls to StringBuffer or StringBuilder append.</p> <pre> - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(a + b); return sb.toString(); </pre> @@ -115,6 +115,15 @@ If a RuntimeException is declared, it implies that this exception type is expected to happen, which if true should be handled in code, and not propagated. </p> <p>It is a fast detector.</p> + <p>As an example, every method could be declared like this: + <code> + public void foo() throws NullPointerException { + } + </code> + But what does that tell you? Is this method very very likely to throw NullPointerExceptions? + If it is, why isn't this method handling them so that exceptions aren't thrown. So don't do this. + If an NPE is very likely, then check for it, and handle the situation. + </p> ]]> </Details> </Detector> @@ -146,7 +155,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.PartiallyConstructedObjectAccess"> <Details> <![CDATA[ - <p>Looks for constructors of non final classes that make method calls to non final methods. + <p>Looks for constructors of non-final classes that make method calls to non-final methods. As these methods could be overridden, the overridden method will be accessing an object that is only partially constructed, perhaps causing problems. Making these called methods final is an easy fix, where possible.</p> @@ -252,17 +261,17 @@ <p>Looks for methods that have the same signature, except where one uses a Character parameter, and the other uses an int, long, float, double parameter. Since autoboxing is available in 1.5 one might assume that - <pre> - test('a') - </pre> +<pre><code> +test('a') +</code></pre> would map to - <pre> - public void test(Character c) - </pre> +<pre><code> +public void test(Character c) +</code></pre> but instead maps to one that takes an int, long, float or double, such as - <pre> - public void test(int i) - </pre> +<pre><code> +public void test(int i) +</code></pre> </p> <p>It is a fast detector.</p> ]]> @@ -491,7 +500,7 @@ <Details> <![CDATA[ <p>Looks for uses of JDBC vendor specific classes and methods making the database - access code non portable.</p> + access code non-portable.</p> <p>It is a fast detector.</p> ]]> </Details> @@ -762,8 +771,10 @@ <Details> <![CDATA[ <p>Looks for calls to classes and methods that do not exist in the JDK for which this class is - compiled. This can happen if you specify the -source and -target options of the javac compiler, and + compiled. This can happen if you specify the <code>-source</code> and <code>-target</code> options of the javac compiler, and specify a target that is less than the JDK version of the javac compiler.</p> + <p>It relies on the system property <code>-Dfb-contrib.sjvu.jdkhome=/path/to/older/jdk/to/check"</code> to specify + what JDK to compare against. If this property is not set, this detector does nothing.</p> <p>It is a slow detector.</p> ]]> </Details> @@ -975,7 +986,7 @@ <Details> <![CDATA[ <p>Looks for methods that are declared to return a Boolean, but return a null - value. As this now allows the method to return 3 values, the use of Boolean is + value. As this now allows the method to return three values, the use of Boolean is dubious. It would be better to just define a new enumeration with three values, and return that.</p> <p>It is a fast detector.</p> @@ -1057,14 +1068,14 @@ <p>Finds contravariant array assignments. Since arrays are mutable data structures, their use must be restricted to covariant or invariant usage.</p> - <pre> - class A {} - class B extends A {} +<pre><code> +class A {} +class B extends A {} - B[] b = new B[2]; - A[] a = b; - a[0] = new A(); // results in ArrayStoreException (Runtime) - </pre> +B[] b = new B[2]; +A[] a = b; +a[0] = new A(); // results in ArrayStoreException (Runtime) +</code></pre> <p>It is a fast detector.</p> ]]> </Details> @@ -1186,9 +1197,9 @@ <![CDATA[ <p>This detector looks for Java bean getter-setter use where the value of a property is set with the value retrieved from the same bean's correllary getter, like this:</p> - <pre> - person.setAge(person.getAge()); - </pre> +<pre><code> + person.setAge(person.getAge()); +</code></pre> <p>Typically this is a copy paste typo.</p> <p>It is a fast detector.</p> ]]> @@ -1199,7 +1210,7 @@ <Details> <![CDATA[ <p>This detector looks for creation of java.awt.Graphics object that do not have the - .dispose() method called on them when finished. These objects will be cleaned up by + <code>.dispose()</code> method called on them when finished. These objects will be cleaned up by the Garbage collector, bug given the likelihood that large numbers of these objects can be created in a short period of time, it is better to dispose them as soon as possible.</p> <p>It is a fast detector.</p> @@ -1232,8 +1243,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.CommonsHashcodeBuilderToHashcode"> <Details> <![CDATA[ - <p>This detector looks for uses for Commons-lang HashCodeBuilder where the - result of hashCode() is returned instead of calling the method toHashCode().</p> + <p>This detector looks for uses for Commons-lang <code>HashCodeBuilder</code> where the + result of <code>hashCode()</code> is returned instead of calling the method <code>toHashCode()</code>.</p> <p>It is a fast detector.</p> ]]> </Details> @@ -1242,8 +1253,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.CommonsStringBuilderToString"> <Details> <![CDATA[ - <p>This detector looks for uses for Commons-lang ToStringBuilder where the - result of toString() is returned without an intermediate invocation of toString().</p> + <p>This detector looks for uses for Commons-lang <code>ToStringBuilder</code> where the + result of <code>toString()</code> is returned without an intermediate invocation of toString().</p> <p>It is a fast detector.</p> ]]> </Details> @@ -1365,7 +1376,7 @@ <p>Looks for fields or local variables that are collections but the names have a different type of collection in the name. This is confusing, and is probably a left over from a type change, such as </p> - <p>List<String> mySet;</p> + <p>List<String> mySet;</p> <p>It is a fast detector.</p> ]]> </Details> @@ -1392,7 +1403,7 @@ </Details> </Detector> - <Detector class="com.mebigfatguy.fbcontrib.detect.CircularDependencies"> + <Detector class="com.mebigfatguy.fbcontrib.detect.FindCircularDependencies"> <Details> <![CDATA[ <p>This detector looks circular dependencies among classes. </p> @@ -1550,7 +1561,7 @@ <Details> <![CDATA[ <p>Looks for problems with the use of the JAX-RS specification.</p> - <p>It is a fast detector</p> + <p>It is a fast detector.</p> ]]> </Details> </Detector> @@ -1560,7 +1571,7 @@ <![CDATA[ <p>Looks for problems with the use of the JPA specification, including spring's support of JPA</p> - <p>It is a fast detector</p> + <p>It is a fast detector.</p> ]]> </Details> </Detector> @@ -1570,9 +1581,9 @@ <![CDATA[ <p>Looks for conditional expressions that are a combination of simple local variable (in)equalities and tests on the results of method calls where the method calls are done first. By placing the simple - conditions first you may elminate costly calls in certain cases. This assumes that the method calls + conditions first you may eliminate costly calls in certain cases. This assumes that the method calls do not have side effects that should happen always.</p> - <p>It is a fast detector</p> + <p>It is a fast detector.</p> ]]> </Details> </Detector> @@ -1581,10 +1592,33 @@ <Details> <![CDATA[ <p>Looks for various issues around doing I/O with streams and reader/writers.</p> - <p>It is a fast detector</p> + <p>It is a fast detector.</p> ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousMapCollection"> + <Details> + <![CDATA[ + <p>Looks for use of maps that are private fields in a List only way, that is, maps that are created in constructors + or static initializers, and are only iterated over. Often this is done because the Map allows for two values, as opposed + to a List. The Fix is to just create a List of some object that holds all the values.</p> + <p>It is a fast detector.</p> + ]]> + </Details> + </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.BuryingLogic"> + <Details> + <![CDATA[ + <p>Looks for methods that needlessly push a large chunk of code to the right through indenting with braces. + The code is basically an if/else-then-return structure. The if true test does the bulk of the logic, and the else + just returns. It is more readable if the bulk of the logic is move as far to the left in the method as is possible. + </p> + <p>It is a fast detector.</p> + ]]> + </Details> + </Detector> <Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger"> <Details></Details> @@ -1603,33 +1637,33 @@ <p> Java will implicitly use StringBuilders, which can make this hard to detect or fix. For example, <br/> - <code> - StringBuilder sb = new StringBuilder();<br/> - for (Map.Entry<Integer, String> e : map.entrySet()) {<br/> - sb.append(e.getKey() + e.getValue()); //bug detected here<br/> - }<br/> - </code><br/> +<pre><code> +StringBuilder sb = new StringBuilder(); +for (Map.Entry<Integer, String> e : map.entrySet()) { + sb.append(e.getKey() + e.getValue()); //bug detected here +} +</code></pre><br/> gets automatically turned into something like: <br/> - <code> - StringBuilder sb = new StringBuilder();<br/> - for (Map.Entry<Integer, String> e : map.entrySet()) {<br/> - StringBuilder tempBuilder = new StringBuilder();<br/> - tempBuilder.append(e.getKey());<br/> - tempBuilder.append(e.getValue());<br/> - sb.append(tempBuilder.toString()); //this isn't too efficient<br/> - }<br/> - </code><br/> +<pre><code> +StringBuilder sb = new StringBuilder(); +for (Map.Entry<Integer, String> e : map.entrySet()) { + StringBuilder tempBuilder = new StringBuilder(); + tempBuilder.append(e.getKey()); + tempBuilder.append(e.getValue()); + <b>sb.append(tempBuilder.toString());</b> //this isn't too efficient +} +</code></pre><br/> which involves a temporary <code>StringBuilder</code>, which is completely unnecessary. To prevent this from happening, simply do:<br/> - <code> - StringBuilder sb = new StringBuilder();<br/> - for (Map.Entry<Integer, String> e : map.entrySet()) {<br/> - sb.append(e.getKey()); <br/> - sb.append(e.getValue());<br/> - }<br/> - </code> +<pre><code> +StringBuilder sb = new StringBuilder(); +for (Map.Entry<Integer, String> e : map.entrySet()) { + sb.append(e.getKey()); + sb.append(e.getValue()); +} +</code></pre> </p> ]]> </Details> @@ -1658,24 +1692,27 @@ does not suffer the potential for <code>NullPointerException</code>s, and is easier to read.</p> <p> - Keep in mind that Java compiles simple <code>String</code> concatenation to use <code>StringBuilder</code>s, so you may see this bug even when you don't use <code>StringBuilder</code>s explicitly. + Keep in mind that Java compiles simple <code>String</code> concatenation to use <code>StringBuilder</code>s, + so you may see this bug even when you don't use <code>StringBuilder</code>s explicitly. </p> <p> Instead of: <br/> - <code> - StringBuilder builder = ... <br/> - builder.append(someObj.toString());<br/> - ... <br/> - System.out.println("Problem with the object :" + someObj.toString());<br/> - </code> - just do: <br/> - <code> - StringBuilder builder = ... <br/> - builder.append(someObj);<br/> - ... <br/> - System.out.println("Problem with the object :" + someObj);<br/> - </code> +<pre><code> +StringBuilder builder = ...; +builder.append(someObj.toString()); +... +System.out.println("Problem with the object :" + someObj.toString()); +</code></pre> + +just do: <br/> + +<pre><code> +StringBuilder builder = ... +builder.append(someObj); +... +System.out.println("Problem with the object :" + someObj); +</code></pre> to avoid the possibility of <code>NullPointerException</code>s when someObj is <code>null</code>. </p> ]]> @@ -1716,21 +1753,21 @@ make low impact changes easier to accomplish in the future.</p> <p>Take the following example:<br/> - <code> - private void appendToList(ArrayList<String> list) {<br/> - if (list.size() < 100) {<br/> - list.add("Foo");<br/> - }<br/> - }<br/> - </code> +<pre><code> +private void appendToList(ArrayList<String> list) { + if (list.size() < 100) { + list.add("Foo"); + } +} +</code></pre> The parameter list is currently defined as an <code>ArrayList</code>, which is a concrete implementation of the <code>List</code> interface. Specifying <code>ArrayList</code> is unnecessary here, because we aren't using any <code>ArrayList</code>-specific methods (like <code>ensureCapacity()</code> or <code>trimToSize()</code>). Instead of using the concrete definition, it is better to do something like:<br/> - <code> - private void appendToList(List<String> list) {<br/> - ...<br/> - </code> +<pre><code> +private void appendToList(List<String> list) { + ... +</code></pre> If the design ever changes, e.g. a <code>LinkedList</code> is used instead, this code won't have to change. </p> @@ -1798,15 +1835,16 @@ <Details> <![CDATA[ <p>This line is in the form of <br/> - <code>String str = ...<br/> - str.equals("someOtherString");<br/> - //or<br/> - str.compareTo("someOtherString");</code></p> +<pre><code>String str = ... +str.equals("someOtherString"); +//or +str.compareTo("someOtherString");</code></pre> + </p> <p>A <code>NullPointerException</code> may occur if the String variable <code>str</code> is <code>null</code>. If instead the code was restructured to<br/> - <code>String str = ...<br/> - "someOtherString".equals(str);<br/> - //or<br/> - "someOtherString".compareTo(str);</code><br/> +<pre><code>String str = ... +"someOtherString".equals(str); +//or +"someOtherString".compareTo(str);</code></pre><br/> that is, call <code>equals()</code> or <code>compareTo()</code> on the string literal, passing the variable as an argument, this exception could never happen as both <code>equals()</code> and <code>compareTo()</code> check for <code>null</code>.</p> @@ -1833,7 +1871,8 @@ <![CDATA[ <p>This class defines a field based on java.util.List, but uses it to some extent like a Set. Since lookup type operations are performed using a linear search for Lists, the performance for large - Lists will be poor. Consider changing this fields implementation to a set based one. If order of + Lists will be poor. If the list is known to only contain a small number of items, (3,4, etc) then it doesn't matter. + Otherwise, consider changing this fields implementation to a set-based one. If order of iteration is important to maintain insert order, perhaps consider a LinkedHashSet.</p> ]]> </Details> @@ -1846,22 +1885,22 @@ <![CDATA[ <p>This class appears to maintain two or more lists or arrays whose contents are related in a parallel way. That is, you have something like:<br/> - <code> - List<String> words = new ArrayList<String>();<br/> - List<Integer> wordCounts = new ArrayList<String>();<br/> - </code> +<pre><code> +List<String> words = new ArrayList<String>(); +List<Integer> wordCounts = new ArrayList<String>(); +</code></pre> where the elements of the list at index 0 are related, the elements at index 1 are related and so on. </p> <p> Consider creating a separate class to hold all the related pieces of information, and adding instances of this class to just one list or array, or if just two values, use a Map to associate one value with the other like:<br/> - <code> - private class WordAndCount{public String word; public int count} - List<WordAndCount> wordsAndCounts = new ArrayList<WordAndCount>();<br/> - <br/> - //or, for just two elements<br/> - Map<String,Integer> wordCounts = new HashMap<String,Integer>();<br/> - </code> +<pre><code> +private class WordAndCount{public String word; public int count} + +List<WordAndCount> wordsAndCounts = new ArrayList<WordAndCount>(); +//or, for just two elements +Map<String,Integer> wordCounts = new HashMap<String,Integer>(); +</code></pre> </p> ]]> @@ -1917,6 +1956,14 @@ math is imprecise, rounding errors will accumulate over time each time the loop is executed. It is usually better to use integer indexing, and calculate the new value of the floating point number at the top of the loop body.</p> + <p>Example: +<pre><code> +for (float f = 1.0f; f <= 10.0f; f += 0.1f) { + System.out.println(f); +} +</code></pre> + The last value printed may not be 10.0, but instead might be 9.900001 or such. + </p> ]]> </Details> </BugPattern> @@ -2002,20 +2049,20 @@ <p>This method passes a primitive value retrieved from a <code>BoxedPrimitive.parseBoxedPrimitive("1")</code> call to the same class's constructor. It is simpler to just pass the string to the BoxedPrimitives constructor or, better yet, use the static valueOf.</p> <p>Instead of something like:<br/> - <code> - Boolean bo = new Boolean(Boolean.parseBoolean("true")); <br/> - Float f = new Float(Float.parseFloat("1.234"));<br/> - </code> +<pre><code> +Boolean bo = new Boolean(Boolean.parseBoolean("true")); +Float f = new Float(Float.parseFloat("1.234")); +</code></pre> Simply do: <br/> - <code> - Boolean bo = new Boolean("true"); <br/> - Float f = new Float("1.234");<br/> - </code> +<pre><code> +Boolean bo = new Boolean("true"); +Float f = new Float("1.234"); +</code></pre> or, to be more memory efficient: <br/> - <code> - Boolean bo = Boolean.valueOf("true"); <br/> - Float f = Float.valueOf("1.234");<br/> - </code> +<pre><code> +Boolean bo = Boolean.valueOf("true"); +Float f = Float.valueOf("1.234"); +</code></pre> </p> ]]> </Details> @@ -2044,21 +2091,21 @@ method. </p> <p>Instead of something like:<br/> - <code> - public int someMethod(String data) {<br/> - long l = Long.valueOf(data).longValue(); <br/> - float f = Float.valueOf(data).floatValue(); <br/> - return Integer.valueOf(data); // There is an implicit .intValue() call<br/> - }<br/> - </code> +<pre><code> +public int someMethod(String data) { +long l = Long.valueOf(data).longValue(); +float f = Float.valueOf(data).floatValue(); +return Integer.valueOf(data); // There is an implicit .intValue() call +} +</code></pre> Simply do: <br/> - <code> - public int someMethod(String data) {<br/> - long l = Long.parseLong(data); <br/> - float f = Float.parseFloat(data); <br/> - return Integer.parseInt(data); <br/> - }<br/> - </code> +<pre><code> +public int someMethod(String data) { + long l = Long.parseLong(data); + float f = Float.parseFloat(data); + return Integer.parseInt(data); +} +</code></pre> </p> ]]> @@ -2075,15 +2122,15 @@ to a boxed primitive object, it is simpler to use the BoxedPrimitive.valueOf(String) method.</p> <p>Instead of something like:<br/> - <code> - Boolean bo = Boolean.valueOf(Boolean.parseBoolean("true")); <br/> - Float f = Float.valueOf(Float.parseFloat("1.234"));<br/> - </code> +<pre><code> +Boolean bo = Boolean.valueOf(Boolean.parseBoolean("true")); +Float f = Float.valueOf(Float.parseFloat("1.234")); +</code></pre> Simply do: <br/> - <code> - Boolean bo = Boolean.valueOf("true"); <br/> - Float f = Float.valueOf("1.234");<br/> - </code> +<pre><code> +Boolean bo = Boolean.valueOf("true"); +Float f = Float.valueOf("1.234"); +</code></pre> </p> ]]> </Details> @@ -2097,15 +2144,15 @@ <p>This method constructs a Boxed Primitive from a primitive only to call the primitiveValue() method to convert it back to a primitive. Just use the primitive value instead.</p> <p>Instead of something like:<br/> - <code> - boolean bo = new Boolean(true).booleanValue(); <br/> - float f = new Float(1.234f).floatValue();<br/> - </code> +<pre><code> +boolean bo = new Boolean(true).booleanValue(); +float f = new Float(1.234f).floatValue(); +</code></pre> Simply do: <br/> - <code> - boolean bo = true; <br/> - float f = 1.234f;<br/> - </code> +<pre><code> +boolean bo = true; +float f = 1.234f; +</code></pre> </p> ]]> @@ -2120,21 +2167,21 @@ <p>This method constructs a Boxed Primitive from a primitive only to call the primitiveValue() method to cast the value to another primitive type. It is simpler to just use casting.</p> <p>Instead of something like:<br/> - <code> - double someDouble = ...<br/> - float f = new Double(someDouble).floatValue();<br/> - <br/> - int someInt = ...<br/> - byte b = new Integer(someInt).byteValue();<br/> - </code> +<pre><code> +double someDouble = ... +float f = new Double(someDouble).floatValue(); + +int someInt = ... +byte b = new Integer(someInt).byteValue(); +</code></pre> Simply do: <br/> - <code> - double someDouble = ...<br/> - float f = (float) someDouble;<br/> - <br/> - int someInt = ...<br/> - byte b = (byte)someInt;<br/> - </code> +<pre><code> +double someDouble = ... +float f = (float) someDouble; + +int someInt = ... +byte b = (byte)someInt; +</code></pre> </p> ]]> </Details> @@ -2147,37 +2194,37 @@ <![CDATA[ <p>This method assigns a Boxed boolean constant to a primitive boolean variable, or assigns a primitive boolean constant to a Boxed boolean variable. Use the correct constant for the variable desired. Use <br/> - <code> - boolean b = true;<br/> - boolean b = false;<br/> - </code> +<pre><code> +boolean b = true; +boolean b = false; +</code></pre> or <br/> - <code> - Boolean b = Boolean.TRUE;<br/> - Boolean b = Boolean.FALSE; - </code> +<pre><code> +Boolean b = Boolean.TRUE; +Boolean b = Boolean.FALSE; +</code></pre> </p> <p>Be aware that this boxing happens automatically when you might not expect it. For example, <br/> - <code> - Map<String, Boolean> statusMap = ... <br/> - <br/> - public Boolean someMethod() {<br/> - statusMap.put("foo", true); //the "true" here is boxed<br/> - return false; //the "false" here is boxed<br/> - }<br/> - </code> +<pre><code> +Map<String, Boolean> statusMap = ... + +public Boolean someMethod() { + statusMap.put("foo", true); //the "true" here is boxed + return false; //the "false" here is boxed +} +</code></pre> has two cases of this needless autoboxing. This can be made more efficient by simply substituting in the constant values: <br/> - <code> - Map<String, Boolean> statusMap = ... <br/> - <br/> - public Boolean someMethod() {<br/> - statusMap.put("foo", Boolean.TRUE); <br/> - return Boolean.FALSE; <br/> - }<br/> - </code> +<pre><code> +Map<String, Boolean> statusMap = ... + +public Boolean someMethod() { + statusMap.put("foo", Boolean.TRUE); + return Boolean.FALSE; +} +</code></pre> </p> ]]> </Details> @@ -2193,26 +2240,29 @@ assigned to the local variable, directly.</p> <p> Instead of the following: <br/> - <code> - public float average(int[] arr) { <br/> - float sum = 0;<br/> - for (int i = 0; i < arr.length; i++) {<br/> - sum += arr[i];<br/> - }<br/> - float ave = sum / arr.length;<br/> - return ave;<br/> - }<br/> - </code> - simply change the method to return the result of the division: <br/> - <code> - public float average(int[] arr) {<br/> - float sum = 0;<br/> - for (int i = 0; i < arr.length; i++) {<br/> - sum += arr[i];<br/> - }<br/> - <b>return sum / arr.length;</b><br/> - } - </code> + +<pre><code> +public float average(int[] arr) { + float sum = 0; + for (int i = 0; i < arr.length; i++) { + sum += arr[i]; + } + float ave = sum / arr.length; + return ave; +} +</code></pre> + + Simply change the method to return the result of the division: <br/> + +<pre><code> +public float average(int[] arr) { + float sum = 0; + for (int i = 0; i < arr.length; i++) { + sum += arr[i]; + } + <b>return sum / arr.length;</b> //Change +} +</code></pre> </p> ]]> </Details> @@ -2373,31 +2423,40 @@ <![CDATA[ <p>This method compares dates with two comparisons, rather than using the reverse comparison. So this pattern</p> - <code> - if ((date1.equals( date2 )) || (date1.after( date2 )))<br/> - </code> + +<pre><code> +if ((date1.equals( date2 )) || (date1.after( date2 ))) +</code></pre> + could become:<br/> - <code> - if (date1.compareTo( date2 ) >= 0) <br/> - </code> - <br/> + +<pre><code> +if (date1.compareTo( date2 ) >= 0) +</code></pre><br/> + and<br/> - <code> - if ((date1.equals( date2 )) || (date1.before( date2 ))) <br/> - </code> + +<pre><code> +if ((date1.equals( date2 )) || (date1.before( date2 ))) +</code></pre> + could become <br/> - <code> - if (date1.compareTo( date2 ) <= 0) <br/> - </code> - <br/> + +<pre><code> +if (date1.compareTo( date2 ) <= 0) +</code></pre><br/> + and<br/> - <code> - if ((date1.before( date2 )) || (date1.after( date2 ))) <br/> - </code> + +<pre><code> +if ((date1.before( date2 )) || (date1.after( date2 ))) +</code></pre> + could become<br/> - <code> - if (!date1.equals( date2 ))<br/> - </code> + +<pre><code> +if (!date1.equals( date2 )) +</code></pre> ]]> </Details> </BugPattern> @@ -2440,17 +2499,17 @@ a potential cause of memory bloat.</p> <p> - If this collection is a list, set or otherwise of static things (e.g. a List<String> for month names), consider + If this collection is a list, set or otherwise of static things (e.g. a List>String> for month names), consider adding all of the elements in a static initializer, which can only be called once:<br/> - <code> - private static List<String> monthNames = new ArrayList<String>();<br/> - static {<br/> - monthNames.add("January");<br/> - monthNames.add("February");<br/> - monthNames.add("March");<br/> - ...<br/> - } - </code> +<pre><code> +private static List<String> monthNames = new ArrayList<String>(); +static { + monthNames.add("January"); + monthNames.add("February"); + monthNames.add("March"); + ... +} +</code></pre> </p> ]]> @@ -2715,7 +2774,15 @@ <p>This method catches an exception, and throws a different exception, without incorporating the original exception. Doing so hides the original source of the exception making debugging and fixing these problems difficult. It is better to use the constructor of this new exception that takes an - original exception so that this detail can be passed along to the user.</p> + original exception so that this detail can be passed along to the user. If this exception has no constructor + that takes an initial cause parameter, use the initCause method to initialize it instead.</p> + <p> +<pre><code> +catch (IOException e) { + throw new MySpecialException("Failed to open configuration", e); +} +</code></pre> + </p> ]]> </Details> </BugPattern> @@ -2731,26 +2798,26 @@ <p> Instead of making calls like: <br/> - <code> - String myString = ... <br/> - if (myString.indexOf("e") != -1) {<br/> - int i = myString.lastIndexOf("e");<br/> - System.out.println(myString + ":" + i); //the Java compiler will use a StringBuilder internally here [builder.append(":")]<br/> - ...<br/> - return myString.replace("m","z");<br/> - }<br/> - </code> +<pre><code> +String myString = ... +if (myString.indexOf("e") != -1) { + int i = myString.lastIndexOf("e"); + System.out.println(myString + ":" + i); //the Java compiler will use a StringBuilder internally here [builder.append(":")] + ... + return myString.replace("m","z"); +} +</code></pre> Replace the single letter <code>String</code>s with their <code>char</code> equivalents like so:<br/> - <code> - String myString = ... <br/> - if (myString.indexOf('e') != -1) {<br/> - int i = myString.lastIndexOf('e');<br/> - System.out.println(myString + ':' + i); //the Java compiler will use a StringBuilder internally here [builder.append(':')]<br/> - ...<br/> - return myString.replace('m','z');<br/> - }<br/> - </code> +<pre><code> +String myString = ... +if (myString.indexOf('e') != -1) { + int i = myString.lastIndexOf('e'); + System.out.println(myString + ':' + i); //the Java compiler will use a StringBuilder internally here [builder.append(':')] + ... + return myString.replace('m','z'); +} +</code></pre> </p> ]]> </Details> @@ -2948,13 +3015,13 @@ <p>This method attempts to check for null by just referring to the variable name as would be done in C++. This ordinarily would be considered a compile error, except the variable in question is a Boolean, which does an auto unbox to boolean. - <code><br/> - if (b && b.booleanValue())<br/> - </code> +<pre><code> +if (b && b.booleanValue()) +</code></pre> should be<br/> - <code> - if ((b != null) && b.booleanValue())<br/> - </code> +<pre><code> +if ((b != null) && b.booleanValue()) +</code></pre> </p> ]]> </Details> @@ -2990,27 +3057,27 @@ <![CDATA[ <p>This method tests a string, and groups null values with real strings, leaving empty strings as another case. That is, FindBugs has detected a structure like: <br/> - <code> - String a = null, b = "", c = "someString"; <br/> - ...<br/> - String testStr = ...; //one of a, b or c<br/> - if (<b>FLAWED_TEST_LOGIC</b>) { <br/> - // Strings a and c fall into this branch... which is not typical. <br/> - } else { <br/> - // String b falls into this branch. <br/> - } <br/> - </code> +<pre><code> +String a = null, b = "", c = "someString"; + +String testStr = ...; //one of a, b or c +if ({{FLAWED_TEST_LOGIC}}) { + // Strings a and c fall into this branch... which is not typical. +} else { + // String b falls into this branch. +} +</code></pre> This might be perfectly valid, but normally, null strings and empty strings are logically handled the same way, and so this test may be flawed.</p> <p>Pattern found is one of the following: <ul> - <li><code>if ((s == null) || (s.length() > 0))</code> --- did you mean + <li><code>if ((s == null) || (s.length() > 0))</code> --- did you mean <code>((s == null) || (s.length() == 0))</code>?</li> <li><code>if ((s == null) || (s.length() != 0))</code> -- did you mean <code>((s == null) || (s.length() == 0))</code>? </li> <li><code>if ((s != null) && (s.length() == 0))</code> -- did you mean - <code>((s != null) && (s.length() > 0))</code> or perhaps + <code>((s != null) && (s.length() > 0))</code> or perhaps <code>((s == null) || (s.length() == 0))</code>? </li> </ul> </p> @@ -3171,24 +3238,24 @@ <![CDATA[ <p>This method appends two literal strings to a <code>StringBuilder</code> back to back. Modern compilers will optimize something like:<br/> - <code> - public static final string CONST_VAL = "there";<br/> - ...<br/> - String str = "Hello" + " "+ CONST_VAL + " " +"world!";<br/> - </code> +<pre><code> +public static final string CONST_VAL = "there"; +... +String str = "Hello" + " "+ CONST_VAL + " " +"world!"; +</code></pre> to: <br/> - <code> - public static final string CONST_VAL = "there";<br/> - ...<br/> - String str = "Hello there world!";<br/> - </code> +<pre><code> +public static final string CONST_VAL = "there"; +... +String str = "Hello there world!"; +</code></pre> This means the concatenation is done during compile time, not at runtime, so there's <b>no need</b> to do: <br/> - <code> - public static final string CONST_VAL = "there";<br/> - ...<br/> - StringBuilder sb = new StringBuilder("Hello").append(" ").append(CONST_VAL).append(" ").append("world!");<br/> - String str = sb.toString();<br/> - </code> +<pre><code> +public static final string CONST_VAL = "there"; +... +StringBuilder sb = new StringBuilder("Hello").append(" ").append(CONST_VAL).append(" ").append("world!"); +String str = sb.toString(); +</code></pre> which is harder to read and will result in more complex bytecode. </p> @@ -3242,14 +3309,15 @@ <p> For example, instead of :<br/> - <code> - return "ThisIsAConstantString ".toLowerCase().trim(); <br/> - </code> +<pre><code> +return "ThisIsAConstantString".toLowerCase().trim(); +</code></pre> just do <br/> - <code> - return "thisisaconstantstring"; <br/> - </code> - for shorter and easier to read code. An exception might be made when locale-specific transformations need to be done (in the case of <code>toUpperCase()</code> and <code>toLowerCase()</code>. +<pre><code> +return "thisisaconstantstring"; +</code></pre> + for shorter and easier to read code. An exception might be made when locale-specific transformations need + to be done (in the case of <code>toUpperCase()</code> and <code>toLowerCase()</code>. </p> ]]> </Details> @@ -3361,11 +3429,11 @@ <p>PLEASE NOTE: String.split will return an array of 1 element when passed the empty string, as opposed to using StringTokenizer which returns false on the first hasMoreElements/hasMoreTokens call. So you may need to use:</p> - <code> - if (s.length() > 0) <br/> - return s.split(";");<br/> - return new String[0];<br/> - </code> +<pre><code> +if (s.length() > 0) <br/> + return s.split(";");<br/> +return new String[0];<br/> +</code></pre> ]]> </Details> </BugPattern> @@ -3780,8 +3848,8 @@ </BugPattern> <BugPattern type="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT"> - <ShortDescription>Method modifies http session attribute without calling setAttribute</ShortDescription> - <LongDescription>Method {1} modifies http session attribute without calling setAttribute</LongDescription> + <ShortDescription>Method modifies an http session attribute without calling setAttribute</ShortDescription> + <LongDescription>Method {1} modifies an http session attribute without calling setAttribute</LongDescription> <Details> <![CDATA[ <p>This method fetches a complex object from an HttpSession object, modifies this object, but does @@ -3851,9 +3919,31 @@ <p>This method attempts to use an SLF4J logger to log a parameterized expression using formatting anchors. However, SLF4J uses simple non numbered anchors such as {}, rather than anchors with digits in them as the code uses. Thus no parameter replacement will occur.</p> + <p>This pattern is invalid: + <code>logger.error("{0} is broken", theThing);</code> + Use instead + <code>logger.error("{} is broken", theThing);</code> + </p> ]]> </Details> </BugPattern> + + <BugPattern type="LO_INVALID_STRING_FORMAT_NOTATION"> + <ShortDescription>Method attempts to log using String.format notation</ShortDescription> + <LongDescription>Method {1} attempts to log using String.format notation</LongDescription> + <Details> + <![CDATA[ + <p>This method attempts to use an SLF4J logger to log a parameterized expression using String.format notation. + However, SLF4J uses simple non numbered anchors such as {}, rather than anchors with percent signs in them as the + code uses. Thus no parameter replacement will occur.</p> + <p>This pattern is invalid: + <code>logger.error("%s is broken", theThing);</code> + Use instead + <code>logger.error("{} is broken", theThing);</code> + </p> + ]]> + </Details> + </BugPattern> <BugPattern type="LO_INCORRECT_NUMBER_OF_ANCHOR_PARAMETERS"> <ShortDescription>Method passes an incorrect number of parameters to an SLF4J logging statement</ShortDescription> @@ -4071,6 +4161,21 @@ symmetry rule of equivalence is maintained, that being if a equals b, then b equals a. It does not appear that the class that is being compared to this class knows about this class, and doesn't compare itself to this.</p> + <p> + Here's an example of a BAD equals method, do NOT do this: +<pre><code> +class Person { + public boolean equals(Object o) { + if (o instanceof Person) { + return name.equals(((Person) o).name); + } else if (o instanceof String) { + return name.equals(o); + } + return false; + } +} +</code></pre> + </p> ]]> </Details> </BugPattern> @@ -4083,13 +4188,13 @@ <p>This method contains a contravariant array assignment. Since arrays are mutable data structures, their use must be restricted to covariant or invariant usage.</p> - <code> - class A {}<br/> - class B extends A {}<br/> - <br/> - B[] b = new B[2];<br/> - A[] a = b;<br/> - </code> +<pre><code> +class A {} +class B extends A {} + +B[] b = new B[2]; +A[] a = b; +</code></pre> ]]> </Details> </BugPattern> @@ -4102,14 +4207,14 @@ <p>This method contains a contravariant array element assignment. Since arrays are mutable data structures, their use must be restricted to covariant or invariant usage.</p> - <code> - class A {}<br/> - class B extends A {}<br/> - <br/> - B[] b = new B[2];<br/> - A[] a = b;<br/> - a[0] = new A(); // results in ArrayStoreException (Runtime)<br/> - </code> +<pre><code> +class A {} +class B extends A {} + +B[] b = new B[2]; +A[] a = b; +a[0] = new A(); // results in ArrayStoreException (Runtime) +</code></pre> ]]> </Details> </BugPattern> @@ -4135,6 +4240,14 @@ <p>This method tests a field to make sure it's not null before executing a conditional block of code. However in the conditional block it reassigns the field. It is likely that the guard should have been a check to see if the field is null, not that the field was not null.</p> + <p>example: +<pre><code> +if (name != null) { + name = person.getName(); +} +</code></pre> + It is possible this is correct, but it seems likely the guard was meant to be <code>if (name == null)</code> + </p> ]]> ... [truncated message content] |