fb-contrib-commit Mailing List for fb-contrib (Page 50)
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-08-14 05:07:12
|
Revision: 615 Author: dbrosius Date: 2006-08-13 22:07:07 -0700 (Sun, 13 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=615&view=rev Log Message: ----------- guard against npes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-14 05:00:38 UTC (rev 614) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-14 05:07:07 UTC (rev 615) @@ -183,9 +183,11 @@ LocalVariableTable lvt = getMethod().getLocalVariableTable(); if (lvt != null) { LocalVariable lv = lvt.getLocalVariable(reg, pc); - int finish = lv.getStartPC() + lv.getLength(); - if (finish < catchInfo.getFinish()) - catchInfo.setFinish(finish); + if (lv != null) { + int finish = lv.getStartPC() + lv.getLength(); + if (finish < catchInfo.getFinish()) + catchInfo.setFinish(finish); + } } break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-14 05:00:45
|
Revision: 614 Author: dbrosius Date: 2006-08-13 22:00:38 -0700 (Sun, 13 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=614&view=rev Log Message: ----------- if the localvariabletable attribute exists, use the lifetime of the catch exception variable as a determiner of when the catch block ends. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-12 17:18:40 UTC (rev 613) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-14 05:00:38 UTC (rev 614) @@ -32,6 +32,8 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.CodeException; import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.LocalVariable; +import org.apache.bcel.classfile.LocalVariableTable; import org.apache.bcel.classfile.Method; import com.mebigfatguy.fbcontrib.utils.Integer14; @@ -178,6 +180,13 @@ int reg = RegisterUtils.getAStoreReg(this, seen); catchInfo.setReg(reg); exReg.put(Integer14.valueOf(reg), Boolean.TRUE); + LocalVariableTable lvt = getMethod().getLocalVariableTable(); + if (lvt != null) { + LocalVariable lv = lvt.getLocalVariable(reg, pc); + int finish = lv.getStartPC() + lv.getLength(); + if (finish < catchInfo.getFinish()) + catchInfo.setFinish(finish); + } break; } } else if (pc > catchInfo.getFinish()) { @@ -280,6 +289,10 @@ return catchFinish; } + public void setFinish(int finish) { + catchFinish = finish; + } + public int getRegister() { return exReg; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 17:18:45
|
Revision: 613 Author: dbrosius Date: 2006-08-12 10:18:40 -0700 (Sat, 12 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=613&view=rev Log Message: ----------- in order for it to be recursion, method has to be called on 'this' -- duh! Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java 2006-08-12 15:20:44 UTC (rev 612) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java 2006-08-12 17:18:40 UTC (rev 613) @@ -20,10 +20,13 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Method; +import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; /** * looks for methods that make a recursive call to itself as the last statement in the @@ -35,8 +38,11 @@ public static final int TAILRECURSIONFUDGE = 6; private BugReporter bugReporter; + private OpcodeStack stack; private int trPCPos; private boolean possibleTailRecursion; + private boolean isStatic; + /** * constructs a TR detector given the reporter to report bugs on @@ -47,6 +53,20 @@ } /** + * implements the visitor to create and clear the stack + * + * @param classContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } finally { + stack = null; + } + } + /** * implements the visitor to figure the pc where the method call must occur * depending on whether the method returns a value, or not. * @@ -64,6 +84,8 @@ } trPCPos -= TAILRECURSIONFUDGE; possibleTailRecursion = true; + isStatic = obj.isStatic(); + stack.resetForMethodEntry(this); super.visitMethod(obj); } } @@ -76,19 +98,33 @@ */ @Override public void sawOpcode(int seen) { - if (seen == INVOKEVIRTUAL) { - boolean isRecursion = (getMethodName().equals(getNameConstantOperand())) - && (getMethodSig().equals(getSigConstantOperand())) - && (getClassName().equals(getClassConstantOperand())); + try { + stack.mergeJumps(this); - if (isRecursion && possibleTailRecursion && (getPC() >= trPCPos)) { - bugReporter.reportBug(new BugInstance(this, "TR_TAIL_RECURSION", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (seen == INVOKEVIRTUAL) { + boolean isRecursion = (getMethodName().equals(getNameConstantOperand())) + && (getMethodSig().equals(getSigConstantOperand())) + && (getClassName().equals(getClassConstantOperand())); + + if (isRecursion && !isStatic) { + int numParms = Type.getArgumentTypes(getMethodSig()).length; + if (stack.getStackDepth() > numParms) { + OpcodeStack.Item itm = stack.getStackItem(numParms); + isRecursion = (itm.getRegisterNumber() == 0); + } + } + + if (isRecursion && possibleTailRecursion && (getPC() >= trPCPos)) { + bugReporter.reportBug(new BugInstance(this, "TR_TAIL_RECURSION", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + else + possibleTailRecursion = false; } - else - possibleTailRecursion = false; + } finally { + stack.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-08-12 15:21:30
|
Revision: 612 Author: dbrosius Date: 2006-08-12 08:20:44 -0700 (Sat, 12 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=612&view=rev Log Message: ----------- initial checkin, new TR detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/TR_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-08-12 13:38:45 UTC (rev 611) +++ trunk/fb-contrib/etc/findbugs.xml 2006-08-12 15:20:44 UTC (rev 612) @@ -238,6 +238,10 @@ speed="fast" reports="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.TailRecursion" + speed="fast" + reports="TR_TAIL_RECURSION" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -297,4 +301,5 @@ <BugPattern abbrev="UTA" type="UTA_USE_TO_ARRAY" category="STYLE" /> <BugPattern abbrev="LEST" type="LEST_LOST_EXCEPTION_STACK_TRACE" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="UCPM" type="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="TR" type="TR_TAIL_RECURSION" 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-08-12 13:38:45 UTC (rev 611) +++ trunk/fb-contrib/etc/messages.xml 2006-08-12 15:20:44 UTC (rev 612) @@ -641,6 +641,17 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.TailRecursion"> + <Details> + <![CDATA[ + <p>looks for methods that make a recursive call to itself as the last statement in the + method. This tail recursion could be converted into a simple loop which would improve + the performance and stack requirements.</p> + <p>It is a fast detector.</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1387,6 +1398,18 @@ </Details> </BugPattern> + <BugPattern type="TR_TAIL_RECURSION"> + <ShortDescription>Method employs tail recursion</ShortDescription> + <LongDescription>Method {1} employs tail recursion</LongDescription> + <Details> + <![CDATA[ + <p>This method recursively calls itself as the last statement of the method + (Tail Recursion). This method can be easily refactored into a simple loop, which + will make it more performant, and reduce the stack size requirements. + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1441,4 +1464,5 @@ <BugCode abbrev="UTA">Use toArray</BugCode> <BugCode abbrev="LEST">Lost Exception Stack Trace</BugCode> <BugCode abbrev="UCPM">Use Character Parameterized Method</BugCode> + <BugCode abbrev="TR">Tail Recursion</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/TR_Sample.java =================================================================== --- trunk/fb-contrib/samples/TR_Sample.java (rev 0) +++ trunk/fb-contrib/samples/TR_Sample.java 2006-08-12 15:20:44 UTC (rev 612) @@ -0,0 +1,11 @@ + +public class TR_Sample +{ + public int factorial(int n) + { + if (n == 1) + return 1; + + return n * factorial(n-1); + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java 2006-08-12 15:20:44 UTC (rev 612) @@ -0,0 +1,94 @@ +/* + * 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 org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; + +/** + * looks for methods that make a recursive call to itself as the last statement in the + * method. This tail recursion could be converted into a simple loop which would improve + * the performance and stack requirements. + */ +public class TailRecursion extends BytecodeScanningDetector +{ + public static final int TAILRECURSIONFUDGE = 6; + + private BugReporter bugReporter; + private int trPCPos; + private boolean possibleTailRecursion; + /** + * constructs a TR detector given the reporter to report bugs on + + * @param bugReporter the sync of bug reports + */ + public TailRecursion(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * implements the visitor to figure the pc where the method call must occur + * depending on whether the method returns a value, or not. + * + * @param obj the context object of the currently parsed method + */ + @Override + public void visitMethod(Method obj) { + Code c = obj.getCode(); + if (c != null) { + byte[] opcodes = c.getCode(); + if (opcodes != null) { + trPCPos = c.getCode().length - 1; + if (!obj.getSignature().endsWith("V")) { + trPCPos -= 1; + } + trPCPos -= TAILRECURSIONFUDGE; + possibleTailRecursion = true; + super.visitMethod(obj); + } + } + } + + /** + * implements the visitor to find methods that employ tail recursion + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + if (seen == INVOKEVIRTUAL) { + boolean isRecursion = (getMethodName().equals(getNameConstantOperand())) + && (getMethodSig().equals(getSigConstantOperand())) + && (getClassName().equals(getClassConstantOperand())); + + if (isRecursion && possibleTailRecursion && (getPC() >= trPCPos)) { + bugReporter.reportBug(new BugInstance(this, "TR_TAIL_RECURSION", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + else + possibleTailRecursion = false; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 13:38:52
|
Revision: 611 Author: dbrosius Date: 2006-08-12 06:38:45 -0700 (Sat, 12 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=611&view=rev Log Message: ----------- add copyright Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-12 03:26:13 UTC (rev 610) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-12 13:38:45 UTC (rev 611) @@ -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.BitSet; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 03:26:17
|
Revision: 610 Author: dbrosius Date: 2006-08-11 20:26:13 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=610&view=rev Log Message: ----------- better descriptions Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-08-12 02:33:27 UTC (rev 609) +++ trunk/fb-contrib/etc/messages.xml 2006-08-12 03:26:13 UTC (rev 610) @@ -1225,7 +1225,7 @@ <BugPattern type="S508C_NO_SETLABELFOR"> <ShortDescription>JLabel doesn't specify what it's labeling</ShortDescription> - <LongDescription>JLabel doesn't specify what it's labeling</LongDescription> + <LongDescription>JLabel in method {1} doesn't specify what it's labeling</LongDescription> <Details> <![CDATA[ <p>This class uses JLabels that do not specify what fields are being labeled. @@ -1238,7 +1238,7 @@ <BugPattern type="S508C_NO_SETSIZE"> <ShortDescription>Window sets size manually, and doesn't use pack</ShortDescription> - <LongDescription>Window sets size manually, and doesn't use pack</LongDescription> + <LongDescription>Window {0} sets size manually, and doesn't use pack</LongDescription> <Details> <![CDATA[ <p>This class creates a window, and sizes the window using setSize. It is better This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 02:33:31
|
Revision: 609 Author: dbrosius Date: 2006-08-11 19:33:27 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=609&view=rev Log Message: ----------- it is difficult to determine where a catch block ends, when the last instruction of the try is a return. As a start, if a store to the catch exception occurs, after the first one, assume the catch has stopped. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-12 01:15:27 UTC (rev 608) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-12 02:33:27 UTC (rev 609) @@ -223,7 +223,11 @@ } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - exReg.put(Integer14.valueOf(RegisterUtils.getAStoreReg(this, seen)), (Boolean)itm.getUserValue()); + int reg = RegisterUtils.getAStoreReg(this, seen); + exReg.put(Integer14.valueOf(reg), (Boolean)itm.getUserValue()); + if ((reg == catchInfo.getRegister() && catchInfo.getFinish() == Integer.MAX_VALUE)) { + it.remove(); + } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { Boolean valid = exReg.get(Integer14.valueOf(RegisterUtils.getALoadReg(this, seen))); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 01:15:35
|
Revision: 608 Author: dbrosius Date: 2006-08-11 18:15:27 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=608&view=rev Log Message: ----------- fix some false positives with LEST Modified Paths: -------------- trunk/fb-contrib/samples/LEST_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/samples/LEST_Sample.java =================================================================== --- trunk/fb-contrib/samples/LEST_Sample.java 2006-08-12 00:47:46 UTC (rev 607) +++ trunk/fb-contrib/samples/LEST_Sample.java 2006-08-12 01:15:27 UTC (rev 608) @@ -30,4 +30,32 @@ throw new IllegalArgumentException(pe.getMessage(), pe); } } + + public Date testLestFP1(String input) throws ParseException + { + try + { + DateFormat df = new SimpleDateFormat("YYYY"); + return df.parse(input); + } + catch (ParseException pe) + { + throw pe; + } + } + + public Date testLestFP2(String input) + { + try + { + DateFormat df = new SimpleDateFormat("YYYY"); + return df.parse(input); + } + catch (ParseException pe) + { + IllegalArgumentException iae = new IllegalArgumentException(pe.getMessage()); + iae.initCause(pe); + throw iae; + } + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-12 00:47:46 UTC (rev 607) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-12 01:15:27 UTC (rev 608) @@ -20,9 +20,11 @@ import java.util.ArrayList; import java.util.BitSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.bcel.Constants; @@ -32,6 +34,7 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -60,6 +63,7 @@ private OpcodeStack stack; private CodeException[] exceptions; private Set<CatchInfo> catchInfos; + private Map<Integer, Boolean> exReg; /** * constructs a LEST detector given the reporter to report bugs on @@ -82,12 +86,14 @@ if ((throwableClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { stack = new OpcodeStack(); catchInfos = new HashSet<CatchInfo>(); + exReg = new HashMap<Integer, Boolean>(); super.visitClassContext(classContext); } } finally { stack = null; catchInfos = null; exceptions = null; + exReg = null; } } @@ -121,6 +127,7 @@ stack.resetForMethodEntry(this); catchInfos.clear(); exceptions = collectExceptions(obj.getExceptionTable()); + exReg.clear(); super.visitCode(obj); } } @@ -168,7 +175,9 @@ CatchInfo catchInfo = it.next(); if (pc == catchInfo.getStart()) { if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { - catchInfo.setReg(RegisterUtils.getAStoreReg(this, seen)); + int reg = RegisterUtils.getAStoreReg(this, seen); + catchInfo.setReg(reg); + exReg.put(Integer14.valueOf(reg), Boolean.TRUE); break; } } else if (pc > catchInfo.getFinish()) { @@ -190,7 +199,13 @@ String className = getClassConstantOperand(); JavaClass exClass = Repository.lookupClass(className); if (exClass.instanceOf(throwableClass)) { - markAsValid = true; + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); + int reg = itm.getRegisterNumber(); + if (reg >= 0) + exReg.put(Integer14.valueOf(reg), Boolean.TRUE); + markAsValid = true; // Fixes javac generated code + } } } else if (seen == ATHROW) { if (stack.getStackDepth() > 0) { @@ -205,6 +220,15 @@ break; } } + } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + exReg.put(Integer14.valueOf(RegisterUtils.getAStoreReg(this, seen)), (Boolean)itm.getUserValue()); + } + } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { + Boolean valid = exReg.get(Integer14.valueOf(RegisterUtils.getALoadReg(this, seen))); + if (valid != null) + markAsValid = valid.booleanValue(); } } } catch (ClassNotFoundException cnfe) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 00:47:53
|
Revision: 607 Author: dbrosius Date: 2006-08-11 17:47:46 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=607&view=rev Log Message: ----------- add StringBuffer.append dynamically if class is 1.5 or better Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-12 00:45:12 UTC (rev 606) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-12 00:47:46 UTC (rev 607) @@ -58,9 +58,13 @@ public void visitClassContext(final ClassContext context) { try { stack = new OpcodeStack(); + if (context.getJavaClass().getMajor() >= Constants.MAJOR_1_5) { + characterMethods.put("java/lang/StringBuffer:append:(Ljava/lang/String;)Ljava/lang/StringBuffer;", Integer14.valueOf(0)); + } super.visitClassContext(context); } finally { stack = null; + characterMethods.remove("java/lang/StringBuffer:append:(Ljava/lang/String;)Ljava/lang/StringBuffer;"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 00:45:31
|
Revision: 606 Author: dbrosius Date: 2006-08-11 17:45:12 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=606&view=rev Log Message: ----------- don't do startsWith (for now) Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-10 19:49:23 UTC (rev 605) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-12 00:45:12 UTC (rev 606) @@ -31,7 +31,7 @@ characterMethods.put("java/lang/String:indexOf:(Ljava/lang/String;I)I", Integer14.valueOf(1)); characterMethods.put("java/lang/String:lastIndexOf:(Ljava/lang/String;)I", Integer14.valueOf(0)); characterMethods.put("java/lang/String:lastIndexOf:(Ljava/lang/String;I)I", Integer14.valueOf(1)); - characterMethods.put("java/lang/String:startsWith:(Ljava/lang/String;)Z", Integer14.valueOf(0)); + //characterMethods.put("java/lang/String:startsWith:(Ljava/lang/String;)Z", Integer14.valueOf(0)); characterMethods.put("java/io/PrintStream:print:(Ljava/lang/String;)V", Integer14.valueOf(0)); characterMethods.put("java/io/PrintStream:println:(Ljava/lang/String;)V", Integer14.valueOf(0)); characterMethods.put("java/io/StringWriter:write:(Ljava/lang/String;)V", Integer14.valueOf(0)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-10 19:49:27
|
Revision: 605 Author: dbrosius Date: 2006-08-10 12:49:23 -0700 (Thu, 10 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=605&view=rev Log Message: ----------- add spaces Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-08-10 18:04:51 UTC (rev 604) +++ trunk/fb-contrib/htdocs/index.html 2006-08-10 19:49:23 UTC (rev 605) @@ -58,7 +58,7 @@ Looks for methods that catch exceptions, and rethrow another exception without encapsulating the original exception within it. Doing this loses the stack history, and where the original problem occurred. This makes finding and fixing errors difficult.</li> - <li><b>[UCPM] UseCharacterParameterizedMethod</b><br/> + <li><b>[UCPM] Use Character Parameterized Method</b><br/> Looks for methods that pass single character string constants as parameters to methods that alternatively have an overridden method that accepts a character instead. It is easier for the method to handle a single character than a String.</li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-10 18:04:54
|
Revision: 604 Author: dbrosius Date: 2006-08-10 11:04:51 -0700 (Thu, 10 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=604&view=rev Log Message: ----------- space Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-08-10 18:04:04 UTC (rev 603) +++ trunk/fb-contrib/htdocs/index.html 2006-08-10 18:04:51 UTC (rev 604) @@ -58,7 +58,7 @@ Looks for methods that catch exceptions, and rethrow another exception without encapsulating the original exception within it. Doing this loses the stack history, and where the original problem occurred. This makes finding and fixing errors difficult.</li> - <li><b>[UCPM]UseCharacterParameterizedMethod</b><br/> + <li><b>[UCPM] UseCharacterParameterizedMethod</b><br/> Looks for methods that pass single character string constants as parameters to methods that alternatively have an overridden method that accepts a character instead. It is easier for the method to handle a single character than a String.</li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-10 18:04:18
|
Revision: 603 Author: dbrosius Date: 2006-08-10 11:04:04 -0700 (Thu, 10 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=603&view=rev Log Message: ----------- doc UCPM Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-08-10 04:28:37 UTC (rev 602) +++ trunk/fb-contrib/htdocs/index.html 2006-08-10 18:04:04 UTC (rev 603) @@ -58,6 +58,10 @@ Looks for methods that catch exceptions, and rethrow another exception without encapsulating the original exception within it. Doing this loses the stack history, and where the original problem occurred. This makes finding and fixing errors difficult.</li> + <li><b>[UCPM]UseCharacterParameterizedMethod</b><br/> + Looks for methods that pass single character string constants as parameters to + methods that alternatively have an overridden method that accepts a character instead. + It is easier for the method to handle a single character than a String.</li> </div> <hr/> <img id="v2_8_0_image" src="flip2.gif" onClick="toggleBlock('v2_8_0', 'v2_8_0_image');" align="top"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-10 04:28:46
|
Revision: 602 Author: dbrosius Date: 2006-08-09 21:28:37 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=602&view=rev Log Message: ----------- more char methods Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-10 04:25:46 UTC (rev 601) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-10 04:28:37 UTC (rev 602) @@ -34,6 +34,7 @@ characterMethods.put("java/lang/String:startsWith:(Ljava/lang/String;)Z", Integer14.valueOf(0)); characterMethods.put("java/io/PrintStream:print:(Ljava/lang/String;)V", Integer14.valueOf(0)); characterMethods.put("java/io/PrintStream:println:(Ljava/lang/String;)V", Integer14.valueOf(0)); + characterMethods.put("java/io/StringWriter:write:(Ljava/lang/String;)V", Integer14.valueOf(0)); } private BugReporter bugReporter; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-10 04:25:51
|
Revision: 601 Author: dbrosius Date: 2006-08-09 21:25:46 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=601&view=rev Log Message: ----------- add more methods Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-10 04:21:25 UTC (rev 600) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-10 04:25:46 UTC (rev 601) @@ -32,6 +32,8 @@ characterMethods.put("java/lang/String:lastIndexOf:(Ljava/lang/String;)I", Integer14.valueOf(0)); characterMethods.put("java/lang/String:lastIndexOf:(Ljava/lang/String;I)I", Integer14.valueOf(1)); characterMethods.put("java/lang/String:startsWith:(Ljava/lang/String;)Z", Integer14.valueOf(0)); + characterMethods.put("java/io/PrintStream:print:(Ljava/lang/String;)V", Integer14.valueOf(0)); + characterMethods.put("java/io/PrintStream:println:(Ljava/lang/String;)V", Integer14.valueOf(0)); } private BugReporter bugReporter; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-10 04:21:36
|
Revision: 600 Author: dbrosius Date: 2006-08-09 21:21:25 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=600&view=rev Log Message: ----------- Initial checkin UCPM detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/UCPM_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-08-10 01:04:23 UTC (rev 599) +++ trunk/fb-contrib/etc/findbugs.xml 2006-08-10 04:21:25 UTC (rev 600) @@ -234,6 +234,10 @@ speed="moderate" reports="LEST_LOST_EXCEPTION_STACK_TRACE" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.UseCharacterParameterizedMethod" + speed="fast" + reports="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -291,5 +295,6 @@ <BugPattern abbrev="SACM" type="SACM_STATIC_ARRAY_CREATED_IN_METHOD" category="PERFORMANCE" /> <BugPattern abbrev="RMC" type="RMC_REDUNDANT_METHOD_CALLS" category="PERFORMANCE" /> <BugPattern abbrev="UTA" type="UTA_USE_TO_ARRAY" category="STYLE" /> - <BugPattern abbrev="LEST" type="LEST_LOST_EXCEPTION_STACK_TRACE" category="CORRECTNESS" /> + <BugPattern abbrev="LEST" type="LEST_LOST_EXCEPTION_STACK_TRACE" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="UCPM" type="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" 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-08-10 01:04:23 UTC (rev 599) +++ trunk/fb-contrib/etc/messages.xml 2006-08-10 04:21:25 UTC (rev 600) @@ -630,6 +630,17 @@ ]]> </Details> </Detector> + + <Detector class="com.mebigfatguy.fbcontrib.detect.UseCharacterParameterizedMethod"> + <Details> + <![CDATA[ + <p>looks for methods that pass single character string constants as parameters to + methods that alternatively have an overridden method that accepts a character instead. + It is easier for the method to handle a single character than a String.</p> + <p>It is a fast detector.</p> + ]]> + </Details> + </Detector> <!-- BugPattern --> @@ -1364,6 +1375,18 @@ </Details> </BugPattern> + <BugPattern type="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD"> + <ShortDescription>Method passes constant String of length 1 to character overridden method</ShortDescription> + <LongDescription>Method {1} passes constant String of length 1 to character overridden method</LongDescription> + <Details> + <![CDATA[ + <p>This method passes a constant literal String of length 1 as a parameter to a method, that + exposes a similar method that takes a character. It is simpler and more expedient to handle one + character, rather than pass a string.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1417,4 +1440,5 @@ <BugCode abbrev="RMC">Redundant Method Calls</BugCode> <BugCode abbrev="UTA">Use toArray</BugCode> <BugCode abbrev="LEST">Lost Exception Stack Trace</BugCode> + <BugCode abbrev="UCPM">Use Character Parameterized Method</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/UCPM_Sample.java =================================================================== --- trunk/fb-contrib/samples/UCPM_Sample.java (rev 0) +++ trunk/fb-contrib/samples/UCPM_Sample.java 2006-08-10 04:21:25 UTC (rev 600) @@ -0,0 +1,13 @@ + +public class UCPM_Sample +{ + public int testUcpm1(String s) + { + return s.indexOf("*") * 10; + } + + public String testUcpm2(String s) + { + return s.startsWith("*") ? s.substring(1) : s; + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2006-08-10 04:21:25 UTC (rev 600) @@ -0,0 +1,118 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.BitSet; +import java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.Constants; +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.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for methods that pass single character string constants as parameters to + * methods that alternatively have an overridden method that accepts a character instead. + * It is easier for the method to handle a single character than a String. + */ +public class UseCharacterParameterizedMethod extends BytecodeScanningDetector +{ + private static Map<String, Integer> characterMethods = new HashMap<String, Integer>(); + static { + //characterMethods.put("java/lang/StringBuffer:append:(Ljava/lang/String;)Ljava/lang/StringBuffer;", Integer14.valueOf(0)); + //characterMethods.put("java/lang/StringBuilder:append:(Ljava/lang/String;)Ljava/lang/StringBuilder;", Integer14.valueOf(0)); + characterMethods.put("java/lang/String:indexOf:(Ljava/lang/String;)I", Integer14.valueOf(0)); + characterMethods.put("java/lang/String:indexOf:(Ljava/lang/String;I)I", Integer14.valueOf(1)); + characterMethods.put("java/lang/String:lastIndexOf:(Ljava/lang/String;)I", Integer14.valueOf(0)); + characterMethods.put("java/lang/String:lastIndexOf:(Ljava/lang/String;I)I", Integer14.valueOf(1)); + characterMethods.put("java/lang/String:startsWith:(Ljava/lang/String;)Z", Integer14.valueOf(0)); + } + + private BugReporter bugReporter; + private OpcodeStack stack; + + /** + * constructs a UCPM detector given the reporter to report bugs on + + * @param bugReporter the sync of bug reports + */ + public UseCharacterParameterizedMethod(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * overrides the visitor to create and clear the opcode stack + * + * @param context the context object for the currently parsed class + */ + @Override + public void visitClassContext(final ClassContext context) { + try { + stack = new OpcodeStack(); + super.visitClassContext(context); + } finally { + stack = null; + } + } + + /** + * looks for methods that contain a LDC opcode + * + * @param method the context object of the current method + * @return if the class uses LDC instructions + */ + + private boolean prescreen(Method obj) { + BitSet bytecodeSet = getClassContext().getBytecodeSet(obj); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.LDC)); + } + + /** + * implement the visitor prescreen the method, and reset the stack + * + * @param obj the context object for the currently parsed method + */ + @Override + public void visitCode(Code obj) { + if (prescreen(getMethod())) { + stack.resetForMethodEntry(this); + super.visitCode(obj); + } + } + + /** + * implements the visitor to look for method calls that pass a constant string as a parameter when + * the string is only one character long, and there is an alternate method passing a character. + */ + @Override + public void sawOpcode(int seen) { + try { + stack.mergeJumps(this); + if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { + String key = getClassConstantOperand() + ":" + getNameConstantOperand() + ":" + getSigConstantOperand(); + Integer parmPos =characterMethods.get(key); + if (parmPos != null) { + int stackPos = parmPos.intValue(); + if (stack.getStackDepth() > stackPos) { + OpcodeStack.Item itm = stack.getStackItem(stackPos); + String con = (String)itm.getConstant(); + if ((con != null) && (con.length() == 1)) { + bugReporter.reportBug(new BugInstance(this, "UCPM_USE_CHARACTER_PARAMETERIZED_METHOD", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } + } finally { + stack.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-08-10 01:04:34
|
Revision: 599 Author: dbrosius Date: 2006-08-09 18:04:23 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=599&view=rev Log Message: ----------- fix DDC long description Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-08-09 04:17:59 UTC (rev 598) +++ trunk/fb-contrib/etc/messages.xml 2006-08-10 01:04:23 UTC (rev 599) @@ -1078,7 +1078,7 @@ <BugPattern type="DDC_DOUBLE_DATE_COMPARISON"> <ShortDescription>Method uses two date comparisons when one would do</ShortDescription> - <LongDescription>Method uses two date comparisons when one would do</LongDescription> + <LongDescription>Method {1} uses two date comparisons when one would do</LongDescription> <Details> <![CDATA[ <p>This method compares dates with two comparisons, rather than using the reverse comparison. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-09 04:18:05
|
Revision: 598 Author: dbrosius Date: 2006-08-08 21:17:59 -0700 (Tue, 08 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=598&view=rev Log Message: ----------- use RegisterUtils Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DateComparison.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DateComparison.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DateComparison.java 2006-08-08 12:49:59 UTC (rev 597) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DateComparison.java 2006-08-09 04:17:59 UTC (rev 598) @@ -23,6 +23,8 @@ import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -88,20 +90,16 @@ public void sawOpcode(int seen) { switch (state) { case SEEN_NOTHING: - if ((seen >= ALOAD_0) || (seen <= ALOAD_3)) - register1_1 = seen - ALOAD_0; - else if (seen == ALOAD) - register1_1 = getRegisterOperand(); - + if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) + register1_1 = RegisterUtils.getALoadReg(this, seen); + if (register1_1 > -1) state = SEEN_LOAD1_1; break; case SEEN_LOAD1_1: - if ((seen >= ALOAD_0) || (seen <= ALOAD_3)) - register1_2 = seen - ALOAD_0; - else if (seen == ALOAD) - register1_2 = getRegisterOperand(); + if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) + register1_2 = RegisterUtils.getALoadReg(this, seen); if (register1_2 > -1) state = SEEN_LOAD1_2; @@ -133,10 +131,8 @@ break; case SEEN_IFNE: - if ((seen >= ALOAD_0) || (seen <= ALOAD_3)) - register2_1 = seen - ALOAD_0; - else if (seen == ALOAD) - register2_1 = getRegisterOperand(); + if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) + register2_1 = RegisterUtils.getALoadReg(this, seen); if (register2_1 > -1) state = SEEN_LOAD2_1; @@ -145,10 +141,8 @@ break; case SEEN_LOAD2_1: - if ((seen >= ALOAD_0) || (seen <= ALOAD_3)) - register2_2 = seen - ALOAD_0; - else if (seen == ALOAD) - register2_2 = getRegisterOperand(); + if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) + register2_2 = RegisterUtils.getALoadReg(this, seen); if ((register2_2 > -1) && ( ((register1_1 == register2_1) && (register1_2 == register2_2)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 12:50:12
|
Revision: 597 Author: dbrosius Date: 2006-08-08 05:49:59 -0700 (Tue, 08 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=597&view=rev Log Message: ----------- base the signatures on Throwable, not Exception Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 06:28:26 UTC (rev 596) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 12:49:59 UTC (rev 597) @@ -47,12 +47,12 @@ */ public class LostExceptionStackTrace extends BytecodeScanningDetector { - private static JavaClass exceptionClass; + private static JavaClass throwableClass; static { try { - exceptionClass = Repository.lookupClass("java/lang/Exception"); + throwableClass = Repository.lookupClass("java/lang/Throwable"); } catch (ClassNotFoundException cnfe) { - exceptionClass = null; + throwableClass = null; } } @@ -79,7 +79,7 @@ public void visitClassContext(ClassContext classContext) { try { int majorVersion = classContext.getJavaClass().getMajor(); - if ((exceptionClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { + if ((throwableClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { stack = new OpcodeStack(); catchInfos = new HashSet<CatchInfo>(); super.visitClassContext(classContext); @@ -178,7 +178,7 @@ if ((seen == INVOKESPECIAL) && ("<init>".equals(getNameConstantOperand()))) { String className = getClassConstantOperand(); JavaClass exClass = Repository.lookupClass(className); - if (exClass.instanceOf(exceptionClass)) { + if (exClass.instanceOf(throwableClass)) { String sig = getSigConstantOperand(); if ((sig.indexOf("Exception") >= 0) || (sig.indexOf("Throwable") >= 0)) { @@ -189,7 +189,7 @@ } else if ((seen == INVOKEVIRTUAL) && "initCause".equals(getNameConstantOperand())) { String className = getClassConstantOperand(); JavaClass exClass = Repository.lookupClass(className); - if (exClass.instanceOf(exceptionClass)) { + if (exClass.instanceOf(throwableClass)) { markAsValid = true; } } else if (seen == ATHROW) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 06:28:31
|
Revision: 596 Author: dbrosius Date: 2006-08-07 23:28:26 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=596&view=rev Log Message: ----------- oops Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 06:23:16 UTC (rev 595) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 06:28:26 UTC (rev 596) @@ -175,8 +175,7 @@ it.remove(); break; } else if ((pc > catchInfo.getStart()) && (pc <= catchInfo.getFinish())) { - String methodName = getNameConstantOperand(); - if ((seen == INVOKESPECIAL) && ("<init>".equals(methodName))) { + if ((seen == INVOKESPECIAL) && ("<init>".equals(getNameConstantOperand()))) { String className = getClassConstantOperand(); JavaClass exClass = Repository.lookupClass(className); if (exClass.instanceOf(exceptionClass)) { @@ -187,7 +186,7 @@ break; } } - } else if ((seen == INVOKEVIRTUAL) && "initCause".equals(methodName)) { + } else if ((seen == INVOKEVIRTUAL) && "initCause".equals(getNameConstantOperand())) { String className = getClassConstantOperand(); JavaClass exClass = Repository.lookupClass(className); if (exClass.instanceOf(exceptionClass)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 06:23:25
|
Revision: 595 Author: dbrosius Date: 2006-08-07 23:23:16 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=595&view=rev Log Message: ----------- mark exceptions valid if initCause is called on them. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 06:07:51 UTC (rev 594) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 06:23:16 UTC (rev 595) @@ -175,7 +175,8 @@ it.remove(); break; } else if ((pc > catchInfo.getStart()) && (pc <= catchInfo.getFinish())) { - if ((seen == INVOKESPECIAL) && ("<init>".equals(getNameConstantOperand()))) { + String methodName = getNameConstantOperand(); + if ((seen == INVOKESPECIAL) && ("<init>".equals(methodName))) { String className = getClassConstantOperand(); JavaClass exClass = Repository.lookupClass(className); if (exClass.instanceOf(exceptionClass)) { @@ -186,6 +187,12 @@ break; } } + } else if ((seen == INVOKEVIRTUAL) && "initCause".equals(methodName)) { + String className = getClassConstantOperand(); + JavaClass exClass = Repository.lookupClass(className); + if (exClass.instanceOf(exceptionClass)) { + markAsValid = true; + } } else if (seen == ATHROW) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 06:07:56
|
Revision: 594 Author: dbrosius Date: 2006-08-07 23:07:51 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=594&view=rev Log Message: ----------- don't check synthetic methods Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 05:52:47 UTC (rev 593) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 06:07:51 UTC (rev 594) @@ -99,6 +99,9 @@ * @return if the class throws exceptions */ public boolean prescreen(Code code, Method method) { + if (method.isSynthetic()) + return false; + CodeException[] ce = code.getExceptionTable(); if ((ce == null) || (ce.length == 0)) return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 05:52:58
|
Revision: 593 Author: dbrosius Date: 2006-08-07 22:52:47 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=593&view=rev Log Message: ----------- document LEST Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-08-08 05:39:19 UTC (rev 592) +++ trunk/fb-contrib/htdocs/index.html 2006-08-08 05:52:47 UTC (rev 593) @@ -54,7 +54,10 @@ Looks for methods that implement synchronized blocks that appear to contain some code at the beginning that does not need to be synchronized. Moving these lines out of the synchronized block should help multithreaded performance.</li> - </ul> + <li><b>[LEST] Lost Exception Stack Trace</b><br/> + Looks for methods that catch exceptions, and rethrow another exception without encapsulating + the original exception within it. Doing this loses the stack history, and where the original + problem occurred. This makes finding and fixing errors difficult.</li> </div> <hr/> <img id="v2_8_0_image" src="flip2.gif" onClick="toggleBlock('v2_8_0', 'v2_8_0_image');" align="top"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 05:39:28
|
Revision: 592 Author: dbrosius Date: 2006-08-07 22:39:19 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=592&view=rev Log Message: ----------- fix fp's due to falling to clear catchInfos on method entry Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 05:06:38 UTC (rev 591) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 05:39:19 UTC (rev 592) @@ -18,9 +18,11 @@ */ package com.mebigfatguy.fbcontrib.detect; +import java.util.ArrayList; import java.util.BitSet; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; import org.apache.bcel.Constants; @@ -114,12 +116,29 @@ public void visitCode(Code obj) { if (prescreen(obj, getMethod())) { stack.resetForMethodEntry(this); - exceptions = obj.getExceptionTable(); + catchInfos.clear(); + exceptions = collectExceptions(obj.getExceptionTable()); super.visitCode(obj); } } /** + * collects all the valid exception objects (ones where start and finish are before the target + * + * @param exceptions the exceptions from the class file + * @return the filtered exceptions + */ + public CodeException[] collectExceptions(CodeException[] exceptions) { + List<CodeException> filteredEx = new ArrayList<CodeException>(); + for (CodeException ce : exceptions) { + if ((ce.getStartPC() < ce.getEndPC()) && (ce.getEndPC() < ce.getHandlerPC())) { + filteredEx.add(ce); + } + } + return filteredEx.toArray(new CodeException[filteredEx.size()]); + } + + /** * implements the visitor to find throwing alternative exceptions from a catch block, without * forwarding along the original exception */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 05:06:48
|
Revision: 591 Author: dbrosius Date: 2006-08-07 22:06:38 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=591&view=rev Log Message: ----------- LEST is starting to work (with many false positives) Modified Paths: -------------- trunk/fb-contrib/samples/LEST_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/samples/LEST_Sample.java =================================================================== --- trunk/fb-contrib/samples/LEST_Sample.java 2006-08-08 03:59:39 UTC (rev 590) +++ trunk/fb-contrib/samples/LEST_Sample.java 2006-08-08 05:06:38 UTC (rev 591) @@ -17,4 +17,17 @@ throw new IllegalArgumentException(pe.getMessage()); } } + + public Date testLest2(String input) + { + try + { + DateFormat df = new SimpleDateFormat("YYYY"); + return df.parse(input); + } + catch (ParseException pe) + { + throw new IllegalArgumentException(pe.getMessage(), pe); + } + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 03:59:39 UTC (rev 590) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 05:06:38 UTC (rev 591) @@ -19,13 +19,20 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.BitSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; import org.apache.bcel.Constants; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.CodeException; -import org.apache.bcel.classfile.ExceptionTable; +import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +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.OpcodeStack; @@ -38,8 +45,19 @@ */ public class LostExceptionStackTrace extends BytecodeScanningDetector { + private static JavaClass exceptionClass; + static { + try { + exceptionClass = Repository.lookupClass("java/lang/Exception"); + } catch (ClassNotFoundException cnfe) { + exceptionClass = null; + } + } + private BugReporter bugReporter; private OpcodeStack stack; + private CodeException[] exceptions; + private Set<CatchInfo> catchInfos; /** * constructs a LEST detector given the reporter to report bugs on @@ -59,12 +77,15 @@ public void visitClassContext(ClassContext classContext) { try { int majorVersion = classContext.getJavaClass().getMajor(); - if (majorVersion >= Constants.MAJOR_1_4) { + if ((exceptionClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { stack = new OpcodeStack(); + catchInfos = new HashSet<CatchInfo>(); super.visitClassContext(classContext); } } finally { stack = null; + catchInfos = null; + exceptions = null; } } @@ -93,6 +114,7 @@ public void visitCode(Code obj) { if (prescreen(obj, getMethod())) { stack.resetForMethodEntry(this); + exceptions = obj.getExceptionTable(); super.visitCode(obj); } } @@ -103,12 +125,107 @@ */ @Override public void sawOpcode(int seen) { + boolean markAsValid = false; + try { stack.mergeJumps(this); + int pc = getPC(); + for (CodeException ex : exceptions) { + if (pc == ex.getEndPC()) { + if ((seen >= IRETURN) && (seen <= RETURN)) { + addCatchBlock(ex.getHandlerPC(), Integer.MAX_VALUE); + } else if ((seen == GOTO) || (seen == GOTO_W)) + addCatchBlock(ex.getHandlerPC(), this.getBranchTarget()); + return; + } + } + Iterator<CatchInfo> it = catchInfos.iterator(); + while (it.hasNext()) { + try { + CatchInfo catchInfo = it.next(); + if (pc == catchInfo.getStart()) { + if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + catchInfo.setReg(RegisterUtils.getAStoreReg(this, seen)); + break; + } + } else if (pc > catchInfo.getFinish()) { + it.remove(); + break; + } else if ((pc > catchInfo.getStart()) && (pc <= catchInfo.getFinish())) { + if ((seen == INVOKESPECIAL) && ("<init>".equals(getNameConstantOperand()))) { + String className = getClassConstantOperand(); + JavaClass exClass = Repository.lookupClass(className); + if (exClass.instanceOf(exceptionClass)) { + String sig = getSigConstantOperand(); + if ((sig.indexOf("Exception") >= 0) + || (sig.indexOf("Throwable") >= 0)) { + markAsValid = true; + break; + } + } + } else if (seen == ATHROW) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + if ((itm.getRegisterNumber() != catchInfo.getRegister()) + && (itm.getUserValue() == null)) { + bugReporter.reportBug(new BugInstance(this, "LEST_LOST_EXCEPTION_STACK_TRACE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + it.remove(); + break; + } + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + it.remove(); + } + } } finally { stack.sawOpcode(this, seen); + if (markAsValid) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + itm.setUserValue(Boolean.TRUE); + } + } } } + + private void addCatchBlock(int start, int finish) { + CatchInfo ci = new CatchInfo(start, finish); + catchInfos.add(ci); + } + + private static class CatchInfo { + private int catchStart; + private int catchFinish; + private int exReg; + + public CatchInfo(int start, int finish) { + catchStart = start; + catchFinish = finish; + exReg = -1; + } + + public void setReg(int reg) { + exReg = reg; + } + + public int getStart() { + return catchStart; + } + + public int getFinish() { + return catchFinish; + } + + public int getRegister() { + return exReg; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |