fb-contrib-commit Mailing List for fb-contrib (Page 52)
Brought to you by:
dbrosius
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(56) |
Oct
(60) |
Nov
(58) |
Dec
(89) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(66) |
Feb
(55) |
Mar
(85) |
Apr
(115) |
May
(35) |
Jun
(28) |
Jul
(3) |
Aug
(48) |
Sep
(37) |
Oct
(22) |
Nov
(14) |
Dec
(66) |
2007 |
Jan
(45) |
Feb
(63) |
Mar
(10) |
Apr
(1) |
May
(1) |
Jun
(12) |
Jul
|
Aug
|
Sep
(25) |
Oct
(21) |
Nov
(39) |
Dec
|
2008 |
Jan
(7) |
Feb
|
Mar
(26) |
Apr
(5) |
May
(2) |
Jun
(32) |
Jul
(9) |
Aug
(10) |
Sep
|
Oct
(3) |
Nov
(1) |
Dec
|
2009 |
Jan
(10) |
Feb
(31) |
Mar
(32) |
Apr
(35) |
May
(25) |
Jun
|
Jul
(31) |
Aug
(10) |
Sep
(95) |
Oct
(35) |
Nov
(10) |
Dec
(34) |
2010 |
Jan
(90) |
Feb
(4) |
Mar
(7) |
Apr
(20) |
May
(20) |
Jun
(13) |
Jul
(7) |
Aug
(18) |
Sep
(25) |
Oct
(4) |
Nov
(16) |
Dec
(2) |
2011 |
Jan
(1) |
Feb
|
Mar
(11) |
Apr
(3) |
May
(2) |
Jun
(26) |
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2012 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(14) |
Nov
(3) |
Dec
(4) |
2013 |
Jan
(3) |
Feb
(2) |
Mar
(1) |
Apr
(4) |
May
|
Jun
(1) |
Jul
(3) |
Aug
|
Sep
|
Oct
(4) |
Nov
(3) |
Dec
(3) |
2014 |
Jan
(4) |
Feb
(2) |
Mar
(4) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
2016 |
Jan
(2) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
(2) |
Nov
(7) |
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
(4) |
Apr
(5) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(3) |
2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(5) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dbr...@us...> - 2006-06-19 05:10:06
|
Revision: 565 Author: dbrosius Date: 2006-06-18 22:09:54 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=565&view=rev Log Message: ----------- Use 1.0.0 of findbugs Modified Paths: -------------- trunk/fb-contrib/lib/findbugs.jar Modified: trunk/fb-contrib/lib/findbugs.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-19 00:06:12
|
Revision: 564 Author: dbrosius Date: 2006-06-18 17:05:58 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=564&view=rev Log Message: ----------- start working on UTA - not working yet. Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/UTA_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/MapEntry.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-06-09 03:29:47 UTC (rev 563) +++ trunk/fb-contrib/etc/findbugs.xml 2006-06-19 00:05:58 UTC (rev 564) @@ -211,6 +211,11 @@ speed="fast" reports="RMC_REDUNDANT_METHOD_CALLS" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.UseToArray" + speed="fast" + reports="UTA_USE_TO_ARRAY" + hidden="true" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -267,4 +272,5 @@ <BugPattern abbrev="ITC" type="ITC_INHERITANCE_TYPE_CHECKING" category="STYLE" experimental="true" /> <BugPattern abbrev="SACM" type="SACM_STATIC_ARRAY_CREATED_IN_METHOD" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="RMC" type="RMC_REDUNDANT_METHOD_CALLS" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="UTA" type="UTA_USE_TO_ARRAY" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-06-09 03:29:47 UTC (rev 563) +++ trunk/fb-contrib/etc/messages.xml 2006-06-19 00:05:58 UTC (rev 564) @@ -600,6 +600,18 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.UseToArray"> + <Details> + <![CDATA[ + <p>looks for code that builds an array of values from a collection, by manually looping + over the elements of the collection, and adding them to the array. It is simpler and + cleaner to use mycollection.toArray(new type[mycollection.size()].</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> @@ -1307,6 +1319,19 @@ </Details> </BugPattern> + <BugPattern type="UTA_USE_TO_ARRAY"> + <ShortDescription>Method manually creates array from collection</ShortDescription> + <LongDescription>Method {1} manually creates array from collection</LongDescription> + <Details> + <![CDATA[ + <p>This method manually loops over a collection, pulling each element out and storing + it in an array to build an array from the collection. It is easier, and clearer to use + the built in collections method toArray. Given a collection 'mycollection' of type T, use + mycollection.toArray(new T[mycollection.size()]); + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1358,4 +1383,5 @@ <BugCode abbrev="ITC">Inheritance Type Checking</BugCode> <BugCode abbrev="SACM">Static Array Created in Method</BugCode> <BugCode abbrev="RMC">Redundant Method Calls</BugCode> + <BugCode abbrev="UTA">Use toArray</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/UTA_Sample.java =================================================================== --- trunk/fb-contrib/samples/UTA_Sample.java (rev 0) +++ trunk/fb-contrib/samples/UTA_Sample.java 2006-06-19 00:05:58 UTC (rev 564) @@ -0,0 +1,23 @@ +import java.util.List; + +public class UTA_Sample +{ + public String[] testList1(List<String> l) + { + String[] data = new String[l.size()]; + for (int i = 0; i < l.size(); i++) + data[i] = l.get(i); + + return data; + } + + public Integer[] testList2(List<Integer> l) + { + int size = l.size(); + Integer[] data = new Integer[size]; + for (int i = 0; i < size; i++) + data[i] = l.get(i); + + return data; + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-06-19 00:05:58 UTC (rev 564) @@ -0,0 +1,197 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.JavaClass; + +import com.mebigfatguy.fbcontrib.utils.Integer14; +import com.mebigfatguy.fbcontrib.utils.MapEntry; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + +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 UseToArray extends BytecodeScanningDetector +{ + private static JavaClass collectionClass; + private static ClassNotFoundException ex; + static { + try { + collectionClass = Repository.lookupClass("java/util/Collection"); + } catch (ClassNotFoundException cnfe) { + collectionClass = null; + ex = cnfe; + } + } + + private BugReporter bugReporter; + private OpcodeStack stack; + private Map<Integer, Object> userValues; + /** map of pc of loop starts to map entry of index register to collection register */ + private Map<Integer, Map.Entry<Integer, Integer>> loopStarts; + + + /** + * constructs a UTA detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public UseToArray(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + public void visitClassContext(ClassContext classContext) { + if (collectionClass == null) { + if (ex != null) { + bugReporter.reportMissingClass(ex); + ex = null; + } + return; + } + + try { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } finally { + stack = null; + } + } + + @Override + public void visitCode(Code obj) { + try { + stack.resetForMethodEntry(this); + userValues = new HashMap<Integer, Object>(); + loopStarts = new HashMap<Integer, Map.Entry<Integer, Integer>>(); + super.visitCode(obj); + } finally { + userValues = null; + loopStarts = null; + } + } + + @Override + public void sawOpcode(int seen) { + int reg = -1; + Object uValue = null; + boolean sawSize = false; + boolean sawLoad = false; + boolean sawNewArray = false; + + try { + if (seen == INVOKEINTERFACE) { + if ("size".equals(getNameConstantOperand()) && "()I".equals(getSigConstantOperand())) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + reg = isLocalCollection(itm); + if (reg >= 0) { + sawSize = true; + } + } + } + } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) + || ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { + if (stack.getStackDepth() > 0) { + reg = Integer14.valueOf(RegisterUtils.getStoreReg(this, seen)); + uValue = stack.getStackItem(0).getUserValue(); + userValues.put(reg, uValue); + } + } else if (((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3))) + || ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3)))) { + sawLoad = true; + } else if (seen == ANEWARRAY) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + uValue = itm.getUserValue(); + sawNewArray = true; + } + } else if (seen == IF_ICMPGE) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm1 = stack.getStackItem(1); + OpcodeStack.Item itm2 = stack.getStackItem(0); + Object const1 = itm1.getConstant(); + reg = itm1.getRegisterNumber(); + if ((reg >= 0) && (const1 instanceof Integer)) { + if (0 == ((Integer) const1).intValue()) { + uValue = itm2.getUserValue(); + if (uValue != null) { + loopStarts.put(Integer14.valueOf(getPC()), new MapEntry<Integer, Integer>(Integer14.valueOf(reg), (Integer)uValue)); + } + } + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + stack.sawOpcode(this, seen); + if (sawSize) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + itm.setUserValue(Integer14.valueOf(reg)); + } + } else if (sawLoad) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + reg = itm.getRegisterNumber(); + if (reg >= 0) { + uValue = userValues.get(Integer14.valueOf(reg)); + itm.setUserValue(uValue); + } + } + } else if (sawNewArray) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + itm.setUserValue(uValue); + } + } + } + } + + /** + * determines if the stack item refers to a collection that is stored in a local variable + * + * param item the stack item to check + * + * @return the register number of the local variable that this collection refers to, or -1 + * @throws ClassNotFoundException if the items class cannot be found + */ + private int isLocalCollection(OpcodeStack.Item item) throws ClassNotFoundException { + Integer aliasReg = (Integer)item.getUserValue(); + if (aliasReg != null) + return aliasReg.intValue(); + + int reg = item.getRegisterNumber(); + if (reg < 0) + return -1; + + JavaClass cls = item.getJavaClass(); + if (cls.implementationOf(collectionClass)) + return reg; + + return -1; + } + +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/MapEntry.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/MapEntry.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/MapEntry.java 2006-06-19 00:05:58 UTC (rev 564) @@ -0,0 +1,55 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 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.utils; + +import java.util.Map.Entry; + +/** + * a simple implementation of the Map.Entry interface + */ +public class MapEntry<K,V> implements Entry<K,V> { + + private K key; + private V value; + + public MapEntry() { + key = null; + value = null; + } + + public MapEntry(K k, V v) { + key = k; + value = v; + } + + public K getKey() { + return key; + } + + public V getValue() { + return value; + } + + public V setValue(V v) { + V temp = value; + value = v; + return temp; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-09 03:29:53
|
Revision: 563 Author: dbrosius Date: 2006-06-08 20:29:47 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=563&view=rev Log Message: ----------- add fp test that is now fixed Modified Paths: -------------- trunk/fb-contrib/samples/ISB_Sample.java Modified: trunk/fb-contrib/samples/ISB_Sample.java =================================================================== --- trunk/fb-contrib/samples/ISB_Sample.java 2006-06-09 02:04:31 UTC (rev 562) +++ trunk/fb-contrib/samples/ISB_Sample.java 2006-06-09 03:29:47 UTC (rev 563) @@ -38,11 +38,19 @@ return msg; } - public String testISB8(int a) + public String testISB6(int a) { return "" + a; } + public String testISB7(String s) + { + StringBuffer sb = new StringBuffer(); + sb.append("foo"); + sb.append(sb.toString()); + return sb.toString(); + } + public String toString() { String a = System.getProperty("foo"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-09 02:04:41
|
Revision: 562 Author: dbrosius Date: 2006-06-08 19:04:31 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=562&view=rev Log Message: ----------- add ISB_EMPTY_STRING_APPENDING bug pattern to ISB Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/ISB_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-06-08 17:52:39 UTC (rev 561) +++ trunk/fb-contrib/etc/findbugs.xml 2006-06-09 02:04:31 UTC (rev 562) @@ -15,7 +15,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.InefficientStringBuffering" speed="fast" - reports="ISB_INEFFICIENT_STRING_BUFFERING" /> + reports="ISB_INEFFICIENT_STRING_BUFFERING,ISB_EMPTY_STRING_APPENDING" /> <Detector class="com.mebigfatguy.fbcontrib.detect.SyncCollectionIterators" speed="slow" @@ -214,6 +214,7 @@ <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> + <BugPattern abbrev="ISB" type="ISB_EMPTY_STRING_APPENDING" category="PERFORMANCE" /> <BugPattern abbrev="SCI" type="SCI_SYNCHRONIZED_COLLECTION_ITERATORS" category="CORRECTNESS" /> <BugPattern abbrev="CC" type="CC_CYCLOMATIC_COMPLEXITY" category="STYLE" /> <BugPattern abbrev="OCP" type="OCP_OVERLY_CONCRETE_PARAMETER" category="STYLE" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-06-08 17:52:39 UTC (rev 561) +++ trunk/fb-contrib/etc/messages.xml 2006-06-09 02:04:31 UTC (rev 562) @@ -615,6 +615,19 @@ </Details> </BugPattern> + <BugPattern type="ISB_EMPTY_STRING_APPENDING"> + <ShortDescription>method concatenates an empty string to effect type conversion</ShortDescription> + <LongDescription>method {1} concatenates an empty string to effect type conversion</LongDescription> + <Details> + <![CDATA[ + <p> This method concatenates an empty string with a literal value, in order to convert + the literal value into a string. It is more efficient to use String.valueOf() to do the same + thing as you do not incur the cost of creating a StringBuffer/Builder and calling methods on it + to accomplish this.</p> + ]]> + </Details> + </BugPattern> + <BugPattern type="SCI_SYNCHRONIZED_COLLECTION_ITERATORS"> <ShortDescription>method creates iterators on synchronized collections</ShortDescription> <LongDescription>method {1} creates iterators on synchronized collections</LongDescription> Modified: trunk/fb-contrib/samples/ISB_Sample.java =================================================================== --- trunk/fb-contrib/samples/ISB_Sample.java 2006-06-08 17:52:39 UTC (rev 561) +++ trunk/fb-contrib/samples/ISB_Sample.java 2006-06-09 02:04:31 UTC (rev 562) @@ -38,6 +38,11 @@ return msg; } + public String testISB8(int a) + { + return "" + a; + } + public String toString() { String a = System.getProperty("foo"); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-08 17:52:39 UTC (rev 561) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-09 02:04:31 UTC (rev 562) @@ -19,6 +19,8 @@ package com.mebigfatguy.fbcontrib.detect; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.Constant; +import org.apache.bcel.classfile.ConstantString; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -75,6 +77,26 @@ .addSourceLine(this)); } } + } else if (seen == INVOKEVIRTUAL) { + String calledClass = getClassConstantOperand(); + if (("java/lang/StringBuffer".equals(calledClass) + || "java/lang/StringBuilder".equals(calledClass)) + && "append".equals(getNameConstantOperand()) + && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) { + if (opStack.getStackDepth() > 0) { + OpcodeStack.Item itm = opStack.getStackItem(0); + Object cons = itm.getConstant(); + if ((cons instanceof String) && (itm.getRegisterNumber() < 0)) { + if (((String)cons).length() == 0) { + bugReporter.reportBug( + new BugInstance(this, "ISB_EMPTY_STRING_APPENDING", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } } else if (seen == GOTO) { int depth = opStack.getStackDepth(); for (int i = 0; i < depth; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-08 17:53:16
|
Revision: 561 Author: dbrosius Date: 2006-06-08 10:52:39 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=561&view=rev Log Message: ----------- try to suppress more fp's due to trinaries around string buffering Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-08 02:47:32 UTC (rev 560) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-08 17:52:39 UTC (rev 561) @@ -76,9 +76,11 @@ } } } else if (seen == GOTO) { - OpcodeStack.Item itm = getStringBufferItemAt(1); - if (itm != null) + int depth = opStack.getStackDepth(); + for (int i = 0; i < depth; i++) { + OpcodeStack.Item itm = opStack.getStackItem(i); itm.setUserValue(Boolean.TRUE); + } } } finally { opStack.sawOpcode(this, seen); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-08 02:47:39
|
Revision: 560 Author: dbrosius Date: 2006-06-07 19:47:32 -0700 (Wed, 07 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=560&view=rev Log Message: ----------- add push/pop as risky patterns Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-07 04:45:14 UTC (rev 559) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-08 02:47:32 UTC (rev 560) @@ -56,6 +56,8 @@ riskyMethodNameContents.add("remove"); riskyMethodNameContents.add("read"); riskyMethodNameContents.add("write"); + riskyMethodNameContents.add("push"); + riskyMethodNameContents.add("pop"); String userNameProp = System.getProperty(RMC_RISKY_USER_KEY); if (userNameProp != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-07 04:45:20
|
Revision: 559 Author: dbrosius Date: 2006-06-06 21:45:14 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=559&view=rev Log Message: ----------- add ability for user to add risky method name parts, thru system property 'fbcontrib.RMC.riskynames' Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 20:30:34 UTC (rev 558) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-07 04:45:14 UTC (rev 559) @@ -45,6 +45,8 @@ */ public class RedundantMethodCalls extends BytecodeScanningDetector { + public static final String RMC_RISKY_USER_KEY = "fbcontrib.RMC.riskynames"; + private static Set<String> riskyMethodNameContents = new HashSet<String>(); static { riskyMethodNameContents.add("next"); @@ -54,6 +56,13 @@ riskyMethodNameContents.add("remove"); riskyMethodNameContents.add("read"); riskyMethodNameContents.add("write"); + + String userNameProp = System.getProperty(RMC_RISKY_USER_KEY); + if (userNameProp != null) { + String[] userNames = userNameProp.split("\\s*,\\s*"); + for (String name : userNames) + riskyMethodNameContents.add(name.toLowerCase()); + } } private BugReporter bugReporter; private OpcodeStack stack = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 21:00:40
|
Revision: 558 Author: dbrosius Date: 2006-06-06 13:30:34 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=558&view=rev Log Message: ----------- reset branchTargets on method entry, and enter catch block targets into branchTargets Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 16:08:04 UTC (rev 557) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 20:30:34 UTC (rev 558) @@ -26,6 +26,7 @@ import java.util.Set; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; import org.apache.bcel.generic.Type; import com.mebigfatguy.fbcontrib.utils.Integer14; @@ -97,6 +98,11 @@ stack.resetForMethodEntry(this); localMethodCalls.clear(); fieldMethodCalls.clear(); + branchTargets.clear(); + CodeException[] codeExceptions = obj.getExceptionTable(); + for (CodeException codeEx : codeExceptions) { + branchTargets.add(codeEx.getHandlerPC()); + } super.visitCode(obj); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 16:08:13
|
Revision: 557 Author: dbrosius Date: 2006-06-06 09:08:04 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=557&view=rev Log Message: ----------- fix javadoc Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java 2006-06-06 16:04:36 UTC (rev 556) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java 2006-06-06 16:08:04 UTC (rev 557) @@ -44,7 +44,7 @@ /** * implements the visitor by forwarding calls for methods that are the static initializer * - * @obj the context object of the currently parsed code block + * @param obj the context object of the currently parsed code block */ @Override public void visitCode(Code obj) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 16:04:46
|
Revision: 556 Author: dbrosius Date: 2006-06-06 09:04:36 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=556&view=rev Log Message: ----------- loosen permissions Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 16:02:16 UTC (rev 555) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 16:04:36 UTC (rev 556) @@ -198,27 +198,27 @@ /** * contains information about a method call */ - private static class MethodCall + static class MethodCall { private String methodName; private String methodSignature; private Object[] methodParms; - private MethodCall(String name, String signature, Object[] parms) { + public MethodCall(String name, String signature, Object[] parms) { methodName = name; methodSignature = signature; methodParms = parms; } - private String getName() { + public String getName() { return methodName; } - private String getSignature() { + public String getSignature() { return methodSignature; } - private Object[] getParms() { + public Object[] getParms() { return methodParms; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 16:02:33
|
Revision: 554 Author: dbrosius Date: 2006-06-06 08:57:07 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=554&view=rev Log Message: ----------- add doc for RMC Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-06-06 05:01:25 UTC (rev 553) +++ trunk/fb-contrib/htdocs/index.html 2006-06-06 15:57:07 UTC (rev 554) @@ -62,6 +62,9 @@ Looks for if/else blocks where a series of them use instanceof on the same variable to determine what to do. If these classes are related by inheritance, this often is better handled through calling a single overridden method.</li> + <li><b>[RMC] Redundant Method Calls</b><br/> + Looks for calls of the same method on the same object when that object hasn't changed. + This often is redundant, and the second call can be removed, or combined.</li> </ul> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 16:02:27
|
Revision: 555 Author: dbrosius Date: 2006-06-06 09:02:16 -0700 (Tue, 06 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=555&view=rev Log Message: ----------- add javadoc, copyright Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 15:57:07 UTC (rev 554) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 16:02:16 UTC (rev 555) @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 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.Arrays; @@ -42,10 +60,19 @@ private Map<String, MethodCall> fieldMethodCalls = null; private Set<Integer> branchTargets = null; + /** + * constructs a RMC detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ public RedundantMethodCalls(BugReporter bugReporter) { this.bugReporter = bugReporter; } + /** + * implements the visitor to create and clear the stack, method call maps, and branch targets + * + * @param classContext the context object of the currently visited class + */ public void visitClassContext(ClassContext classContext) { try { stack = new OpcodeStack(); @@ -60,6 +87,12 @@ branchTargets = null; } } + + /** + * implements the visitor to reset the stack, and method call maps for new method + * + * @param obj the context object of the currently parsed code block + */ public void visitCode(Code obj) { stack.resetForMethodEntry(this); localMethodCalls.clear(); @@ -67,6 +100,12 @@ super.visitCode(obj); } + /** + * implements the visitor to look for repetitive calls to the same method on the same object + * using the same constant parameters. These methods must return a value. + * + * @param seen the opcode of the currently parsed instruction + */ public void sawOpcode(int seen) { try { stack.mergeJumps(this); @@ -141,6 +180,12 @@ } } + /** + * returns true if the method name contains a pattern that is considered likely to be this modifying + * + * @param methodName the method name to check + * @return whether the method sounds like it modifies this + */ private boolean isRiskyName(String methodName) { methodName = methodName.toLowerCase(Locale.ENGLISH); for (String riskyName : riskyMethodNameContents) { @@ -150,6 +195,9 @@ return false; } + /** + * contains information about a method call + */ private static class MethodCall { private String methodName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 05:01:30
|
Revision: 553 Author: dbrosius Date: 2006-06-05 22:01:25 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=553&view=rev Log Message: ----------- add branch targets for TABLESWITCH and LOOKUPSWITCH Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:55:47 UTC (rev 552) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 05:01:25 UTC (rev 553) @@ -77,6 +77,12 @@ if (((seen >= IFEQ) && (seen <= GOTO)) || ((seen >= IFNULL) && (seen <= GOTO_W))) { branchTargets.add(Integer14.valueOf(getBranchTarget())); + } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) { + int[] offsets = getSwitchOffsets(); + int pc = getPC(); + for (int offset : offsets) { + branchTargets.add(Integer14.valueOf(offset + pc)); + } } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { localMethodCalls.remove(Integer14.valueOf(RegisterUtils.getAStoreReg(this, seen))); } else if (seen == PUTFIELD) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 04:55:53
|
Revision: 552 Author: dbrosius Date: 2006-06-05 21:55:47 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=552&view=rev Log Message: ----------- add 'read' and 'write' to risky method contents Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:53:23 UTC (rev 551) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:55:47 UTC (rev 552) @@ -33,6 +33,8 @@ riskyMethodNameContents.add("append"); riskyMethodNameContents.add("put"); riskyMethodNameContents.add("remove"); + riskyMethodNameContents.add("read"); + riskyMethodNameContents.add("write"); } private BugReporter bugReporter; private OpcodeStack stack = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 04:53:30
|
Revision: 551 Author: dbrosius Date: 2006-06-05 21:53:23 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=551&view=rev Log Message: ----------- clearer format msg Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:30:19 UTC (rev 550) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:53:23 UTC (rev 551) @@ -111,7 +111,7 @@ .addClass(this) .addMethod(this) .addSourceLine(this) - .addString(methodName + "[" + signature + "]")); + .addString(methodName + signature)); } } if (reg >= 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 04:30:27
|
Revision: 550 Author: dbrosius Date: 2006-06-05 21:30:19 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=550&view=rev Log Message: ----------- add method name and signature to the bug report Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:27:58 UTC (rev 549) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:30:19 UTC (rev 550) @@ -110,7 +110,8 @@ bugReporter.reportBug(new BugInstance(this, "RMC_REDUNDANT_METHOD_CALLS", NORMAL_PRIORITY) .addClass(this) .addMethod(this) - .addSourceLine(this)); + .addSourceLine(this) + .addString(methodName + "[" + signature + "]")); } } if (reg >= 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 04:28:07
|
Revision: 549 Author: dbrosius Date: 2006-06-05 21:27:58 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=549&view=rev Log Message: ----------- add 'append' as a risky name content Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:13:16 UTC (rev 548) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:27:58 UTC (rev 549) @@ -30,6 +30,7 @@ static { riskyMethodNameContents.add("next"); riskyMethodNameContents.add("add"); + riskyMethodNameContents.add("append"); riskyMethodNameContents.add("put"); riskyMethodNameContents.add("remove"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-06 04:13:31
|
Revision: 548 Author: dbrosius Date: 2006-06-05 21:13:16 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=548&view=rev Log Message: ----------- Initial Checkin new RMC detector. Likely to have many false positives at present. Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/RMC_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-06-04 03:43:32 UTC (rev 547) +++ trunk/fb-contrib/etc/findbugs.xml 2006-06-06 04:13:16 UTC (rev 548) @@ -207,6 +207,10 @@ speed="fast" reports="SACM_STATIC_ARRAY_CREATED_IN_METHOD" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.RedundantMethodCalls" + speed="fast" + reports="RMC_REDUNDANT_METHOD_CALLS" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -261,4 +265,5 @@ <BugPattern abbrev="NMCS" type="NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="ITC" type="ITC_INHERITANCE_TYPE_CHECKING" category="STYLE" experimental="true" /> <BugPattern abbrev="SACM" type="SACM_STATIC_ARRAY_CREATED_IN_METHOD" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="RMC" type="RMC_REDUNDANT_METHOD_CALLS" category="PERFORMANCE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-06-04 03:43:32 UTC (rev 547) +++ trunk/fb-contrib/etc/messages.xml 2006-06-06 04:13:16 UTC (rev 548) @@ -589,7 +589,17 @@ <p>It is a fast detector</p> ]]> </Details> - </Detector> + </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.RedundantMethodCalls"> + <Details> + <![CDATA[ + <p>looks for calls of the same method on the same object when that object hasn't changed. + This often is redundant, and the second call can be removed, or combined.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1270,6 +1280,20 @@ </Details> </BugPattern> + <BugPattern type="RMC_REDUNDANT_METHOD_CALLS"> + <ShortDescription>Method calls the same method on the same object redundantly</ShortDescription> + <LongDescription>Method {1} calls the same method on the same object redundantly</LongDescription> + <Details> + <![CDATA[ + <p>This method makes two consecutive calls to the same method using the same constant + parameters, on the same instance without any intervening changes to the objects. If this + method does not make changes to the object, which it appears it doesn't, then making + two calls is just a waste. These method calls could be combined by assigning the + result into a temporary, and using the temporary the second time. + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1320,4 +1344,5 @@ <BugCode abbrev="NMCS">Needless Member Collection Synchronization</BugCode> <BugCode abbrev="ITC">Inheritance Type Checking</BugCode> <BugCode abbrev="SACM">Static Array Created in Method</BugCode> + <BugCode abbrev="RMC">Redundant Method Calls</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/RMC_Sample.java =================================================================== --- trunk/fb-contrib/samples/RMC_Sample.java (rev 0) +++ trunk/fb-contrib/samples/RMC_Sample.java 2006-06-06 04:13:16 UTC (rev 548) @@ -0,0 +1,14 @@ +import java.util.Calendar; +import java.util.Date; + +public class RMC_Sample +{ + public boolean test1(Calendar c) + { + Date d = c.getTime(); + long l = d.getTime(); + Date e = c.getTime(); + long j = e.getTime(); + return l == j; + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-06-06 04:13:16 UTC (rev 548) @@ -0,0 +1,167 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import org.apache.bcel.classfile.Code; +import org.apache.bcel.generic.Type; + +import com.mebigfatguy.fbcontrib.utils.Integer14; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.FieldAnnotation; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for calls of the same method on the same object when that object hasn't changed. + * This often is redundant, and the second call can be removed, or combined. + */ +public class RedundantMethodCalls extends BytecodeScanningDetector +{ + private static Set<String> riskyMethodNameContents = new HashSet<String>(); + static { + riskyMethodNameContents.add("next"); + riskyMethodNameContents.add("add"); + riskyMethodNameContents.add("put"); + riskyMethodNameContents.add("remove"); + } + private BugReporter bugReporter; + private OpcodeStack stack = null; + private Map<Integer, MethodCall> localMethodCalls = null; + private Map<String, MethodCall> fieldMethodCalls = null; + private Set<Integer> branchTargets = null; + + public RedundantMethodCalls(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + localMethodCalls = new HashMap<Integer, MethodCall>(); + fieldMethodCalls = new HashMap<String, MethodCall>(); + branchTargets = new HashSet<Integer>(); + super.visitClassContext(classContext); + } finally { + stack = null; + localMethodCalls = null; + fieldMethodCalls = null; + branchTargets = null; + } + } + public void visitCode(Code obj) { + stack.resetForMethodEntry(this); + localMethodCalls.clear(); + fieldMethodCalls.clear(); + super.visitCode(obj); + } + + public void sawOpcode(int seen) { + try { + stack.mergeJumps(this); + if (branchTargets.remove(Integer14.valueOf(getPC()))) { + localMethodCalls.clear(); + fieldMethodCalls.clear(); + } + + if (((seen >= IFEQ) && (seen <= GOTO)) || ((seen >= IFNULL) && (seen <= GOTO_W))) { + branchTargets.add(Integer14.valueOf(getBranchTarget())); + } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + localMethodCalls.remove(Integer14.valueOf(RegisterUtils.getAStoreReg(this, seen))); + } else if (seen == PUTFIELD) { + fieldMethodCalls.remove(getNameConstantOperand()); + } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + int parmCount = Type.getArgumentTypes(signature).length; + if (stack.getStackDepth() > parmCount) { + Object[] parmConstants = new Object[parmCount]; + for (int i = 0; i < parmCount; i++) { + OpcodeStack.Item parm = stack.getStackItem(i); + parmConstants[i] = parm.getConstant(); + if (parmConstants[i] == null) + return; + } + OpcodeStack.Item obj = stack.getStackItem(parmCount); + int reg = obj.getRegisterNumber(); + FieldAnnotation fa = obj.getField(); + + MethodCall mc; + if (reg >= 0) { + mc = localMethodCalls.get(Integer14.valueOf(reg)); + } else if (fa != null) { + mc = fieldMethodCalls.get(fa.getFieldName()); + } else + return; + + if (mc != null) { + if (!signature.endsWith("V") && methodName.equals(mc.getName()) && signature.equals(mc.getSignature()) && !isRiskyName(methodName)) { + Object[] parms = mc.getParms(); + if (Arrays.equals(parms, parmConstants)) { + bugReporter.reportBug(new BugInstance(this, "RMC_REDUNDANT_METHOD_CALLS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + if (reg >= 0) { + localMethodCalls.remove(Integer14.valueOf(reg)); + } else { + fieldMethodCalls.remove(fa.getFieldName()); + } + } else { + if (reg >= 0) { + localMethodCalls.put(Integer14.valueOf(reg), new MethodCall(methodName, signature, parmConstants)); + } else if (fa != null) { + fieldMethodCalls.put(fa.getFieldName(), new MethodCall(methodName, signature, parmConstants)); + } + } + } + } + } finally { + stack.sawOpcode(this, seen); + } + } + + private boolean isRiskyName(String methodName) { + methodName = methodName.toLowerCase(Locale.ENGLISH); + for (String riskyName : riskyMethodNameContents) { + if (methodName.indexOf(riskyName) >= 0) + return true; + } + return false; + } + + private static class MethodCall + { + private String methodName; + private String methodSignature; + private Object[] methodParms; + + private MethodCall(String name, String signature, Object[] parms) { + methodName = name; + methodSignature = signature; + methodParms = parms; + } + + private String getName() { + return methodName; + } + + private String getSignature() { + return methodSignature; + } + + private Object[] getParms() { + return methodParms; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-04 03:43:57
|
Revision: 547 Author: dbrosius Date: 2006-06-03 20:43:32 -0700 (Sat, 03 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=547&view=rev Log Message: ----------- remove some false positives Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-06-03 05:19:26 UTC (rev 546) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-06-04 03:43:32 UTC (rev 547) @@ -124,7 +124,7 @@ case SEEN_STORE: if (branchTargets.contains(Integer14.valueOf(getPC()))) { state = SEEN_NOTHING; - return; + break; } state = lookForLoad(seen) ? SEEN_LOAD : SEEN_NOTHING; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-03 05:19:32
|
Revision: 546 Author: dbrosius Date: 2006-06-02 22:19:26 -0700 (Fri, 02 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=546&view=rev Log Message: ----------- For COM, when invoking a method make sure the class, method name and signature match, not just the constant pool index :) Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-05-24 18:15:48 UTC (rev 545) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-06-03 05:19:26 UTC (rev 546) @@ -29,6 +29,7 @@ import org.apache.bcel.generic.Instruction; import org.apache.bcel.generic.InstructionHandle; import org.apache.bcel.generic.InstructionList; +import org.apache.bcel.generic.InvokeInstruction; import org.apache.bcel.generic.ReferenceType; import edu.umd.cs.findbugs.BugInstance; @@ -173,6 +174,19 @@ if (!childRefType.getSignature().equals(parentRefType.getSignature())) return false; } + } else if (childin instanceof InvokeInstruction) { + String childClassName = ((InvokeInstruction) childin).getClassName(childPoolGen); + String parentClassName = ((InvokeInstruction) parentin).getClassName(parentPoolGen); + if (!childClassName.equals(parentClassName)) + return false; + String childMethodName = ((InvokeInstruction) childin).getMethodName(childPoolGen); + String parentMethodName = ((InvokeInstruction) parentin).getMethodName(parentPoolGen); + if (!childMethodName.equals(parentMethodName)) + return false; + String childSignature = ((InvokeInstruction) childin).getSignature(childPoolGen); + String parentSignature = ((InvokeInstruction) parentin).getSignature(parentPoolGen); + if (!childSignature.equals(parentSignature)) + return false; } else { if (!childin.equals(parentin)) return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-05-24 18:16:14
|
Revision: 545 Author: dbrosius Date: 2006-05-24 11:15:48 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=545&view=rev Log Message: ----------- better engrish Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-05-21 06:29:10 UTC (rev 544) +++ trunk/fb-contrib/htdocs/index.html 2006-05-24 18:15:48 UTC (rev 545) @@ -60,7 +60,7 @@ initializer are guaranteed to be thread safe.</li> <li><b>[ITC] Inheritance Type Checking</b><br/> Looks for if/else blocks where a series of them use instanceof on the same - variable to determine what do to. If these classes are related by inheritance, + variable to determine what to do. If these classes are related by inheritance, this often is better handled through calling a single overridden method.</li> </ul> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-05-21 06:29:15
|
Revision: 544 Author: dbrosius Date: 2006-05-20 23:29:10 -0700 (Sat, 20 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=544&view=rev Log Message: ----------- clearer messages Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-05-17 05:26:47 UTC (rev 543) +++ trunk/fb-contrib/etc/messages.xml 2006-05-21 06:29:10 UTC (rev 544) @@ -1164,7 +1164,8 @@ <Details> <![CDATA[ <p>This class uses JLabels that do not specify what fields are being labeled. - This hampers screen readers from given appropriate feed back to users. + This hampers screen readers from given appropriate feed back to users. Use + the JLabel.setLabelFor method to accomplish this. </p> ]]> </Details> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-05-17 05:26:52
|
Revision: 543 Author: dbrosius Date: 2006-05-16 22:26:47 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=543&view=rev Log Message: ----------- use Integer14.valueOf Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-17 05:10:55 UTC (rev 542) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-17 05:26:47 UTC (rev 543) @@ -29,6 +29,8 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -278,7 +280,7 @@ } else { int reg = item.getRegisterNumber(); if (reg >= 0) { - Integer register = new Integer(reg); + Integer register = Integer14.valueOf(reg); String fName = aliases.get(register); if (fName != null) { collectionFields.remove(fName); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-05-17 05:11:14
|
Revision: 542 Author: dbrosius Date: 2006-05-16 22:10:55 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=542&view=rev Log Message: ----------- use Integer14.valueOf Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.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/ParallelLists.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.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/utils/Integer14.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java 2006-05-17 05:10:55 UTC (rev 542) @@ -27,6 +27,7 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -123,7 +124,7 @@ OpcodeStack.Item itm = stack.getStackItem(0); Integer size = (Integer)itm.getConstant(); if ((size != null) && (size.intValue() == 1)) { - userValue = new Integer(-1); + userValue = Integer14.valueOf(-1); } } } else if ((seen >= IASTORE) && (seen <= SASTORE)) { @@ -131,7 +132,7 @@ OpcodeStack.Item itm = stack.getStackItem(2); int reg = itm.getRegisterNumber(); if (reg != -1) { - WrapperInfo wi = wrappers.get(new Integer(reg)); + WrapperInfo wi = wrappers.get(Integer14.valueOf(reg)); if (wi != null) { OpcodeStack.Item elItm = stack.getStackItem(0); wi.wrappedReg = elItm.getRegisterNumber(); @@ -139,7 +140,7 @@ } else { OpcodeStack.Item elItm = stack.getStackItem(0); if (elItm.getRegisterNumber() != -1) - userValue = new Integer(elItm.getRegisterNumber()); + userValue = Integer14.valueOf(elItm.getRegisterNumber()); } } } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { @@ -150,7 +151,7 @@ int reg = RegisterUtils.getAStoreReg(this, seen); Integer elReg = (Integer)itm.getUserValue(); if (elReg != null) - wrappers.put(new Integer(reg), new WrapperInfo(elReg.intValue())); + wrappers.put(Integer14.valueOf(reg), new WrapperInfo(elReg.intValue())); } else { Integer elReg = (Integer)itm.getUserValue(); if (elReg != null) { @@ -177,7 +178,7 @@ if ((argSig.length() > 0) && (argSig.charAt(0) == '[')) { OpcodeStack.Item itm = stack.getStackItem(args.length - i - 1); int arrayReg = itm.getRegisterNumber(); - WrapperInfo wi = wrappers.get(new Integer(arrayReg)); + WrapperInfo wi = wrappers.get(Integer14.valueOf(arrayReg)); if (wi != null) wi.wasArg = true; } @@ -187,16 +188,16 @@ if (stack.getStackDepth() >= 2) { OpcodeStack.Item arItm = stack.getStackItem(1); int arReg = arItm.getRegisterNumber(); - WrapperInfo wi = wrappers.get(new Integer(arReg)); + WrapperInfo wi = wrappers.get(Integer14.valueOf(arReg)); if ((wi != null) && wi.wasArg) { - userValue = new Integer(wi.wrappedReg); + userValue = Integer14.valueOf(wi.wrappedReg); } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { int reg = RegisterUtils.getALoadReg(this, seen); - WrapperInfo wi = wrappers.get(new Integer(reg)); + WrapperInfo wi = wrappers.get(Integer14.valueOf(reg)); if (wi != null) - userValue = new Integer(wi.wrappedReg); + userValue = Integer14.valueOf(wi.wrappedReg); } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) || ((seen == LSTORE) || ((seen >= LSTORE_0) && (seen <= LSTORE_3))) || ((seen == DSTORE) || ((seen >= DSTORE_0) && (seen <= DSTORE_3))) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-05-17 05:10:55 UTC (rev 542) @@ -29,6 +29,7 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -104,7 +105,7 @@ syncPC = -1; isStatic = m.isStatic(); unsafeAliases.clear(); - unsafeAliases.add(new Integer(0)); + unsafeAliases.add(Integer14.valueOf(0)); branchInfo.clear(); unsafeCallOccurred = false; stack.resetForMethodEntry(this); @@ -124,7 +125,7 @@ if (unsafeCallOccurred && ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { int storeReg = RegisterUtils.getAStoreReg(this, seen); if (storeReg >= 0) - unsafeAliases.add(new Integer(storeReg)); + unsafeAliases.add(Integer14.valueOf(storeReg)); } if ((seen == INVOKEVIRTUAL) @@ -136,7 +137,7 @@ int parmCount = Type.getArgumentTypes(methodSig).length; if (stack.getStackDepth() > parmCount) { OpcodeStack.Item itm = stack.getStackItem(parmCount); - unsafeCallOccurred = unsafeAliases.contains(new Integer(itm.getRegisterNumber())); + unsafeCallOccurred = unsafeAliases.contains(Integer14.valueOf(itm.getRegisterNumber())); } else unsafeCallOccurred = false; } else @@ -145,8 +146,8 @@ unsafeCallOccurred = (getDottedClassConstantOperand().equals(this.getClassContext().getJavaClass().getClassName())); else if ((seen >= IFEQ) && (seen <= GOTO)) { - Integer from = new Integer(getPC()); - Integer to = new Integer(getBranchTarget()); + Integer from = Integer14.valueOf(getPC()); + Integer to = Integer14.valueOf(getBranchTarget()); branchInfo.put(from, to); unsafeCallOccurred = false; } @@ -160,7 +161,7 @@ OpcodeStack.Item itm = stack.getStackItem(0); int monitorReg = itm.getRegisterNumber(); if (monitorReg >= 0) { - unsafeAliases.add(new Integer(monitorReg)); + unsafeAliases.add(Integer14.valueOf(monitorReg)); } } } @@ -173,7 +174,7 @@ unsafe |= ((seen == PUTFIELD) || (seen == GETFIELD) || (seen == GETSTATIC) || (seen == PUTSTATIC)); unsafe |= (!isStatic) && ((seen == ALOAD_0) || (seen == ASTORE_0)); int aloadReg = RegisterUtils.getALoadReg(this, seen); - unsafe |= (aloadReg >= 0) && unsafeAliases.contains(new Integer(aloadReg)); + unsafe |= (aloadReg >= 0) && unsafeAliases.contains(Integer14.valueOf(aloadReg)); if (unsafe) { //If a branch exists in the safe code, make sure the entire branch //is in the safe code, otherwise trim before the branch Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-05-17 05:10:55 UTC (rev 542) @@ -32,6 +32,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -280,13 +282,13 @@ private void addLineNumber(Set<Integer> lineNumbers) { LineNumberTable lnt = getCode().getLineNumberTable(); if (lnt == null) - lineNumbers.add(new Integer(-lineNumbers.size())); + lineNumbers.add(Integer14.valueOf(-lineNumbers.size())); else { int line = lnt.getSourceLine(getPC()); if (line < 0) - lineNumbers.add(new Integer(lineNumbers.size())); + lineNumbers.add(Integer14.valueOf(lineNumbers.size())); else { - lineNumbers.add(new Integer(line)); + lineNumbers.add(Integer14.valueOf(line)); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2006-05-17 05:10:55 UTC (rev 542) @@ -26,6 +26,8 @@ import org.apache.bcel.classfile.ConstantInteger; import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -120,7 +122,7 @@ //case CALOAD: usually harmless so ignore case SALOAD: if (state == SEEN_CONSTANT_0) - iConst0Looped.add(new Integer(getPC())); + iConst0Looped.add(Integer14.valueOf(getPC())); else { bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) .addClass(this) @@ -134,7 +136,7 @@ String methodName = getNameConstantOperand(); if ("get".equals(methodName)) { if (state == SEEN_CONSTANT_0) - iConst0Looped.add(new Integer(getPC())); + iConst0Looped.add(Integer14.valueOf(getPC())); else { bugReporter.reportBug(new BugInstance(this, "CLI_CONSTANT_LIST_INDEX", NORMAL_PRIORITY) .addClass(this) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java 2006-05-17 05:10:55 UTC (rev 542) @@ -25,6 +25,8 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.Detector; @@ -112,7 +114,7 @@ && (edgeType != EdgeTypes.UNKNOWN_EDGE)) { if ((edgeType == EdgeTypes.UNHANDLED_EXCEPTION_EDGE) || (edgeType == EdgeTypes.HANDLED_EXCEPTION_EDGE)) { - Integer nodeTarget = new Integer(e.getTarget().getId()); + Integer nodeTarget = Integer14.valueOf(e.getTarget().getId()); if (!exceptionNodeTargets.contains(nodeTarget)) { exceptionNodeTargets.add(nodeTarget); branches++; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java 2006-05-17 05:10:55 UTC (rev 542) @@ -33,6 +33,7 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -188,7 +189,7 @@ BugInstance bi = null; for (int i = 0; i < parmCount; i++) { - if (changedParms.remove(new Integer(i))) + if (changedParms.remove(Integer14.valueOf(i))) continue; int reg; @@ -220,7 +221,7 @@ if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { int parm = getAStoreParameter(seen); if (parm >= 0) - changedParms.add(new Integer(parm)); + changedParms.add(Integer14.valueOf(parm)); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2006-05-17 05:10:55 UTC (rev 542) @@ -25,6 +25,7 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -74,8 +75,8 @@ for (int t = 0; t < argTypes.length; t++) { String sig = argTypes[t].getSignature(); if (isJDBCClass(sig)) { - jdbcLocals.put(new Integer(parmRegs[t]), - new Integer(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), parmRegs[t], 0))); + jdbcLocals.put(Integer14.valueOf(parmRegs[t]), + Integer14.valueOf(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), parmRegs[t], 0))); } } } @@ -126,13 +127,13 @@ OpcodeStack.Item itm = stack.getStackItem(0); if (itm.getUserValue() != null) { int reg = RegisterUtils.getAStoreReg(this, seen); - jdbcLocals.put(new Integer(reg), new Integer(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC()))); + jdbcLocals.put(Integer14.valueOf(reg), Integer14.valueOf(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC()))); } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { int reg = RegisterUtils.getALoadReg(this, seen); - if (jdbcLocals.containsKey(new Integer(reg))) + if (jdbcLocals.containsKey(Integer14.valueOf(reg))) tosIsJDBC = true; } } finally { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java 2006-05-17 05:10:55 UTC (rev 542) @@ -28,6 +28,7 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -96,7 +97,7 @@ syncRegs.clear(); int[] parmRegs = RegisterUtils.getParameterRegisters(obj); for (int pr : parmRegs) { - syncRegs.put(new Integer(pr), + syncRegs.put(Integer14.valueOf(pr), new CollectionRegInfo(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), pr, 0))); } } @@ -137,13 +138,13 @@ if (seen == INVOKESPECIAL) { if ("<init>".equals(getNameConstantOperand())) { if (syncCtors.contains(getClassConstantOperand())) { - tosIsSyncColReg = new Integer(-1); + tosIsSyncColReg = Integer14.valueOf(-1); } } } else if (seen == INVOKESTATIC) { if ("java/util/Collections".equals(getClassConstantOperand())) { if (syncMethods.contains(getNameConstantOperand())) { - tosIsSyncColReg = new Integer(-1); + tosIsSyncColReg = Integer14.valueOf(-1); } } } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { @@ -151,25 +152,25 @@ OpcodeStack.Item item = stack.getStackItem(0); int reg = RegisterUtils.getAStoreReg(this, seen); if (item.getUserValue() != null) { - if (!syncRegs.containsKey(new Integer(reg))) { + if (!syncRegs.containsKey(Integer14.valueOf(reg))) { CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this), RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC())); - syncRegs.put(new Integer(reg), cri); + syncRegs.put(Integer14.valueOf(reg), cri); } } else { - CollectionRegInfo cri = syncRegs.get(new Integer(reg)); + CollectionRegInfo cri = syncRegs.get(Integer14.valueOf(reg)); if (cri == null) { cri = new CollectionRegInfo(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC())); - syncRegs.put(new Integer(reg), cri); + syncRegs.put(Integer14.valueOf(reg), cri); } cri.setIgnore(); } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { int reg = RegisterUtils.getALoadReg(this, seen); - CollectionRegInfo cri = syncRegs.get(new Integer(reg)); + CollectionRegInfo cri = syncRegs.get(Integer14.valueOf(reg)); if ((cri != null) && !cri.getIgnore()) - tosIsSyncColReg = new Integer(reg); + tosIsSyncColReg = Integer14.valueOf(reg); } else if ((seen == PUTFIELD) || (seen == ARETURN)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-05-17 05:10:55 UTC (rev 542) @@ -9,6 +9,7 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -26,9 +27,9 @@ */ public class NonOwnedSynchronization extends BytecodeScanningDetector { - private static final Integer OWNED = new Integer(Integer.MAX_VALUE); - private static final Integer LOW = new Integer(LOW_PRIORITY); - private static final Integer NORMAL = new Integer(NORMAL_PRIORITY); + private static final Integer OWNED = Integer14.valueOf(Integer.MAX_VALUE); + private static final Integer LOW = Integer14.valueOf(LOW_PRIORITY); + private static final Integer NORMAL = Integer14.valueOf(NORMAL_PRIORITY); private BugReporter bugReporter; private OpcodeStack stack; private Map<Integer, Integer> regPriorities; @@ -79,9 +80,9 @@ regPriorities.clear(); int[] parmRegs = RegisterUtils.getParameterRegisters(method); for (int reg : parmRegs) - regPriorities.put(new Integer(reg), NORMAL); + regPriorities.put(Integer14.valueOf(reg), NORMAL); if (!method.isStatic()) - regPriorities.put(new Integer(0), LOW); + regPriorities.put(Integer14.valueOf(0), LOW); super.visitCode(obj); } } @@ -110,7 +111,7 @@ if (getMethod().isStatic() && (reg == 0)) tosIsPriority = LOW; else { - tosIsPriority = regPriorities.get(new Integer(reg)); + tosIsPriority = regPriorities.get(Integer14.valueOf(reg)); if (tosIsPriority == null) tosIsPriority = NORMAL; } @@ -125,7 +126,7 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); Integer priority = (Integer)item.getUserValue(); - regPriorities.put(new Integer(RegisterUtils.getAStoreReg(this, seen)), priority); + regPriorities.put(Integer14.valueOf(RegisterUtils.getAStoreReg(this, seen)), priority); } } break; @@ -144,7 +145,7 @@ } else { int reg = itm.getRegisterNumber(); if (reg > 0) - tosIsPriority = regPriorities.get(new Integer(reg)); + tosIsPriority = regPriorities.get(Integer14.valueOf(reg)); else tosIsPriority = OWNED; } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OrphanedDOMNode.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OrphanedDOMNode.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OrphanedDOMNode.java 2006-05-17 05:10:55 UTC (rev 542) @@ -26,6 +26,8 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -134,7 +136,7 @@ if ("org/w3c/dom/Document".equals(className)) { if (domCreationMethods.contains(methodInfo)) { sawCreate = true; - itemPC = new Integer(getPC()); + itemPC = Integer14.valueOf(getPC()); } } } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && seen <= ASTORE_3)) { @@ -145,9 +147,9 @@ else reg = seen - ASTORE_0; if (pc != null) - nodeStores.put(new Integer(reg), pc); + nodeStores.put(Integer14.valueOf(reg), pc); else - nodeStores.remove(new Integer(reg)); + nodeStores.remove(Integer14.valueOf(reg)); } else if (seen == PUTFIELD) { //Stores to member variables are assumed ok findDOMNodeCreationPoint(0); @@ -157,7 +159,7 @@ reg = getRegisterOperand(); else reg = seen - ALOAD_0; - itemPC = nodeStores.get(new Integer(reg)); + itemPC = nodeStores.get(Integer14.valueOf(reg)); if (itemPC != null) sawCreate = true; } else if (seen == ARETURN) { @@ -165,7 +167,7 @@ OpcodeStack.Item itm = stack.getStackItem(0); int reg = itm.getRegisterNumber(); nodeCreations.remove(itm); - nodeStores.remove(new Integer(reg)); + nodeStores.remove(Integer14.valueOf(reg)); } } @@ -182,7 +184,7 @@ if (nodeCreations.containsKey(itm)) { int reg = itm.getRegisterNumber(); nodeCreations.remove(itm); - nodeStores.remove(new Integer(reg)); + nodeStores.remove(Integer14.valueOf(reg)); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2006-05-17 05:10:55 UTC (rev 542) @@ -35,6 +35,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -189,7 +191,7 @@ if (!methodIsStatic) parm--; if ((parm >= 0) && (parm < parmCount)) - parameterDefiners.remove(new Integer(reg)); + parameterDefiners.remove(Integer14.valueOf(reg)); } else { parameterDefiners.clear(); } @@ -202,7 +204,7 @@ if (!methodIsStatic) parm--; if ((parm >= 0) && (parm < parmCount)) - parameterDefiners.remove(new Integer(reg)); + parameterDefiners.remove(Integer14.valueOf(reg)); } else { parameterDefiners.clear(); } @@ -218,7 +220,7 @@ if (!methodIsStatic) parm--; if ((parm >= 0) && (parm < parmCount)) - usedParameters.add(new Integer(reg)); + usedParameters.add(Integer14.valueOf(reg)); } } finally { stack.sawOpcode(this, seen); @@ -281,7 +283,7 @@ Map<JavaClass, List<String>> definers = getClassDefiners(cls); if (definers.size() > 0) { - parameterDefiners.put( new Integer(i + (methodIsStatic ? 0 : 1)), definers ); + parameterDefiners.put( Integer14.valueOf(i + (methodIsStatic ? 0 : 1)), definers ); hasPossiblyOverlyConcreteParm = true; } } @@ -323,7 +325,7 @@ String methodName = getNameConstantOperand(); String methodInfo = methodName + methodSig; - Map<JavaClass, List<String>> definers = parameterDefiners.get(new Integer(reg)); + Map<JavaClass, List<String>> definers = parameterDefiners.get(Integer14.valueOf(reg)); if ((definers != null) && (definers.size() > 0)) { Iterator<List<String>> it = definers.values().iterator(); while (it.hasNext()) { @@ -340,7 +342,7 @@ it.remove(); } if (definers.size() == 0) { - parameterDefiners.remove(new Integer(reg)); + parameterDefiners.remove(Integer14.valueOf(reg)); } } } @@ -349,11 +351,11 @@ if (parmSig.startsWith("L")) { parmSig = parmSig.substring( 1, parmSig.length() - 1).replace('/', '.'); if ("java.lang.Object".equals(parmSig)) { - parameterDefiners.remove(new Integer(reg)); + parameterDefiners.remove(Integer14.valueOf(reg)); return; } - Map<JavaClass, List<String>> definers = parameterDefiners.get(new Integer(reg)); + Map<JavaClass, List<String>> definers = parameterDefiners.get(Integer14.valueOf(reg)); if ((definers != null) && (definers.size() > 0)) { Iterator<JavaClass> it = definers.keySet().iterator(); while (it.hasNext()) { @@ -363,7 +365,7 @@ } if (definers.size() == 0) - parameterDefiners.remove(new Integer(reg)); + parameterDefiners.remove(Integer14.valueOf(reg)); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java 2006-05-17 05:10:55 UTC (rev 542) @@ -27,6 +27,8 @@ import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.JavaClass; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -109,7 +111,7 @@ indexToFieldMap.clear(); } else if ((seen == ISTORE) || (seen == IINC) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) { int reg = getIntOpRegister(seen); - indexToFieldMap.remove(new Integer(reg)); + indexToFieldMap.remove(Integer14.valueOf(reg)); } else if ((seen >= IALOAD) && (seen <= SALOAD)) { checkParms(); } @@ -134,7 +136,7 @@ if ((indexReg >= 0) && (fa != null)) { if (listFields.contains(fa.getFieldName())) { - String f = indexToFieldMap.get(new Integer(indexReg)); + String f = indexToFieldMap.get(Integer14.valueOf(indexReg)); if ((f != null) && (!f.equals(fa.getFieldName()))) { bugReporter.reportBug( new BugInstance( this, "PL_PARALLEL_LISTS", NORMAL_PRIORITY) .addClass(this) @@ -144,7 +146,7 @@ indexToFieldMap.clear(); } else - indexToFieldMap.put(new Integer(indexReg), fa.getFieldName()); + indexToFieldMap.put(Integer14.valueOf(indexReg), fa.getFieldName()); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java 2006-05-17 05:10:55 UTC (rev 542) @@ -25,6 +25,8 @@ import org.apache.bcel.classfile.Code; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -113,7 +115,7 @@ String methodName = getNameConstantOperand(); if (queryClasses.contains(clsName) && queryMethods.contains(methodName)) - queryLocations.add(new Integer(getPC())); + queryLocations.add(Integer14.valueOf(getPC())); } else if ((seen == GOTO) || (seen == GOTO_W)) { int branchTarget = getBranchTarget(); int pc = getPC(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2006-05-17 05:10:55 UTC (rev 542) @@ -29,6 +29,7 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -170,7 +171,7 @@ OpcodeStack.Item item = stack.getStackItem(0); if ("Ljavax/swing/JLabel;".equals(item.getSignature())) { int reg = RegisterUtils.getAStoreReg(this, seen); - localLabels.put(new Integer(reg), SourceLineAnnotation.fromVisitedInstruction(this)); + localLabels.put(Integer14.valueOf(reg), SourceLineAnnotation.fromVisitedInstruction(this)); } } } else if (seen == INVOKEVIRTUAL) { @@ -198,7 +199,7 @@ else { int reg = item.getRegisterNumber(); if (reg >= 0) { - localLabels.remove(new Integer(reg)); + localLabels.remove(Integer14.valueOf(reg)); } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2006-05-17 05:10:55 UTC (rev 542) @@ -27,6 +27,8 @@ import org.apache.bcel.classfile.ConstantFieldref; import org.apache.bcel.classfile.ConstantNameAndType; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -117,14 +119,14 @@ } } else if (seen == ALOAD) { int reg = getRegisterOperand(); - if (localCollections.contains(new Integer(reg))) { - collectionInfo = new Integer(reg); + if (localCollections.contains(Integer14.valueOf(reg))) { + collectionInfo = Integer14.valueOf(reg); state = SEEN_LOAD; } } else if ((seen >= ALOAD_0) && (seen <= ALOAD_3)) { int reg = seen - ALOAD_0; - if (localCollections.contains(new Integer(reg))) { - collectionInfo = new Integer(reg); + if (localCollections.contains(Integer14.valueOf(reg))) { + collectionInfo = Integer14.valueOf(reg); state = SEEN_LOAD; } } else if (seen == GETFIELD) { @@ -142,10 +144,10 @@ case SEEN_SYNC: if (seen == ASTORE) { int reg = getRegisterOperand(); - localCollections.add(new Integer(reg)); + localCollections.add(Integer14.valueOf(reg)); } else if ((seen >= ASTORE_0) && (seen <= ASTORE_3)) { int reg = seen - ASTORE_0; - localCollections.add(new Integer(reg)); + localCollections.add(Integer14.valueOf(reg)); } else if (seen == PUTFIELD) { ConstantFieldref ref = (ConstantFieldref)getConstantRefOperand(); @@ -198,7 +200,7 @@ OpcodeStack.Item item = stack.getStackItem(0); int reg = item.getRegisterNumber(); if (reg >= 0) - monitorObjects.add(new Integer(reg)); + monitorObjects.add(Integer14.valueOf(reg)); else { FieldAnnotation fa = item.getField(); if (fa != null) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-05-17 05:10:55 UTC (rev 542) @@ -25,6 +25,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.Integer14; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -41,24 +43,24 @@ private static final int SEEN_LOAD = 2; private static final Set<Integer> branchInstructions = new HashSet<Integer>(); static { - branchInstructions.add(new Integer(GOTO)); - branchInstructions.add(new Integer(GOTO_W)); - branchInstructions.add(new Integer(IFEQ)); - branchInstructions.add(new Integer(IFNE)); - branchInstructions.add(new Integer(IFLT)); - branchInstructions.add(new Integer(IFGE)); - branchInstructions.add(new Integer(IFGT)); - branchInstructions.add(new Integer(IFLE)); - branchInstructions.add(new Integer(IF_ICMPEQ)); - branchInstructions.add(new Integer(IF_ICMPNE)); - branchInstructions.add(new Integer(IF_ICMPLT)); - branchInstructions.add(new Integer(IF_ICMPGE)); - branchInstructions.add(new Integer(IF_ICMPGT)); - branchInstructions.add(new Integer(IF_ICMPLE)); - branchInstructions.add(new Integer(IF_ACMPEQ)); - branchInstructions.add(new Integer(IF_ACMPNE)); - branchInstructions.add(new Integer(IFNULL)); - branchInstructions.add(new Integer(IFNONNULL)); + branchInstructions.add(Integer14.valueOf(GOTO)); + branchInstructions.add(Integer14.valueOf(GOTO_W)); + branchInstructions.add(Integer14.valueOf(IFEQ)); + branchInstructions.add(Integer14.valueOf(IFNE)); + branchInstructions.add(Integer14.valueOf(IFLT)); + branchInstructions.add(Integer14.valueOf(IFGE)); + branchInstructions.add(Integer14.valueOf(IFGT)); + branchInstructions.add(Integer14.valueOf(IFLE)); + branchInstructions.add(Integer14.valueOf(IF_ICMPEQ)); + branchInstructions.add(Integer14.valueOf(IF_ICMPNE)); + branchInstructions.add(Integer14.valueOf(IF_ICMPLT)); + branchInstructions.add(Integer14.valueOf(IF_ICMPGE)); + branchInstructions.add(Integer14.valueOf(IF_ICMPGT)); + branchInstructions.add(Integer14.valueOf(IF_ICMPLE)); + branchInstructions.add(Integer14.valueOf(IF_ACMPEQ)); + branchInstructions.add(Integer14.valueOf(IF_ACMPNE)); + branchInstructions.add(Integer14.valueOf(IFNULL)); + branchInstructions.add(Integer14.valueOf(IFNONNULL)); } private BugReporter bugReporter; @@ -120,7 +122,7 @@ break; case SEEN_STORE: - if (branchTargets.contains(new Integer(getPC()))) { + if (branchTargets.contains(Integer14.valueOf(getPC()))) { state = SEEN_NOTHING; return; } @@ -139,8 +141,8 @@ break; } - if (branchInstructions.contains(new Integer(seen))) { - branchTargets.add(new Integer(getBranchTarget())); + if (branchInstructions.contains(Integer14.valueOf(seen))) { + branchTargets.add(Integer14.valueOf(getBranchTarget())); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java 2006-05-17 05:10:55 UTC (rev 542) @@ -27,6 +27,7 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -111,7 +112,7 @@ try { stack.mergeJumps(this); - Set<Integer> regs = localScopeEnds.remove(new Integer(getPC())); + Set<Integer> regs = localScopeEnds.remove(Integer14.valueOf(getPC())); if (regs != null) { for (Integer i : regs) { localCollections.remove(i); @@ -156,26 +157,26 @@ throws ClassNotFoundException { int reg = colItm.getRegisterNumber(); if (reg != -1) { - Set<SourceLineAnnotation> pcs = localSourceLineAnnotations.get(new Integer(reg)); + Set<SourceLineAnnotation> pcs = localSourceLineAnnotations.get(Integer14.valueOf(reg)); if (pcs == null) { pcs = new HashSet<SourceLineAnnotation>(); - localSourceLineAnnotations.put(new Integer(reg), pcs); + localSourceLineAnnotations.put(Integer14.valueOf(reg), pcs); } pcs.add(SourceLineAnnotation.fromVisitedInstruction(this, getPC())); - Set<String> commonSupers = localCollections.get(new Integer(reg)); + Set<String> commonSupers = localCollections.get(Integer14.valueOf(reg)); if (commonSupers != null) mergeItem(commonSupers, pcs, addItm); else { commonSupers = new HashSet<String>(); - localCollections.put(new Integer(reg), commonSupers); + localCollections.put(Integer14.valueOf(reg), commonSupers); addNewItem(commonSupers, addItm); - Integer scopeEnd = new Integer(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC())); + Integer scopeEnd = Integer14.valueOf(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC())); Set<Integer> regs = localScopeEnds.get(scopeEnd); if (regs == null) { regs = new HashSet<Integer>(); localScopeEnds.put(scopeEnd, regs); } - regs.add(new Integer(reg)); + regs.add(Integer14.valueOf(reg)); } } else { FieldAnnotation fa = colItm.getField(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Integer14.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Integer14.java 2006-05-17 05:03:21 UTC (rev 541) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Integer14.java 2006-05-17 05:10:55 UTC (rev 542) @@ -20,8 +20,8 @@ public class Integer14 { - public static final int MIN_CACHE = -32; - public static final int MAX_CACHE = 32; + public static final int MIN_CACHE = -10; + public static final int MAX_CACHE = 256; private static final Integer[] cachedInts = new Integer[MAX_CACHE-MIN_CACHE+1]; static { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-05-17 05:03:28
|
Revision: 541 Author: dbrosius Date: 2006-05-16 22:03:21 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=541&view=rev Log Message: ----------- jdk1.5's Integer is pretty useful. Add this class to get the caching functionality that is missing in 1.4 Added Paths: ----------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Integer14.java Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Integer14.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Integer14.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/Integer14.java 2006-05-17 05:03:21 UTC (rev 541) @@ -0,0 +1,41 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 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.utils; + +public class Integer14 +{ + public static final int MIN_CACHE = -32; + public static final int MAX_CACHE = 32; + + private static final Integer[] cachedInts = new Integer[MAX_CACHE-MIN_CACHE+1]; + static { + for (int i = MIN_CACHE; i <= MAX_CACHE; i++) + cachedInts[i-MIN_CACHE] = new Integer(i); + } + + private Integer14() + {} + + public static Integer valueOf(int i) + { + if ((i < MIN_CACHE) || (i > MAX_CACHE)) + return new Integer(i); + return cachedInts[i-MIN_CACHE]; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |