[Fb-contrib-commit] SF.net SVN: fb-contrib:[1748] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2013-07-14 19:23:11
|
Revision: 1748
http://sourceforge.net/p/fb-contrib/code/1748
Author: dbrosius
Date: 2013-07-14 19:23:07 +0000 (Sun, 14 Jul 2013)
Log Message:
-----------
sync from github: prepare for version 4.8.4
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/pom.xml
trunk/fb-contrib/samples/FCBL_Sample.java
trunk/fb-contrib/samples/samples.fbp
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java
Added Paths:
-----------
trunk/fb-contrib/samples/AIOB_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/build.xml 2013-07-14 19:23:07 UTC (rev 1748)
@@ -17,7 +17,7 @@
<property name="javac.deprecation" value="on" />
<property name="javac.debug" value="on" />
- <property name="fb-contrib.version" value="4.9.0" />
+ <property name="fb-contrib.version" value="4.8.4" />
<property name="sonatype.dir" value="${user.home}/.fb-contrib-${fb-contrib.version}-sonatype" />
@@ -182,6 +182,7 @@
<attribute name="Bundle-Vendor" value="FB-Contrib Project" />
<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.collect, com.mebigfatguy.fbcontrib.detect" />
</manifest>
</jar>
</target>
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/etc/findbugs.xml 2013-07-14 19:23:07 UTC (rev 1748)
@@ -30,9 +30,9 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.UnrelatedCollectionContents" speed="fast" reports="UCC_UNRELATED_COLLECTION_CONTENTS" />
<Detector class="com.mebigfatguy.fbcontrib.detect.DeclaredRuntimeException" speed="fast" reports="DRE_DECLARED_RUNTIME_EXCEPTION" />
-<!-- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE
<Detector class="com.mebigfatguy.fbcontrib.detect.ClassEnvy" speed="fast" reports="CE_CLASS_ENVY" disabled="true" />
-<!-- COMMENT OUT FOR RELEASE -->
+ COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.detect.LiteralStringComparison" speed="fast" reports="LSC_LITERAL_STRING_COMPARISON" />
<Detector class="com.mebigfatguy.fbcontrib.detect.PartiallyConstructedObjectAccess" speed="fast" reports="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" />
@@ -73,9 +73,9 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.AbstractOverriddenMethod" speed="fast" reports="AOM_ABSTRACT_OVERRIDDEN_METHOD" />
<Detector class="com.mebigfatguy.fbcontrib.detect.CustomBuiltXML" speed="fast" reports="CBX_CUSTOM_BUILT_XML" />
-<!-- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedSynchronizedBlock" speed="fast" reports="BSB_BLOATED_SYNCHRONIZED_BLOCK" hidden="true" />
-<!-- COMMENT OUT FOR RELEASE -->
+ COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.detect.ConstantListIndex" speed="fast" reports="CLI_CONSTANT_LIST_INDEX" />
<Detector class="com.mebigfatguy.fbcontrib.detect.SloppyClassReflection" speed="fast" reports="SCR_SLOPPY_CLASS_REFLECTION" />
@@ -176,9 +176,9 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryNewNullCheck" speed="fast" reports="UNNC_UNNECESSARY_NEW_NULL_CHECK" />
<Detector class="com.mebigfatguy.fbcontrib.detect.DeprecatedTypesafeEnumPattern" speed="fast" reports="DTEP_DEPRECATED_TYPESAFE_ENUM_PATTERN" />
-<!-- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE
<Detector class="com.mebigfatguy.fbcontrib.detect.StutteredMethodArguments" speed="fast" reports="SMA_STUTTERED_METHOD_ARGUMENTS" hidden="true" />
-<!-- COMMENT OUT FOR RELEASE -->
+ COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.detect.TristateBooleanPattern" speed="fast" reports="TBP_TRISTATE_BOOLEAN_PATTERN" />
@@ -193,9 +193,9 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.PoorlyDefinedParameter" speed="fast" reports="PDP_POORLY_DEFINED_PARAMETER" />
<Detector class="com.mebigfatguy.fbcontrib.detect.NonSymmetricEquals" speed="fast" reports="NSE_NON_SYMMETRIC_EQUALS" />
-<!-- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE
<Detector class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment" speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" />
-<!-- COMMENT OUT FOR RELEASE -->
+ COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField" speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
@@ -221,9 +221,9 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousGetterSetterUse" speed="fast" reports="SGSU_SUSPICIOUS_GETTER_SETTER_USE" />
<Detector class="com.mebigfatguy.fbcontrib.detect.LingeringGraphicsObjects" speed="fast" reports="LGO_LINGERING_GRAPHICS_OBJECT" />
-<!-- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE
<Detector class="com.mebigfatguy.fbcontrib.detect.StackedTryBlocks" speed="fast" reports="STB_STACKED_TRY_BLOCKS" />
-<!-- COMMENT OUT FOR RELEASE -->
+ COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.detect.CommonsEqualsBuilderToEquals" speed="fast" reports="CEBE_COMMONS_EQUALS_BUILDER_ISEQUALS" />
<Detector class="com.mebigfatguy.fbcontrib.detect.CommonsHashcodeBuilderToHashcode" speed="fast" reports="CHTH_COMMONS_HASHCODE_BUILDER_TOHASHCODE" />
@@ -235,7 +235,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.BackportReusePublicIdentifiers" speed="fast" reports="BRPI_BACKPORT_REUSE_PUBLIC_IDENTIFIERS" />
<Detector class="com.mebigfatguy.fbcontrib.detect.CloneUsability" speed="fast" reports="CU_CLONE_USABILITY_OBJECT_RETURN,CU_CLONE_USABILITY_MISMATCHED_RETURN,CU_CLONE_USABILITY_THROWS" />
-
+<!-- COMMENT OUT FOR RELEASE
<Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingArrayAsList" speed="fast" reports="CAAL_CONFUSING_ARRAY_AS_LIST" />
<Detector class="com.mebigfatguy.fbcontrib.detect.PresizeCollections" speed="fast" reports="PSC_PRESIZE_COLLECTIONS" />
@@ -244,6 +244,8 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NonProductiveMethodCall" speed="fast" reports="NPMC_NON_PRODUCTIVE_METHOD_CALL" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ArrayIndexOutOfBounds" speed="fast" reports="AIOB_ARRAY_INDEX_OUT_OF_BOUNDS,AIOB_ARRAY_STORE_TO_NULL_REFERENCE" />
+-->
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -430,4 +432,6 @@
<BugPattern abbrev="PSC" type="PSC_PRESIZE_COLLECTIONS" category="PERFORMANCE" />
<BugPattern abbrev="UMTP" type="UMTP_UNBOUND_METHOD_TEMPLATE_PARAMETER" category="CORRECTNESS" />
<BugPattern abbrev="NPMC" type="NPMC_NON_PRODUCTIVE_METHOD_CALL" category="CORRECTNESS" />
+ <BugPattern abbrev="AIOB" type="AIOB_ARRAY_INDEX_OUT_OF_BOUNDS" category="CORRECTNESS" />
+ <BugPattern abbrev="AIOB" type="AIOB_ARRAY_STORE_TO_NULL_REFERENCE" category="CORRECTNESS" />
</FindbugsPlugin>
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/etc/messages.xml 2013-07-14 19:23:07 UTC (rev 1748)
@@ -40,7 +40,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SyncCollectionIterators">
<Details>
<![CDATA[
- <p> Looks for use of iterators on synchronized collections built from the Collections class</p>
+ <p> Looks for use of iterators on synchronized collections built from the java.util.Collections class</p>
<p> As the collection in question was built thru Collections.synchronizedXXX, an assumption
is made that this collection must be multithreaded safe. However, iterator access is used,
which is explicitly unsafe. When iterators are to be used, synchronization should be done manually.</p>
@@ -319,7 +319,8 @@
<Details>
<![CDATA[
<p>Looks for methods that store the return result in a local variable and
- then immediately returns that local variable.</p>
+ then immediately returns that local variable. It is simpler to just return
+ the method (or assignment) result directly.</p>
<p>It is a fast detector</p>
]]>
</Details>
@@ -350,7 +351,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.OrphanedDOMNode">
<Details>
<![CDATA[
- <p>Looks for methods that create DOM Nodes but do not add them to any DOM Document.</p>
+ <p>Looks for methods that create DOM nodes but do not add them to any DOM Document.</p>
<p>It is a fast Detector</p>
]]>
</Details>
@@ -1332,7 +1333,24 @@
</Details>
</Detector>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ArrayIndexOutOfBounds">
+ <Details>
+ <![CDATA[
+ <p>Looks for questionable load/stores to array elements.<ul>
+ <li>
+ Looks for accesses to array elements using literal values that are known to be outside the bounds of the array.
+ This mistake will cause an ArrayIndexOutOfBoundsException to occur at runtime.</li>
+ <li>
+ Looks for stores to array elements where the array itself appears to have not been allocated.
+ </li>
+ </ul>
+ </p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
<!-- BugPattern -->
<BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING">
@@ -3484,7 +3502,7 @@
<p>This method serializes an instance of a non-static inner class. Since this class has a
reference to the containing class, this outer class will be serialized as well. This is often
not intentional, and will make the amount of data that is serialized much more than is needed.
- If the outer classes is not desired to be serialized, either make the inner class, static, or
+ If the outer classes is not desired to be serialized, either make the inner class static, or
pull it out into a separate "first class" class.
]]>
</Details>
@@ -3593,7 +3611,7 @@
<LongDescription>Method {1} backport concurrency utils</LongDescription>
<Details>
<![CDATA[
- <p> This class usees Backport Utils concurrent classes. Updated/Efficient version of these
+ <p> This class uses Backport Utils concurrent classes. Updated/Efficient version of these
classes are available in versions of the JDK 5.0 and higher, and these
classes should only be used if you are targeting JDK 1.4 and lower.
</p>
@@ -3633,7 +3651,7 @@
<![CDATA[
<p> This class implements the Cloneable interface but defines its clone method to still return
a CloneNotSupportedException. Since you are implementing clone() it would make sense that the method
- in question will _not_ throw that exception, so annotating your method with it just makes client use
+ in question will <em>not</em> throw that exception, so annotating your method with it just makes client use
of your more painful as they have to handle an exception that will never happen. Just remove the
throws clause from your method.
</p>
@@ -3691,6 +3709,27 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="AIOB_ARRAY_INDEX_OUT_OF_BOUNDS">
+ <ShortDescription>Method attempts to access an array element outside the array's size</ShortDescription>
+ <LongDescription>Method {1} attempts to access an array element outside the array's size</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method access an array element using a literal index that is know to be outside the size of the specified
+ array. This will cause an ArrayIndexOutOfBoundsException at runtime</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="AIOB_ARRAY_STORE_TO_NULL_REFERENCE">
+ <ShortDescription>Method attempts to store an array element to an array that does not appear to be allocated</ShortDescription>
+ <LongDescription>Method {1} attempts to store an array element to an array that does not appear to be allocated</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method attempts to store an array element into an an array that appears to not have been allocated.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3804,4 +3843,5 @@
<BugCode abbrev="PSC">Presize Collection</BugCode>
<BugCode abbrev="UMTP">Unbound Method Template Parameter</BugCode>
<BugCode abbrev="NPMC">Non Productive Method Call</BugCode>
+ <BugCode abbrev="AIOB">Array Index Out of Bounds</BugCode>
</MessageCollection>
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/htdocs/index.shtml 2013-07-14 19:23:07 UTC (rev 1748)
@@ -107,6 +107,16 @@
is discarded. Since the method makes no changes to the object, calling this method
is useless. The method call can be removed.
</li>
+ <li><b>[AIOB] Array Index Out of Bounds</b><br/>
+ Looks for questionable load/stores to array elements.<ul>
+ <li>
+ Looks for accesses to array elements using literal values that are known to be outside the bounds of the array.
+ This mistake will cause an ArrayIndexOutOfBoundsException to occur at runtime.</li>
+ <li>
+ Looks for stores to array elements where the array itself appears to have not been allocated.
+ </li>
+ </ul>
+ </li>
</ul>
</div>
<hr/>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/pom.xml 2013-07-14 19:23:07 UTC (rev 1748)
@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>4.9.0</version>
+ <version>4.8.4</version>
<parent>
<groupId>org.sonatype.oss</groupId>
Added: trunk/fb-contrib/samples/AIOB_Sample.java
===================================================================
--- trunk/fb-contrib/samples/AIOB_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/AIOB_Sample.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -0,0 +1,22 @@
+
+public class AIOB_Sample
+{
+ int[] fa = new int[4];
+ int[] fb;
+
+ public void testOutOfBounds()
+ {
+ int[] a = new int[4];
+
+ a[4] = 2;
+ fa[4] = 2;
+ }
+
+ public void testUnallocated()
+ {
+ int[] b = null;
+
+ b[4] = 4;
+ fb[4] = 4;
+ }
+}
Property changes on: trunk/fb-contrib/samples/AIOB_Sample.java
___________________________________________________________________
Added: svn:eol
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/fb-contrib/samples/FCBL_Sample.java
===================================================================
--- trunk/fb-contrib/samples/FCBL_Sample.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/samples/FCBL_Sample.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -7,6 +7,7 @@
protected int boo;
int hoo;
private int fp;
+ private int multiMethodFP;
private String test;
private int x = 1;
private int y = 2;
@@ -57,4 +58,17 @@
test = "woowoo";
}
+
+ public void mm1FP(int i) {
+ multiMethodFP = i;
+ mm2FP(3);
+
+ if (multiMethodFP == i) {
+ System.out.println("FP");
+ }
+ }
+
+ public void mm2FP(int i) {
+ multiMethodFP = i;
+ }
}
Modified: trunk/fb-contrib/samples/samples.fbp
===================================================================
--- trunk/fb-contrib/samples/samples.fbp 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/samples/samples.fbp 2013-07-14 19:23:07 UTC (rev 1748)
@@ -1,10 +1,12 @@
<Project projectName="sample">
- <Jar>.</Jar>
- <AuxClasspathEntry>./lib/jsp-api-2.2.1.jar</AuxClasspathEntry>
- <AuxClasspathEntry>./lib/junit-4.10.jar</AuxClasspathEntry>
- <AuxClasspathEntry>./lib/log4j-1.2.16.jar</AuxClasspathEntry>
- <AuxClasspathEntry>./lib/servlet-api-3.0.1.jar</AuxClasspathEntry>
- <SrcDir>.</SrcDir>
+ <Jar>./.</Jar>
+ <AuxClasspathEntry>././lib/jsp-api-2.2.1.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>././lib/junit-4.10.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>././lib/log4j-1.2.16.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>././lib/servlet-api-3.0.1.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./lib/commons-lang3-3.1.jar</AuxClasspathEntry>
+ <AuxClasspathEntry>./lib/backport-util-concurrent-3.1.jar</AuxClasspathEntry>
+ <SrcDir>./.</SrcDir>
<SuppressionFilter>
<LastVersion value="-1" relOp="NEQ"/>
</SuppressionFilter>
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -0,0 +1,197 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2013 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.fbcontrib.detect;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.Constant;
+import org.apache.bcel.classfile.ConstantInteger;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.Type;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+public class ArrayIndexOutOfBounds extends BytecodeScanningDetector {
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ private Set<Integer> initializedRegs;
+
+ /**
+ * constructs an AIOB detector given the reporter to report bugs on
+
+ * @param bugReporter the sync of bug reports
+ */
+ public ArrayIndexOutOfBounds(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ initializedRegs = new HashSet<Integer>();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ initializedRegs = null;
+ }
+ }
+
+ public void visitCode(Code obj) {
+ Method m = getMethod();
+ stack.resetForMethodEntry(this);
+ initializedRegs.clear();
+ Type[] argTypes = m.getArgumentTypes();
+ int arg = ((m.getAccessFlags() & Constants.ACC_STATIC) != 0) ? 0 : 1;
+ for (Type argType : argTypes) {
+ String argSig = argType.getSignature();
+ initializedRegs.add(Integer.valueOf(arg));
+ arg += ("J".equals(argSig) || "D".equals(argSig)) ? 2 : 1;
+ }
+ super.visitCode(obj);
+
+ initializedRegs.clear();
+ }
+
+ public void sawOpcode(int seen) {
+ Integer size = null;
+ try {
+ switch (seen) {
+ case ICONST_0:
+ case ICONST_1:
+ case ICONST_2:
+ case ICONST_3:
+ case ICONST_4:
+ case ICONST_5:
+ size = Integer.valueOf(seen - ICONST_0);
+ break;
+
+ case BIPUSH:
+ case SIPUSH:
+ size = getIntConstant();
+ break;
+
+ case LDC:
+ Constant c = getConstantRefOperand();
+ if (c instanceof ConstantInteger) {
+ size = Integer.valueOf(((ConstantInteger) c).getBytes());
+ }
+ break;
+
+ case NEWARRAY:
+ case ANEWARRAY:
+ if (stack.getStackDepth() >= 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ size = (Integer) item.getUserValue();
+ }
+ break;
+
+ case IASTORE:
+ case LASTORE:
+ case FASTORE:
+ case DASTORE:
+ case AASTORE:
+ case BASTORE:
+ case CASTORE:
+ case SASTORE:
+ if (stack.getStackDepth() >= 3) {
+ OpcodeStack.Item indexItem = stack.getStackItem(1);
+ Integer index = (Integer) indexItem.getConstant();
+ if (index != null) {
+ OpcodeStack.Item arrayItem = stack.getStackItem(2);
+ Integer sz = (Integer) arrayItem.getUserValue();
+ if (sz != null) {
+ if (index.intValue() >= sz.intValue()) {
+ bugReporter.reportBug(new BugInstance(this, "AIOB_ARRAY_INDEX_OUT_OF_BOUNDS", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+
+ int reg = arrayItem.getRegisterNumber();
+ if ((reg >= 0) && !initializedRegs.contains(Integer.valueOf(reg))) {
+ bugReporter.reportBug(new BugInstance(this, "AIOB_ARRAY_STORE_TO_NULL_REFERENCE", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ break;
+
+ case IALOAD:
+ case LALOAD:
+ case FALOAD:
+ case DALOAD:
+ case AALOAD:
+ case BALOAD:
+ case CALOAD:
+ case SALOAD:
+ if (stack.getStackDepth() >= 2) {
+ OpcodeStack.Item indexItem = stack.getStackItem(0);
+ Integer index = (Integer) indexItem.getConstant();
+ if (index != null) {
+ OpcodeStack.Item arrayItem = stack.getStackItem(1);
+ Integer sz = (Integer) arrayItem.getUserValue();
+ if (sz != null) {
+ if (index.intValue() >= sz.intValue()) {
+ bugReporter.reportBug(new BugInstance(this, "AIOB_ARRAY_INDEX_OUT_OF_BOUNDS", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+ break;
+
+ case ASTORE_0:
+ case ASTORE_1:
+ case ASTORE_2:
+ case ASTORE_3:
+ case ASTORE:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item value = stack.getStackItem(0);
+ if (!value.isNull())
+ initializedRegs.add(Integer.valueOf(getRegisterOperand()));
+ } else {
+ initializedRegs.add(Integer.valueOf(getRegisterOperand()));
+ }
+ break;
+ }
+
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (size != null) {
+ if (stack.getStackDepth() >= 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(size);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayIndexOutOfBounds.java
___________________________________________________________________
Added: svn:eol
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -54,6 +54,7 @@
dangerousAssignmentClassSources.add("java/io/InputStream");
dangerousAssignmentClassSources.add("java/io/ObjectInput");
dangerousAssignmentMethodSources.add("java/lang/System.currentTimeMillis()J");
+ dangerousAssignmentMethodSources.add("java/lang/System.nanoTime()J");
dangerousAssignmentMethodSources.add("java/util/Iterator.next()Ljava/lang/Object;");
dangerousAssignmentMethodSources.add("java/util/regex/Matcher.start()I");
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CommonsStringBuilderToString.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -117,9 +117,11 @@
si = stack.getStackItem(0);
signature = si.getSignature();
if (isToStringBuilder(signature)) {
- Pair p = stackTracker.pop();
- registerTracker.put(Integer.valueOf(p.register),
- Boolean.valueOf(p.appendInvoked));
+ if (!stackTracker.isEmpty()) {
+ Pair p = stackTracker.pop();
+ registerTracker.put(Integer.valueOf(p.register),
+ Boolean.valueOf(p.appendInvoked));
+ }
}
break;
case INVOKESPECIAL:
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -82,13 +82,14 @@
}
private static final Map<String, Integer> modifyingMethods = new HashMap<String, Integer>();
static {
- modifyingMethods.put("add(Ljava/lang/Object;)Z", Integer.valueOf(1));
- modifyingMethods.put("addAll(Ljava/util/Collection;)Z", Integer.valueOf(1));
+ Integer ONE = Integer.valueOf(1);
+ modifyingMethods.put("add(Ljava/lang/Object;)Z", ONE);
+ modifyingMethods.put("addAll(Ljava/util/Collection;)Z", ONE);
modifyingMethods.put("addAll(ILjava/util/Collection;)Z", Integer.valueOf(2));
modifyingMethods.put("clear()V", Integer.valueOf(0));
- modifyingMethods.put("remove(I)Ljava/lang/Object;", Integer.valueOf(1));
- modifyingMethods.put("removeAll(Ljava/util/Collection;)Z", Integer.valueOf(1));
- modifyingMethods.put("retainAll(Ljava/util/Collection;)Z", Integer.valueOf(1));
+ modifyingMethods.put("remove(I)Ljava/lang/Object;", ONE);
+ modifyingMethods.put("removeAll(Ljava/util/Collection;)Z", ONE);
+ modifyingMethods.put("retainAll(Ljava/util/Collection;)Z", ONE);
}
private BugReporter bugReporter;
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -365,7 +365,7 @@
@Override
public String toString() {
- return basicBlock.toString() + "|" + uncheckedFields;
+ return basicBlock + "|" + uncheckedFields;
}
}
}
\ No newline at end of file
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -85,10 +85,10 @@
if (seen == INVOKESPECIAL) {
String calledClass = getClassConstantOperand();
- String signature = getSigConstantOperand();
if (("java/lang/StringBuffer".equals(calledClass)
|| "java/lang/StringBuilder".equals(calledClass))
&& "<init>".equals(getNameConstantOperand())) {
+ String signature = getSigConstantOperand();
if ("()V".equals(signature)) {
OpcodeStack.Item itm = getStringBufferItemAt(2);
if (itm != null) {
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -269,7 +269,7 @@
} else if ("(Ljava/lang/Object;)V".equals(sig)) {
if (stack.getStackDepth() > 0) {
final JavaClass clazz = stack.getStackItem(0).getJavaClass();
- if(clazz.instanceOf(THROWABLE_CLASS)) {
+ if((clazz != null) && clazz.instanceOf(THROWABLE_CLASS)) {
bugReporter.reportBug(new BugInstance(this, "LO_LOGGER_LOST_EXCEPTION_STACK_TRACE", NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -77,6 +77,7 @@
riskyMethodNameContents.add("close");
riskyMethodNameContents.add("copy");
riskyMethodNameContents.add("currentTimeMillis");
+ riskyMethodNameContents.add("nanoTime");
riskyMethodNameContents.add("newInstance");
riskyMethodNameContents.add("noneOf");
riskyMethodNameContents.add("allOf");
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -235,36 +235,40 @@
byte[] bytes = getCode().getCode();
if (lastPCs[1] != -1) {
- int loadIns = CodeByteUtils.getbyte(bytes, lastPCs[2]);
- if ((CodeByteUtils.getbyte(bytes, lastPCs[3]) == INVOKEVIRTUAL)
- && ((loadIns == LDC) || (loadIns == LDC_W))
- && (CodeByteUtils.getbyte(bytes, lastPCs[1]) == INVOKEVIRTUAL)) {
- ConstantPool pool = getConstantPool();
- int toStringIndex = CodeByteUtils.getshort(bytes, lastPCs[1]+1);
- ConstantMethodref toStringMR = (ConstantMethodref)pool.getConstant(toStringIndex);
- String toStringCls = toStringMR.getClass(pool);
- if (toStringCls.startsWith("java.lang.StringBu")) {
- int consIndex = CodeByteUtils.getbyte(bytes, lastPCs[2]+1);
- Constant c = pool.getConstant(consIndex);
- if (c instanceof ConstantString) {
- if ("".equals(((ConstantString) c).getBytes(pool))) {
- int nandtIndex = toStringMR.getNameAndTypeIndex();
- ConstantNameAndType cnt = (ConstantNameAndType)pool.getConstant(nandtIndex);
- if ("toString".equals(cnt.getName(pool))) {
- int lengthIndex = CodeByteUtils.getshort(bytes, lastPCs[3]+1);
- ConstantMethodref lengthMR = (ConstantMethodref)pool.getConstant(lengthIndex);
- nandtIndex = lengthMR.getNameAndTypeIndex();
- cnt = (ConstantNameAndType)pool.getConstant(nandtIndex);
- if ("equals".equals(cnt.getName(pool))) {
- bugReporter.reportBug(new BugInstance(this, "SPP_USE_STRINGBUILDER_LENGTH", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
- }
- }
- }
- }
- }
+ if (CodeByteUtils.getbyte(bytes, lastPCs[3]) == INVOKEVIRTUAL) {
+ int loadIns = CodeByteUtils.getbyte(bytes, lastPCs[2]);
+ if (((loadIns == LDC) || (loadIns == LDC_W))
+ && (CodeByteUtils.getbyte(bytes, lastPCs[1]) == INVOKEVIRTUAL)) {
+ ConstantPool pool = getConstantPool();
+ int toStringIndex = CodeByteUtils.getshort(bytes, lastPCs[1]+1);
+ Constant cmr = pool.getConstant(toStringIndex);
+ if (cmr instanceof ConstantMethodref) {
+ ConstantMethodref toStringMR = (ConstantMethodref)cmr;
+ String toStringCls = toStringMR.getClass(pool);
+ if (toStringCls.startsWith("java.lang.&&StringBu")) {
+ int consIndex = CodeByteUtils.getbyte(bytes, lastPCs[2]+1);
+ Constant c = pool.getConstant(consIndex);
+ if (c instanceof ConstantString) {
+ if ("".equals(((ConstantString) c).getBytes(pool))) {
+ int nandtIndex = toStringMR.getNameAndTypeIndex();
+ ConstantNameAndType cnt = (ConstantNameAndType)pool.getConstant(nandtIndex);
+ if ("toString".equals(cnt.getName(pool))) {
+ int lengthIndex = CodeByteUtils.getshort(bytes, lastPCs[3]+1);
+ ConstantMethodref lengthMR = (ConstantMethodref)pool.getConstant(lengthIndex);
+ nandtIndex = lengthMR.getNameAndTypeIndex();
+ cnt = (ConstantNameAndType)pool.getConstant(nandtIndex);
+ if ("equals".equals(cnt.getName(pool))) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_USE_STRINGBUILDER_LENGTH", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
}
} else if ((seen == IRETURN) && lastIfEqWasBoolean) {
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2013-06-01 19:30:46 UTC (rev 1747)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2013-07-14 19:23:07 UTC (rev 1748)
@@ -214,6 +214,10 @@
}
state = State.SEEN_NOTHING;
break;
+
+ case SEEN_ARRAYSTORE:
+ case SEEN_NEWARRAY:
+ break;
}
} finally {
TernaryPatcher.pre(stack, seen);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|