fb-contrib-commit Mailing List for fb-contrib (Page 37)
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...> - 2007-10-18 05:38:43
|
Revision: 941 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=941&view=rev Author: dbrosius Date: 2007-10-17 22:38:45 -0700 (Wed, 17 Oct 2007) Log Message: ----------- make sure lastPCs[0] is initialized Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-18 05:37:16 UTC (rev 940) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-18 05:38:45 UTC (rev 941) @@ -113,7 +113,7 @@ if (seen == IRETURN) { byte[] bytes = getCode().getCode(); - if ((lastPCs[3] != -1) + if ((lastPCs[0] != -1) && ((0x00FF & bytes[lastPCs[3]]) == ICONST_0) && ((0x00FF & bytes[lastPCs[2]]) == GOTO) && ((0x00FF & bytes[lastPCs[1]]) == ICONST_1) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-18 05:37:12
|
Revision: 940 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=940&view=rev Author: dbrosius Date: 2007-10-17 22:37:16 -0700 (Wed, 17 Oct 2007) Log Message: ----------- record IFNULL and IFNONNULL branch targets Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-18 03:44:58 UTC (rev 939) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-18 05:37:16 UTC (rev 940) @@ -99,7 +99,7 @@ try { stack.mergeJumps(this); - if ((seen >= IFEQ) && (seen <= GOTO)) { + if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == IFNULL) || (seen == IFNONNULL) || (seen == GOTO_W)) { Integer branchTarget = Integer.valueOf(getBranchTarget()); Set<Integer> branchInsSet = branchTargets.get(branchTarget); if (branchInsSet == null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-18 03:44:58
|
Revision: 939 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=939&view=rev Author: dbrosius Date: 2007-10-17 20:44:58 -0700 (Wed, 17 Oct 2007) Log Message: ----------- try to salvage SPP_USELESS_TRINARY Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 06:06:58 UTC (rev 938) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-18 03:44:58 UTC (rev 939) @@ -111,25 +111,28 @@ } - if (seen == ICONST_0) { + if (seen == IRETURN) { byte[] bytes = getCode().getCode(); if ((lastPCs[3] != -1) - && ((0x00FF & bytes[lastPCs[3]]) == GOTO) - && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1) - && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) { - boolean bug = true; - Set<Integer> branchInsSet = branchTargets.get(Integer.valueOf(getPC())); - if (branchInsSet.size() > 1) - bug = false; - branchInsSet = branchTargets.get(Integer.valueOf(lastPCs[2])); - if (branchInsSet != null) - bug = false; - - if (bug) { - bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + && ((0x00FF & bytes[lastPCs[3]]) == ICONST_0) + && ((0x00FF & bytes[lastPCs[2]]) == GOTO) + && ((0x00FF & bytes[lastPCs[1]]) == ICONST_1) + && ((0x00FF & bytes[lastPCs[0]]) == IFEQ)) { + if (getMethod().getSignature().endsWith("Z")) { + boolean bug = true; + Set<Integer> branchInsSet = branchTargets.get(Integer.valueOf(lastPCs[1])); + if (branchInsSet != null) + bug = false; + branchInsSet = branchTargets.get(Integer.valueOf(lastPCs[3])); + if ((branchInsSet != null) && branchInsSet.size() > 1) + bug = false; + + if (bug) { + bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } } } else if (seen == LDC2_W) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-13 06:07:03
|
Revision: 938 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=938&view=rev Author: dbrosius Date: 2007-10-12 23:06:58 -0700 (Fri, 12 Oct 2007) Log Message: ----------- If the ICONST_1 instruction is the branch target of one or more src statements, or if the ICONST_0 is the branch target of two or more src statements, it is probably generated by the compiler so don't report. Modified Paths: -------------- trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 05:18:24 UTC (rev 937) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 06:06:58 UTC (rev 938) @@ -86,6 +86,9 @@ public boolean testFPUselessTrinary(boolean a, boolean b) { - return a || b; + if (a && b) + return a || b; + + return a && b; } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 05:18:24 UTC (rev 937) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 06:06:58 UTC (rev 938) @@ -19,7 +19,9 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.apache.bcel.Repository; @@ -45,7 +47,8 @@ private int lastPCs[]; private int lastOpcode; private int lastReg; - private Set<Integer> branchTargets; + /** branch targets, to a set of branch instructions */ + private Map<Integer, Set<Integer>> branchTargets; /** * constructs a SPP detector given the reporter to report bugs on @@ -60,7 +63,7 @@ try { stack = new OpcodeStack(); lastPCs = new int[4]; - branchTargets = new HashSet<Integer>(); + branchTargets = new HashMap<Integer, Set<Integer>>(); super.visitClassContext(classContext); } finally { stack = null; @@ -97,21 +100,37 @@ stack.mergeJumps(this); if ((seen >= IFEQ) && (seen <= GOTO)) { - branchTargets.add(Integer.valueOf(getBranchTarget())); + Integer branchTarget = Integer.valueOf(getBranchTarget()); + Set<Integer> branchInsSet = branchTargets.get(branchTarget); + if (branchInsSet == null) + { + branchInsSet = new HashSet<Integer>(); + branchTargets.put(branchTarget, branchInsSet); + } + branchInsSet.add(Integer.valueOf(getPC())); } if (seen == ICONST_0) { byte[] bytes = getCode().getCode(); if ((lastPCs[3] != -1) - && (!branchTargets.contains(Integer.valueOf(lastPCs[2]))) && ((0x00FF & bytes[lastPCs[3]]) == GOTO) && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1) && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) { - bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + boolean bug = true; + Set<Integer> branchInsSet = branchTargets.get(Integer.valueOf(getPC())); + if (branchInsSet.size() > 1) + bug = false; + branchInsSet = branchTargets.get(Integer.valueOf(lastPCs[2])); + if (branchInsSet != null) + bug = false; + + if (bug) { + bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } } else if (seen == LDC2_W) { Object con = getConstantRefOperand(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-13 05:18:22
|
Revision: 937 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=937&view=rev Author: dbrosius Date: 2007-10-12 22:18:24 -0700 (Fri, 12 Oct 2007) Log Message: ----------- if the ICONST_1 statement is the target of a seemingly unrelated branch, it is probably caused by compiler emitted code, so don't report. Modified Paths: -------------- trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 04:49:06 UTC (rev 936) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 05:18:24 UTC (rev 937) @@ -83,4 +83,9 @@ { return (b ? true : false); } + + public boolean testFPUselessTrinary(boolean a, boolean b) + { + return a || b; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 04:49:06 UTC (rev 936) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 05:18:24 UTC (rev 937) @@ -19,6 +19,8 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; @@ -43,6 +45,7 @@ private int lastPCs[]; private int lastOpcode; private int lastReg; + private Set<Integer> branchTargets; /** * constructs a SPP detector given the reporter to report bugs on @@ -57,10 +60,12 @@ try { stack = new OpcodeStack(); lastPCs = new int[4]; + branchTargets = new HashSet<Integer>(); super.visitClassContext(classContext); } finally { stack = null; lastPCs = null; + branchTargets = null; } } @@ -75,6 +80,7 @@ lastOpcode = -1; lastReg = -1; Arrays.fill(lastPCs, -1); + branchTargets.clear(); super.visitCode(obj); } @@ -90,9 +96,15 @@ try { stack.mergeJumps(this); + if ((seen >= IFEQ) && (seen <= GOTO)) { + branchTargets.add(Integer.valueOf(getBranchTarget())); + } + + if (seen == ICONST_0) { byte[] bytes = getCode().getCode(); if ((lastPCs[3] != -1) + && (!branchTargets.contains(Integer.valueOf(lastPCs[2]))) && ((0x00FF & bytes[lastPCs[3]]) == GOTO) && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1) && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-13 04:49:03
|
Revision: 936 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=936&view=rev Author: dbrosius Date: 2007-10-12 21:49:06 -0700 (Fri, 12 Oct 2007) Log Message: ----------- guard against a non initialized lastPCs array Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 03:30:42 UTC (rev 935) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 04:49:06 UTC (rev 936) @@ -92,7 +92,8 @@ if (seen == ICONST_0) { byte[] bytes = getCode().getCode(); - if (((0x00FF & bytes[lastPCs[3]]) == GOTO) + if ((lastPCs[3] != -1) + && ((0x00FF & bytes[lastPCs[3]]) == GOTO) && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1) && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) { bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-13 03:30:41
|
Revision: 935 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=935&view=rev Author: dbrosius Date: 2007-10-12 20:30:42 -0700 (Fri, 12 Oct 2007) Log Message: ----------- add SPP_USELESS_TRINARY to the SPP detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/etc/findbugs.xml 2007-10-13 03:30:42 UTC (rev 935) @@ -256,7 +256,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT" /> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT,SPP_USELESS_TRINARY" /> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -381,6 +381,7 @@ <BugPattern abbrev="SPP" type="SPP_EQUALS_ON_ENUM" category="CORRECTNESS" /> <BugPattern abbrev="SPP" type="SPP_INVALID_BOOLEAN_NULL_CHECK" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_CHARAT" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_USELESS_TRINARY" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" /> <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" /> <BugPattern abbrev="DWI" type="DWI_DELETING_WHILE_ITERATING" category="CORRECTNESS" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/etc/messages.xml 2007-10-13 03:30:42 UTC (rev 935) @@ -1869,6 +1869,17 @@ </Details> </BugPattern> + <BugPattern type="SPP_USELESS_TRINARY"> + <ShortDescription>Method uses a trinary operator to cast a boolean to true or false</ShortDescription> + <LongDescription>Method {1} uses a trinary operator to cast a boolean to true or false</LongDescription> + <Details> + <![CDATA[ + <p>This method tests the value of a boolean and using a trinary operator to return either true or false. + The trinary operator is completely unecessary, just use the original boolean value.</p> + ]]> + </Details> + </BugPattern> + <BugPattern type="BAS_BLOATED_ASSIGNMENT_SCOPE"> <ShortDescription>Method assigns a variable in a larger scope then is needed</ShortDescription> <LongDescription>Method {1} assigns a variable in a larger scope then is needed</LongDescription> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 03:30:42 UTC (rev 935) @@ -78,4 +78,9 @@ return s.toCharArray()[0]; return ' '; } + + public boolean testUselessTrinary(boolean b) + { + return (b ? true : false); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-12 01:51:10 UTC (rev 934) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 03:30:42 UTC (rev 935) @@ -90,7 +90,17 @@ try { stack.mergeJumps(this); - if (seen == LDC2_W) { + if (seen == ICONST_0) { + byte[] bytes = getCode().getCode(); + if (((0x00FF & bytes[lastPCs[3]]) == GOTO) + && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1) + && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) { + bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } else if (seen == LDC2_W) { Object con = getConstantRefOperand(); if (con instanceof ConstantDouble) { double d = ((ConstantDouble) con).getBytes(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-12 01:51:07
|
Revision: 934 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=934&view=rev Author: dbrosius Date: 2007-10-11 18:51:10 -0700 (Thu, 11 Oct 2007) Log Message: ----------- MRC can work on static methods as well Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java 2007-10-11 06:38:53 UTC (rev 933) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java 2007-10-12 01:51:10 UTC (rev 934) @@ -66,7 +66,8 @@ @Override public void visitCode(Code obj) { Method m = getMethod(); - if (((m.getAccessFlags() & Constants.ACC_PRIVATE) != 0) + int aFlags = m.getAccessFlags(); + if ((((aFlags & Constants.ACC_PRIVATE) != 0) || ((aFlags & Constants.ACC_STATIC) != 0)) && (!m.getSignature().endsWith(")Z"))) { stack.resetForMethodEntry(this); returnConstant = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-11 06:38:49
|
Revision: 933 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=933&view=rev Author: dbrosius Date: 2007-10-10 23:38:53 -0700 (Wed, 10 Oct 2007) Log Message: ----------- remove debugging stack trace printing Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-10-11 06:38:02 UTC (rev 932) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-10-11 06:38:53 UTC (rev 933) @@ -264,8 +264,6 @@ } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); - } catch (Exception e) { - e.printStackTrace(); } finally { stack.sawOpcode(this, seen); if (sawAlias) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-11 06:38:00
|
Revision: 932 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=932&view=rev Author: dbrosius Date: 2007-10-10 23:38:02 -0700 (Wed, 10 Oct 2007) Log Message: ----------- check for member collections now as well Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-10-11 05:57:21 UTC (rev 931) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-10-11 06:38:02 UTC (rev 932) @@ -33,6 +33,7 @@ import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; /** * looks for loops that transfers the contents of one collection to another. These collection sources @@ -54,10 +55,11 @@ private BugReporter bugReporter; private OpcodeStack stack; - /** register to alias register */ - private Map<Integer, Integer> userValues; + /** register/field to alias register/field */ + private Map<Comparable, Comparable> userValues; /** alias register to loop info */ - private Map<Integer, LoopInfo> loops; + private Map<Comparable, LoopInfo> loops; + private boolean isInstanceMethod; /** * constructs a UTA detector given the reporter to report bugs on @@ -99,8 +101,9 @@ public void visitCode(Code obj) { try { stack.resetForMethodEntry(this); - userValues = new HashMap<Integer, Integer>(); - loops = new HashMap<Integer, LoopInfo>(); + userValues = new HashMap<Comparable, Comparable>(); + loops = new HashMap<Comparable, LoopInfo>(); + isInstanceMethod = !getMethod().isStatic(); super.visitCode(obj); } finally { userValues = null; @@ -115,8 +118,8 @@ */ @Override public void sawOpcode(int seen) { - int reg = -1; - Integer uValue = null; + Comparable regOrField = null; + Comparable uValue = null; boolean sawAlias = false; boolean sawLoad = false; @@ -127,26 +130,41 @@ if ("get".equals(methodName) && "(I)Ljava/lang/Object;".equals(signature)) { if (stack.getStackDepth() > 1) { OpcodeStack.Item itm = stack.getStackItem(1); - reg = isLocalCollection(itm); + int reg = isLocalCollection(itm); if (reg >= 0) { + regOrField = Integer14.valueOf(reg); sawAlias = true; + } else { + String field = isFieldCollection(itm); + if (field != null) { + regOrField = field; + sawAlias = true; + } } } } else if ("keySet".equals(methodName) || "values".equals(methodName) || "iterator".equals(methodName) || "next".equals(methodName) || "hasNext".equals(methodName)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - reg = isLocalCollection(itm); + int reg = isLocalCollection(itm); if (reg >= 0) { + regOrField = Integer14.valueOf(reg); sawAlias = true; + } else { + String field = isFieldCollection(itm); + if (field != null) { + regOrField = field; + sawAlias = true; + } } } } else if ("add".equals(methodName) && "(Ljava/lang/Object;)Z".equals(signature)) { if (stack.getStackDepth() > 1) { OpcodeStack.Item colItem = stack.getStackItem(1); OpcodeStack.Item valueItem = stack.getStackItem(0); - reg = isLocalCollection(colItem); + int reg = isLocalCollection(colItem); if (reg >= 0) { - uValue = (Integer)valueItem.getUserValue(); + regOrField = Integer14.valueOf(reg); + uValue = (Comparable)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); if ((loop != null) && loop.isInLoop(getPC(), false)) { @@ -156,13 +174,28 @@ .addSourceLine(this)); } } + } else { + String field = isFieldCollection(colItem); + if (field != null) { + regOrField = field; + uValue = (Comparable)valueItem.getUserValue(); + if (uValue != null) { + LoopInfo loop = loops.get(uValue); + if ((loop != null) && loop.isInLoop(getPC(), false)) { + bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } } } } } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) || ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { if (stack.getStackDepth() > 0) { - uValue = (Integer)stack.getStackItem(0).getUserValue(); + uValue = (Comparable)stack.getStackItem(0).getUserValue(); userValues.put(Integer14.valueOf(RegisterUtils.getStoreReg(this, seen)), uValue); } } else if (((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3))) @@ -181,7 +214,7 @@ gotoPos += brOffset; if (gotoPos < getPC()) { OpcodeStack.Item itm = stack.getStackItem(0); - uValue = (Integer)itm.getUserValue(); + uValue = (Comparable)itm.getUserValue(); if (uValue != null) { loops.put(uValue, new LoopInfo(getPC(), getBranchTarget())); } @@ -198,6 +231,22 @@ } } } + } else if (isInstanceMethod && (seen == PUTFIELD)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item item = stack.getStackItem(1); + if (item.getRegisterNumber() == 0) { + uValue = (Comparable)stack.getStackItem(0).getUserValue(); + userValues.put(getNameConstantOperand(), uValue); + } + } + } else if (isInstanceMethod && (seen == GETFIELD)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if (item.getRegisterNumber() == 0) { + uValue = userValues.get(getNameConstantOperand()); + sawLoad = true; + } + } } else if (((seen > IFEQ) && (seen <= GOTO)) || (seen == IFNULL) || (seen == IFNONNULL)) { LoopInfo loop = findLoop(getPC(), true); if (loop != null) { @@ -206,29 +255,37 @@ } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - uValue = (Integer)itm.getUserValue(); + uValue = (Comparable)itm.getUserValue(); if (uValue != null) { - reg = ((Integer)uValue).intValue(); + regOrField = uValue; sawAlias = true; } } } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); + } catch (Exception e) { + e.printStackTrace(); } finally { stack.sawOpcode(this, seen); if (sawAlias) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - itm.setUserValue(Integer14.valueOf(reg)); + itm.setUserValue(regOrField); } } else if (sawLoad) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - reg = itm.getRegisterNumber(); + int reg = itm.getRegisterNumber(); if (reg >= 0) { uValue = userValues.get(Integer14.valueOf(reg)); itm.setUserValue(uValue); + } else { + XField xField = itm.getXField(); + if (xField != null) { + uValue = userValues.get(xField.getName()); + itm.setUserValue(uValue); + } } } } @@ -244,9 +301,9 @@ * @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(); + Comparable aliasReg = (Comparable)item.getUserValue(); + if (aliasReg instanceof Integer) + return ((Integer)aliasReg).intValue(); int reg = item.getRegisterNumber(); if (reg < 0) @@ -259,6 +316,30 @@ return -1; } + /** + * determines if the stack item refers to a collection that is stored in a field + * + * param item the stack item to check + * + * @return the field name of the collection, or null + * @throws ClassNotFoundException if the items class cannot be found + */ + private String isFieldCollection(OpcodeStack.Item item) throws ClassNotFoundException { + Comparable aliasReg = (Comparable)item.getUserValue(); + if (aliasReg instanceof String) + return (String)aliasReg; + + XField field = item.getXField(); + if (field == null) + return null; + + JavaClass cls = item.getJavaClass(); + if ((cls != null) && cls.implementationOf(collectionClass)) + return field.getName(); + + return null; + } + private LoopInfo findLoop(int pc, boolean ignoreConditionals) { for (LoopInfo loop : loops.values()) { if (loop.isInLoop(pc, ignoreConditionals)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-11 05:57:17
|
Revision: 931 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=931&view=rev Author: dbrosius Date: 2007-10-10 22:57:21 -0700 (Wed, 10 Oct 2007) Log Message: ----------- filter out RuntimeExceptions from throws clauses when building constraining info Modified Paths: -------------- trunk/fb-contrib/samples/EXS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java Modified: trunk/fb-contrib/samples/EXS_Sample.java =================================================================== --- trunk/fb-contrib/samples/EXS_Sample.java 2007-10-11 03:21:15 UTC (rev 930) +++ trunk/fb-contrib/samples/EXS_Sample.java 2007-10-11 05:57:21 UTC (rev 931) @@ -43,6 +43,19 @@ throw new RuntimeException("Ooops"); } } + + @Override + public void constrainedByRuntime() + { + try + { + InputStream is = new FileInputStream("c:\\test.txt"); + } + catch (IOException ioe) + { + throw new RuntimeException("Ooops"); + } + } } class Super @@ -52,4 +65,7 @@ public void constrainedNon() throws SQLException {} + + public void constrainedByRuntime() throws RuntimeException + {} } \ No newline at end of file Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-11 03:21:15 UTC (rev 930) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-11 05:57:21 UTC (rev 931) @@ -344,7 +344,7 @@ * @param m the method to add exceptions from * @return a map with one entry of a class name to a set of exceptions that constrain what can be thrown. */ - private Map<String, Set<String>> buildConstrainingInfo(JavaClass cls, Method m) { + private Map<String, Set<String>> buildConstrainingInfo(JavaClass cls, Method m) throws ClassNotFoundException { Map<String, Set<String>> constraintInfo = new HashMap<String, Set<String>>(); Set<String> exs = new HashSet<String>(); ExceptionTable et = m.getExceptionTable(); @@ -355,7 +355,10 @@ int index = indexTable[i]; if (index != 0) { ConstantClass ccls = (ConstantClass)pool.getConstant(index); - exs.add(ccls.getBytes(pool)); + String exName = ccls.getBytes(pool); + JavaClass exClass = Repository.lookupClass(exName); + if (!exClass.instanceOf(runtimeClass)) + exs.add(ccls.getBytes(pool)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-11 03:21:11
|
Revision: 930 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=930&view=rev Author: dbrosius Date: 2007-10-10 20:21:15 -0700 (Wed, 10 Oct 2007) Log Message: ----------- the branch offset of an ifne conditional may be negative if the 'target' is the loop end. in this case, use the loop end. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-10-11 02:45:03 UTC (rev 929) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-10-11 03:21:15 UTC (rev 930) @@ -199,11 +199,9 @@ } } } else if (((seen > IFEQ) && (seen <= GOTO)) || (seen == IFNULL) || (seen == IFNONNULL)) { - if (getBranchOffset() > 0) { - LoopInfo loop = findLoop(getPC(), true); - if (loop != null) { - loop.addConditionalRange(getPC(), getBranchTarget()); - } + LoopInfo loop = findLoop(getPC(), true); + if (loop != null) { + loop.addConditionalRange(getPC(), getBranchOffset() > 0 ? getBranchTarget() : loop.end); } } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-11 02:45:04
|
Revision: 929 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=929&view=rev Author: dbrosius Date: 2007-10-10 19:45:03 -0700 (Wed, 10 Oct 2007) Log Message: ----------- add fp case Modified Paths: -------------- trunk/fb-contrib/samples/UAA_Sample.java Modified: trunk/fb-contrib/samples/UAA_Sample.java =================================================================== --- trunk/fb-contrib/samples/UAA_Sample.java 2007-10-08 01:42:30 UTC (rev 928) +++ trunk/fb-contrib/samples/UAA_Sample.java 2007-10-11 02:45:03 UTC (rev 929) @@ -1,4 +1,6 @@ import java.util.HashSet; +import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -51,4 +53,16 @@ return out; } + + public void testFPIfAtEndOfLoop(List<String> d, List<String> s, int i) + { + Iterator<String> it = s.iterator(); + while (it.hasNext()) + { + if (i == 0) + { + d.add(it.next()); + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-08 01:42:26
|
Revision: 928 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=928&view=rev Author: dbrosius Date: 2007-10-07 18:42:30 -0700 (Sun, 07 Oct 2007) Log Message: ----------- set priority based on subtype of bug Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-08 01:39:46 UTC (rev 927) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-08 01:42:30 UTC (rev 928) @@ -167,10 +167,16 @@ constrainingInfo = getConstrainingInfo(getClassContext().getJavaClass(), getMethod()); String bug = null; - if (constrainingInfo == null) + int priority = NORMAL_PRIORITY; + + if (constrainingInfo == null) { bug = "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS"; - else if (!constrainingInfo.values().iterator().next().isEmpty()) + priority = HIGH_PRIORITY; + } + else if (!constrainingInfo.values().iterator().next().isEmpty()) { bug = "EXS_EXCEPTION_SOFTENING_HAS_CHECKED"; + priority = NORMAL_PRIORITY; + } else { String pack1 = constrainingInfo.keySet().iterator().next(); String pack2 = getClassContext().getJavaClass().getClassName(); @@ -184,12 +190,14 @@ pack2 = pack2.substring(0, dotPos); else pack2 = ""; - if (SignatureUtils.similarPackages(pack1, pack2, 2)) + if (SignatureUtils.similarPackages(pack1, pack2, 2)) { bug = "EXS_EXCEPTION_SOFTENING_NO_CHECKED"; + priority = NORMAL_PRIORITY; + } } if (bug != null) { - bugReporter.reportBug(new BugInstance(this, bug, NORMAL_PRIORITY) + bugReporter.reportBug(new BugInstance(this, bug, priority) .addClass(this) .addMethod(this) .addSourceLine(this)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-08 01:39:44
|
Revision: 927 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=927&view=rev Author: dbrosius Date: 2007-10-07 18:39:46 -0700 (Sun, 07 Oct 2007) Log Message: ----------- document EXS Modified Paths: -------------- trunk/fb-contrib/htdocs/index.html Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2007-10-08 01:34:32 UTC (rev 926) +++ trunk/fb-contrib/htdocs/index.html 2007-10-08 01:39:46 UTC (rev 927) @@ -68,6 +68,13 @@ Looks for classes that implement Serializable and implements readObject and writeObject by just calling the readDefaultObject or writeDefaultObject of the stream parameter. As this is the standard behavior, implementing these methods is not needed.</li> + <li><b>[EXS] Exception Softening</b><br/> + looks for methods that catch checked exceptions, and throw unchecked exceptions in their + place. There are several levels of concern. Least important are methods constrained by + interface or super class contracts not to throw checked exceptions but appear owned by + the same author. Next are methods constrained by interface or super class contracts and + throw other types of checked exceptions. Lastly are method not constrained by any interface + or superclass contract.</b><br/> </ul> </div> <hr/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-08 01:34:29
|
Revision: 926 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=926&view=rev Author: dbrosius Date: 2007-10-07 18:34:32 -0700 (Sun, 07 Oct 2007) Log Message: ----------- differentiate the three types of EXS bugs. Break out similarPackages to SignatureUtils Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-10-07 23:41:34 UTC (rev 925) +++ trunk/fb-contrib/etc/messages.xml 2007-10-08 01:34:32 UTC (rev 926) @@ -2007,14 +2007,13 @@ </BugPattern> <BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS"> - <ShortDescription>constrained method converts checked exception to unchecked</ShortDescription> - <LongDescription>constrained method {1} converts checked exception to unchecked</LongDescription> + <ShortDescription>unconstrained method converts checked exception to unchecked</ShortDescription> + <LongDescription>unconstrained method {1} converts checked exception to unchecked</LongDescription> <Details> <![CDATA[ - <p>This method's exception signature is constrained by an interface or super class to not throw - any checked exceptions. Therefore a caught checked exception was converted to an unchecked exception - and thrown. However it appears that the class in question is owned by the same author as the constraining - interface or superclass. Consider changes the signature of this method to include the checked exception.</p> + <p>This method is not constrained by an interface or superclass, but converts a caught checked exception + to unchecked exception and thrown. It would be more appropriate just throw the checked exception, adding + the exception to the throws clause of the method. ]]> </Details> </BugPattern> @@ -2033,13 +2032,14 @@ </BugPattern> <BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CHECKED"> - <ShortDescription>unconstrained method converts checked exception to unchecked</ShortDescription> - <LongDescription>unconstrained method {1} converts checked exception to unchecked</LongDescription> + <ShortDescription>constrained method converts checked exception to unchecked</ShortDescription> + <LongDescription>constrained method {1} converts checked exception to unchecked</LongDescription> <Details> <![CDATA[ - <p>This method is not constrained by an interface or superclass, but converts a caught checked exception - to unchecked exception and thrown. It would be more appropriate just throw the checked exception, adding - the exception to the throws clause of the method. + <p>This method's exception signature is constrained by an interface or super class to not throw + any checked exceptions. Therefore a caught checked exception was converted to an unchecked exception + and thrown. However it appears that the class in question is owned by the same author as the constraining + interface or superclass. Consider changes the signature of this method to include the checked exception.</p> ]]> </Details> </BugPattern> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2007-10-07 23:41:34 UTC (rev 925) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2007-10-08 01:34:32 UTC (rev 926) @@ -33,6 +33,7 @@ import org.apache.bcel.generic.Type; import com.mebigfatguy.fbcontrib.utils.Integer14; +import com.mebigfatguy.fbcontrib.utils.SignatureUtils; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -262,7 +263,7 @@ thisClsAccessCount++; else { String calledPackage = getPackageName(calledClass); - if (similarPackages(calledPackage, packageName, 2) && !generalPurpose(calledClass)) { + if (SignatureUtils.similarPackages(calledPackage, packageName, 2) && !generalPurpose(calledClass)) { Set<Integer> lineNumbers = clsAccessCount.get(calledClass); if (lineNumbers == null) { lineNumbers = new HashSet<Integer>(); @@ -353,33 +354,4 @@ return ""; return className.substring(0, dotPos); } - - /** - * returns whether or not the two packages have the same first 'depth' parts, if they exist - * - * @param packName1 the first package to check - * @param packName2 the second package to check - * @param depth the number of package parts to check - * - * @return if they are similar - */ - private boolean similarPackages(final String packName1, final String packName2, int depth) { - if (depth == 0) - return true; - - int dot1 = packName1.indexOf('.'); - int dot2 = packName2.indexOf('.'); - if (dot1 < 0) - return (dot2 < 0); - else if (dot2 < 0) - return false; - - String s1 = packName1.substring(0, dot1); - String s2 = packName2.substring(0, dot2); - - if (!s1.equals(s2)) - return false; - - return similarPackages(packName1.substring(dot1+1), packName2.substring(dot2+1), depth-1); - } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-07 23:41:34 UTC (rev 925) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-08 01:34:32 UTC (rev 926) @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.BitSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; @@ -34,9 +35,12 @@ import org.apache.bcel.classfile.CodeException; import org.apache.bcel.classfile.ConstantClass; import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.ExceptionTable; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.SignatureUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -65,6 +69,7 @@ private OpcodeStack stack; private Map<Integer, CodeException> catchHandlerPCs; private List<CatchInfo> catchInfos; + private Map<String, Set<String>> constrainingInfo; /** constructs a EXS detector given the reporter to report bugs on. @@ -103,11 +108,13 @@ stack.resetForMethodEntry(this); catchHandlerPCs = collectExceptions(obj.getExceptionTable()); catchInfos = new ArrayList<CatchInfo>(); + constrainingInfo = null; super.visitCode(obj); } } finally { catchInfos = null; catchHandlerPCs = null; + constrainingInfo = null; } } @@ -155,10 +162,38 @@ } if (!anyRuntimes) { - bugReporter.reportBug(new BugInstance(this, "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + + if (constrainingInfo == null) + constrainingInfo = getConstrainingInfo(getClassContext().getJavaClass(), getMethod()); + + String bug = null; + if (constrainingInfo == null) + bug = "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS"; + else if (!constrainingInfo.values().iterator().next().isEmpty()) + bug = "EXS_EXCEPTION_SOFTENING_HAS_CHECKED"; + else { + String pack1 = constrainingInfo.keySet().iterator().next(); + String pack2 = getClassContext().getJavaClass().getClassName(); + int dotPos = pack1.lastIndexOf('.'); + if (dotPos >= 0) + pack1 = pack1.substring(0, dotPos); + else + pack1 = ""; + dotPos = pack2.lastIndexOf('.'); + if (dotPos >= 0) + pack2 = pack2.substring(0, dotPos); + else + pack2 = ""; + if (SignatureUtils.similarPackages(pack1, pack2, 2)) + bug = "EXS_EXCEPTION_SOFTENING_NO_CHECKED"; + } + + if (bug != null) { + bugReporter.reportBug(new BugInstance(this, bug, NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } } } @@ -235,6 +270,91 @@ return catchTypes; } + /** finds the super class or interface that constrains the types of exceptions that can be thrown from the given method + * + * @param m the method to check + * @return a map containing the class name to a set of exceptions that constrain this method + */ + public Map<String, Set<String>> getConstrainingInfo(JavaClass cls, Method m) throws ClassNotFoundException { + String methodName = m.getName(); + String methodSig = m.getSignature(); + + { + //First look for the method in interfaces of the class + JavaClass[] infClasses = cls.getInterfaces(); + + for (JavaClass infCls : infClasses) { + Method infMethod = findMethod(infCls, methodName, methodSig); + if (infMethod != null) { + return buildConstrainingInfo(infCls, infMethod); + } else { + Map<String, Set<String>> constrainingExs = getConstrainingInfo(infCls, m); + if (constrainingExs != null) { + return constrainingExs; + } + } + } + } + + { + //Next look at the superclass + JavaClass superCls = cls.getSuperClass(); + if (superCls != null) { + Method superMethod = findMethod(superCls, methodName, methodSig); + if (superMethod != null) { + return buildConstrainingInfo(superCls, superMethod); + } + + //Otherwise recursively call this on the super class + return getConstrainingInfo(superCls, m); + } + + return null; + } + } + + /** finds a method that matches the name and signature in the given class + * @param cls the class to look in + * @param methodName the name to look for + * @param methodSig the signature to look for + * + * @return the method or null + */ + private Method findMethod(JavaClass cls, String methodName, String methodSig) { + Method[] methods = cls.getMethods(); + for (Method method : methods) { + if (method.getName().equals(methodName) && method.getSignature().equals(methodSig)) { + return method; + } + } + return null; + } + + /** returns exception names describing what exceptions are allowed to be thrown + * + * @param cls the cls to find the exceptions in + * @param m the method to add exceptions from + * @return a map with one entry of a class name to a set of exceptions that constrain what can be thrown. + */ + private Map<String, Set<String>> buildConstrainingInfo(JavaClass cls, Method m) { + Map<String, Set<String>> constraintInfo = new HashMap<String, Set<String>>(); + Set<String> exs = new HashSet<String>(); + ExceptionTable et = m.getExceptionTable(); + if (et != null) { + int[] indexTable = et.getExceptionIndexTable(); + ConstantPool pool = cls.getConstantPool(); + for (int i = 0; i < indexTable.length; i++) { + int index = indexTable[i]; + if (index != 0) { + ConstantClass ccls = (ConstantClass)pool.getConstant(index); + exs.add(ccls.getBytes(pool)); + } + } + } + constraintInfo.put(cls.getClassName(), exs); + return constraintInfo; + } + /** returns whether a method explicitly throws an exception * * @param method the currently parsed method Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2007-10-07 23:41:34 UTC (rev 925) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/SignatureUtils.java 2007-10-08 01:34:32 UTC (rev 926) @@ -38,6 +38,36 @@ return findInheritedMethod(supers, methodName, signature) != null; } + /** + * returns whether or not the two packages have the same first 'depth' parts, if they exist + * + * @param packName1 the first package to check + * @param packName2 the second package to check + * @param depth the number of package parts to check + * + * @return if they are similar + */ + public static boolean similarPackages(final String packName1, final String packName2, int depth) { + if (depth == 0) + return true; + + int dot1 = packName1.indexOf('.'); + int dot2 = packName2.indexOf('.'); + if (dot1 < 0) + return (dot2 < 0); + else if (dot2 < 0) + return false; + + String s1 = packName1.substring(0, dot1); + String s2 = packName2.substring(0, dot2); + + if (!s1.equals(s2)) + return false; + + return similarPackages(packName1.substring(dot1+1), packName2.substring(dot2+1), depth-1); + } + + private static JavaClass findInheritedMethod(JavaClass[] classes, String methodName, String signature) { for (JavaClass cls : classes) { if (cls != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-07 23:41:45
|
Revision: 925 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=925&view=rev Author: dbrosius Date: 2007-10-07 16:41:34 -0700 (Sun, 07 Oct 2007) Log Message: ----------- if it's possible the pc is in a catch block that caught a runtime exception, don't report. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-07 22:38:41 UTC (rev 924) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-07 23:41:34 UTC (rev 925) @@ -20,11 +20,13 @@ import java.util.ArrayList; import java.util.BitSet; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Set; import org.apache.bcel.Constants; import org.apache.bcel.Repository; @@ -141,12 +143,24 @@ JavaClass exClass = itm.getJavaClass(); if (exClass.instanceOf(runtimeClass)) { if (catchInfos.size() > 0) { - String catchSignature = catchInfos.get(catchInfos.size() - 1).getSignature(); - - bugReporter.reportBug(new BugInstance(this, "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + Set<String> possibleCatchSignatures = findPossibleCatchSignatures(catchInfos, pc); + if (!possibleCatchSignatures.contains(exClass.getClassName())) { + boolean anyRuntimes = false; + for (String possibleCatches : possibleCatchSignatures) { + exClass = Repository.lookupClass(possibleCatches); + if (exClass.instanceOf(runtimeClass)) { + anyRuntimes = true; + break; + } + } + + if (!anyRuntimes) { + bugReporter.reportBug(new BugInstance(this, "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } } } @@ -199,6 +213,28 @@ } } + /** returns an array of catch types that the current pc is in + * + * @param catchInfos the list of catch infos for this method + * @param pc the current pc + * @return an set of catch exception types that the pc is currently in + */ + public Set<String> findPossibleCatchSignatures(List<CatchInfo> catchInfos, int pc) + { + Set<String> catchTypes = new HashSet<String>(); + ListIterator<CatchInfo> it = catchInfos.listIterator(catchInfos.size()); + while (it.hasPrevious()) { + CatchInfo ci = it.previous(); + if ((pc >= ci.getStart()) && (pc < ci.getFinish())) { + catchTypes.add(ci.getSignature()); + } else { + break; + } + } + + return catchTypes; + } + /** returns whether a method explicitly throws an exception * * @param method the currently parsed method This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-07 22:38:42
|
Revision: 924 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=924&view=rev Author: dbrosius Date: 2007-10-07 15:38:41 -0700 (Sun, 07 Oct 2007) Log Message: ----------- starting to find problems. Not yet differentiating severity of problems. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-06 22:29:47 UTC (rev 923) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-07 22:38:41 UTC (rev 924) @@ -20,18 +20,22 @@ import java.util.ArrayList; import java.util.BitSet; -import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; -import java.util.Set; +import java.util.ListIterator; +import java.util.Map; 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.ConstantClass; import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; @@ -47,10 +51,18 @@ */ public class ExceptionSoftening extends BytecodeScanningDetector { + private static JavaClass runtimeClass; + static { + try { + runtimeClass = Repository.lookupClass("java/lang/RuntimeException"); + } catch (ClassNotFoundException cnfe) { + runtimeClass = null; + } + } private BugReporter bugReporter; private OpcodeStack stack; - private LinkedHashMap<Integer, CodeException> catchHandlerPCs; - private Set<CatchInfo> catchInfos; + private Map<Integer, CodeException> catchHandlerPCs; + private List<CatchInfo> catchInfos; /** constructs a EXS detector given the reporter to report bugs on. @@ -68,8 +80,10 @@ @Override public void visitClassContext(ClassContext classContext) { try { - stack = new OpcodeStack(); - super.visitClassContext(classContext); + if (runtimeClass != null) { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } } finally { stack = null; } @@ -86,7 +100,7 @@ if (prescreen(method)) { stack.resetForMethodEntry(this); catchHandlerPCs = collectExceptions(obj.getExceptionTable()); - catchInfos = new HashSet<CatchInfo>(); + catchInfos = new ArrayList<CatchInfo>(); super.visitCode(obj); } } finally { @@ -103,8 +117,8 @@ public void sawOpcode(int seen) { try { stack.mergeJumps(this); - int nextPC = getNextPC(); - CodeException ex = catchHandlerPCs.get(Integer.valueOf(nextPC)); + int pc = getPC(); + CodeException ex = catchHandlerPCs.get(Integer.valueOf(pc)); if (ex != null) { int endPC; if ((seen == GOTO) || (seen == GOTO_W)) @@ -117,6 +131,30 @@ CatchInfo ci = new CatchInfo(ex.getHandlerPC(), endPC, catchSig); catchInfos.add(ci); } + + removeFinishedCatchBlocks(catchInfos, pc); + + if (seen == ATHROW) { + try { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + JavaClass exClass = itm.getJavaClass(); + if (exClass.instanceOf(runtimeClass)) { + if (catchInfos.size() > 0) { + String catchSignature = catchInfos.get(catchInfos.size() - 1).getSignature(); + + bugReporter.reportBug(new BugInstance(this, "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } + } + } finally { stack.sawOpcode(this, seen); } @@ -127,7 +165,7 @@ * and with a catch type * * @param exceptions the exceptions from the class file - * @return the filtered exceptions keyed by catch handler pc + * @return the filtered exceptions keyed by catch end pc */ private LinkedHashMap<Integer, CodeException> collectExceptions(CodeException[] exceptions) { List<CodeException> filteredEx = new ArrayList<CodeException>(); @@ -140,12 +178,27 @@ LinkedHashMap<Integer, CodeException> handlers = new LinkedHashMap<Integer, CodeException>(); for (CodeException ex : filteredEx) { - handlers.put(Integer.valueOf(ex.getHandlerPC()), ex); + handlers.put(Integer.valueOf(ex.getEndPC()), ex); } return handlers; } + /** remove catchinfo blocks from the map where the handler end is before the current pc + * + * @param handlers the exception handlers installed + * @param pc the current pc + */ + private void removeFinishedCatchBlocks(List<CatchInfo> catchInfos, int pc) + { + Iterator<CatchInfo> it = catchInfos.iterator(); + while (it.hasNext()) + { + if (it.next().getFinish() < pc) + it.remove(); + } + } + /** returns whether a method explicitly throws an exception * * @param method the currently parsed method This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-06 22:29:44
|
Revision: 923 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=923&view=rev Author: dbrosius Date: 2007-10-06 15:29:47 -0700 (Sat, 06 Oct 2007) Log Message: ----------- initial checkin - EXS detector - not even close to working Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/EXS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-10-01 03:27:47 UTC (rev 922) +++ trunk/fb-contrib/etc/findbugs.xml 2007-10-06 22:29:47 UTC (rev 923) @@ -295,6 +295,10 @@ speed="fast" reports="MOM_MISLEADING_OVERLOAD_MODEL" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.ExceptionSoftening" + speed="moderate" + reports="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS,EXS_EXCEPTION_SOFTENING_HAS_CHECKED,EXS_EXCEPTION_SOFTENING_NO_CHECKED" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -387,4 +391,7 @@ <BugPattern abbrev="MRC" type="MRC_METHOD_RETURNS_CONSTANT" category="STYLE" experimental="true" /> <BugPattern abbrev="NCS" type="NCS_NEEDLESS_CUSTOM_SERIALIZATION" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="MOM" type="MOM_MISLEADING_OVERLOAD_MODEL" category="STYLE" experimental="true" /> + <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS" category="STYLE" experimental="true" /> + <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_HAS_CHECKED" category="STYLE" experimental="true" /> + <BugPattern abbrev="EXS" type="EXS_EXCEPTION_SOFTENING_NO_CHECKED" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-10-01 03:27:47 UTC (rev 922) +++ trunk/fb-contrib/etc/messages.xml 2007-10-06 22:29:47 UTC (rev 923) @@ -801,6 +801,21 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.ExceptionSoftening"> + <Details> + <![CDATA[ + <p>looks for methods that catch checked exceptions, and throw unchecked + exceptions in their place. There are several levels of concern. Least + concerning are methods constrained by interface or super class contracts + not to throw checked exceptions but appear owned by the same author. Next + are methods constrained by interface or super class contracts and throw other + types of checked exceptions. Most egregious are method not constrained by any interface + or superclass contract.</p> + <p>It is a moderately fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -1991,6 +2006,44 @@ </Details> </BugPattern> + <BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS"> + <ShortDescription>constrained method converts checked exception to unchecked</ShortDescription> + <LongDescription>constrained method {1} converts checked exception to unchecked</LongDescription> + <Details> + <![CDATA[ + <p>This method's exception signature is constrained by an interface or super class to not throw + any checked exceptions. Therefore a caught checked exception was converted to an unchecked exception + and thrown. However it appears that the class in question is owned by the same author as the constraining + interface or superclass. Consider changes the signature of this method to include the checked exception.</p> + ]]> + </Details> + </BugPattern> + + <BugPattern type="EXS_EXCEPTION_SOFTENING_HAS_CHECKED"> + <ShortDescription>constrained method converts checked exception to unchecked instead of another allowable checked exception</ShortDescription> + <LongDescription>constrained method {1} converts checked exception to unchecked instead of another allowable checked exception</LongDescription> + <Details> + <![CDATA[ + <p>This method's exception signature is constrained by an interface of super class to not throw a + checked exception that was caught. Therefore this exception was converted to an unchecked exception and + thrown. It would probably be better to throw the closest checked exception allowed, and to annotate + the new exception with the original exception using the initial cause field.</p> + ]]> + </Details> + </BugPattern> + + <BugPattern type="EXS_EXCEPTION_SOFTENING_NO_CHECKED"> + <ShortDescription>unconstrained method converts checked exception to unchecked</ShortDescription> + <LongDescription>unconstrained method {1} converts checked exception to unchecked</LongDescription> + <Details> + <![CDATA[ + <p>This method is not constrained by an interface or superclass, but converts a caught checked exception + to unchecked exception and thrown. It would be more appropriate just throw the checked exception, adding + the exception to the throws clause of the method. + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2059,4 +2112,5 @@ <BugCode abbrev="MRC">Method Returns Constant</BugCode> <BugCode abbrev="NCS">Needless Custom Serialization</BugCode> <BugCode abbrev="MOM">Misleading Overload Model</BugCode> + <BugCode abbrev="EXS">Exception Softening</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/EXS_Sample.java =================================================================== --- trunk/fb-contrib/samples/EXS_Sample.java (rev 0) +++ trunk/fb-contrib/samples/EXS_Sample.java 2007-10-06 22:29:47 UTC (rev 923) @@ -0,0 +1,55 @@ +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.sql.SQLException; + + +public class EXS_Sample extends Super +{ + @Override + public void constrainedNone() + { + try + { + InputStream is = new FileInputStream("c:\\test.txt"); + } + catch (IOException ioe) + { + throw new RuntimeException("Ooops"); + } + } + + @Override + public void constrainedNon() throws SQLException + { + try + { + InputStream is = new FileInputStream("c:\\test.txt"); + } + catch (IOException ioe) + { + throw new RuntimeException("Ooops"); + } + } + + public void notConstrained() + { + try + { + InputStream is = new FileInputStream("c:\\test.txt"); + } + catch (IOException ioe) + { + throw new RuntimeException("Ooops"); + } + } +} + +class Super +{ + public void constrainedNone() + {} + + public void constrainedNon() throws SQLException + {} +} \ No newline at end of file Property changes on: trunk/fb-contrib/samples/EXS_Sample.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-10-06 22:29:47 UTC (rev 923) @@ -0,0 +1,182 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2007 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.ArrayList; +import java.util.BitSet; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Set; + +import org.apache.bcel.Constants; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; +import org.apache.bcel.classfile.ConstantClass; +import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.Method; + +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 catch checked exceptions, and throw unchecked + * exceptions in their place. There are several levels of concern. Least + * important are methods constrained by interface or super class contracts + * not to throw checked exceptions but appear owned by the same author. Next + * are methods constrained by interface or super class contracts and throw other + * types of checked exceptions. Lastly are method not constrained by any interface + * or superclass contract. + */ +public class ExceptionSoftening extends BytecodeScanningDetector +{ + private BugReporter bugReporter; + private OpcodeStack stack; + private LinkedHashMap<Integer, CodeException> catchHandlerPCs; + private Set<CatchInfo> catchInfos; + + + /** constructs a EXS detector given the reporter to report bugs on. + + * @param bugReporter the sync of bug reports + */ + public ExceptionSoftening(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** overrides the visitor to reset 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; + } + } + + /** overrides the visitor to look for methods that catch exceptions + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + try { + Method method = getMethod(); + if (prescreen(method)) { + stack.resetForMethodEntry(this); + catchHandlerPCs = collectExceptions(obj.getExceptionTable()); + catchInfos = new HashSet<CatchInfo>(); + super.visitCode(obj); + } + } finally { + catchInfos = null; + catchHandlerPCs = null; + } + } + + /** overrides the visitor to find catch blocks that throw runtime exceptions + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + try { + stack.mergeJumps(this); + int nextPC = getNextPC(); + CodeException ex = catchHandlerPCs.get(Integer.valueOf(nextPC)); + if (ex != null) { + int endPC; + if ((seen == GOTO) || (seen == GOTO_W)) + endPC = this.getBranchTarget(); + else + endPC = Integer.MAX_VALUE; + ConstantPool pool = getConstantPool(); + ConstantClass ccls = (ConstantClass)pool.getConstant(ex.getCatchType()); + String catchSig = ccls.getBytes(pool); + CatchInfo ci = new CatchInfo(ex.getHandlerPC(), endPC, catchSig); + catchInfos.add(ci); + } + } finally { + stack.sawOpcode(this, seen); + } + } + + /** + * collects all the valid exception objects (ones where start and finish are before the target) + * and with a catch type + * + * @param exceptions the exceptions from the class file + * @return the filtered exceptions keyed by catch handler pc + */ + private LinkedHashMap<Integer, CodeException> collectExceptions(CodeException[] exceptions) { + List<CodeException> filteredEx = new ArrayList<CodeException>(); + for (CodeException ce : exceptions) { + if ((ce.getCatchType() != 0) && (ce.getStartPC() < ce.getEndPC()) && (ce.getEndPC() <= ce.getHandlerPC())) { + filteredEx.add(ce); + } + } + + LinkedHashMap<Integer, CodeException> handlers = new LinkedHashMap<Integer, CodeException>(); + + for (CodeException ex : filteredEx) { + handlers.put(Integer.valueOf(ex.getHandlerPC()), ex); + } + + return handlers; + } + + /** returns whether a method explicitly throws an exception + * + * @param method the currently parsed method + * @return if the method throws an exception + */ + private boolean prescreen(Method method) { + BitSet bytecodeSet = getClassContext().getBytecodeSet(method); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.ATHROW)); + } + + private static class CatchInfo { + private int catchStart; + private int catchFinish; + private String catchSignature; + + public CatchInfo(int start, int finish, String signature) { + catchStart = start; + catchFinish = finish; + catchSignature = signature; + } + + public int getStart() { + return catchStart; + } + + public int getFinish() { + return catchFinish; + } + + public String getSignature() { + return catchSignature; + } + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-10-01 03:27:44
|
Revision: 922 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=922&view=rev Author: dbrosius Date: 2007-09-30 20:27:47 -0700 (Sun, 30 Sep 2007) Log Message: ----------- initial checkin, new MOM detector Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/MOM_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2007-09-30 03:06:51 UTC (rev 921) +++ trunk/fb-contrib/etc/findbugs.xml 2007-10-01 03:27:47 UTC (rev 922) @@ -291,6 +291,10 @@ speed="fast" reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel" + speed="fast" + reports="MOM_MISLEADING_OVERLOAD_MODEL" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -382,4 +386,5 @@ <BugPattern abbrev="UAA" type="UAA_USE_ADD_ALL" category="STYLE" experimental="true" /> <BugPattern abbrev="MRC" type="MRC_METHOD_RETURNS_CONSTANT" category="STYLE" experimental="true" /> <BugPattern abbrev="NCS" type="NCS_NEEDLESS_CUSTOM_SERIALIZATION" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="MOM" type="MOM_MISLEADING_OVERLOAD_MODEL" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2007-09-30 03:06:51 UTC (rev 921) +++ trunk/fb-contrib/etc/messages.xml 2007-10-01 03:27:47 UTC (rev 922) @@ -790,6 +790,17 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel"> + <Details> + <![CDATA[ + <p>looks for classes that define both static and instance methods with the same name. + As each type represents a different use model, it doesn't make sense that this name + would be overloaded, and will confuse users of the class.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -1969,6 +1980,17 @@ </Details> </BugPattern> + <BugPattern type="MOM_MISLEADING_OVERLOAD_MODEL"> + <ShortDescription>class 'overloads' a method with both instance and static versions</ShortDescription> + <LongDescription>class {0} 'overloads' a method with both instance and static versions</LongDescription> + <Details> + <![CDATA[ + <p>This class 'overloads' the same method with both an instance and static version. As the use + of these two models is different, it will be confusing to the users of these methods.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -2036,4 +2058,5 @@ <BugCode abbrev="UAA">Use Add All</BugCode> <BugCode abbrev="MRC">Method Returns Constant</BugCode> <BugCode abbrev="NCS">Needless Custom Serialization</BugCode> + <BugCode abbrev="MOM">Misleading Overload Model</BugCode> </MessageCollection> \ No newline at end of file Added: trunk/fb-contrib/samples/MOM_Sample.java =================================================================== --- trunk/fb-contrib/samples/MOM_Sample.java (rev 0) +++ trunk/fb-contrib/samples/MOM_Sample.java 2007-10-01 03:27:47 UTC (rev 922) @@ -0,0 +1,11 @@ + +public class MOM_Sample +{ + public void test(int i) + { + } + + public static void test(int i, int j) + { + } +} Property changes on: trunk/fb-contrib/samples/MOM_Sample.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java 2007-10-01 03:27:47 UTC (rev 922) @@ -0,0 +1,69 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugInstance; +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.Detector; +import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XFactory; +import edu.umd.cs.findbugs.visitclass.PreorderVisitor; + +/** looks for classes that define both static and instance methods with the same name. + * This 'overloading' is confusing as one method is instance based the other class based, + * and points to a confusion in implementation. + */ +public class MisleadingOverloadModel extends PreorderVisitor implements Detector +{ + private static enum MethodType { INSTANCE, STATIC, BOTH }; + private BugReporter bugReporter; + + /** + * constructs a MOM detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public MisleadingOverloadModel(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + public void visitClassContext(ClassContext classContext) { + Map<String, MethodType> declMethods = new HashMap<String, MethodType>(); + JavaClass cls = classContext.getJavaClass(); + String clsName = cls.getClassName(); + Method[] methods = cls.getMethods(); + for (Method m : methods) { + String methodName = m.getName(); + boolean report = false; + MethodType newType; + if (m.isStatic()) { + report = declMethods.get(methodName) == MethodType.INSTANCE; + if (report) + newType = MethodType.BOTH; + else + newType = MethodType.STATIC; + } else { + report = declMethods.get(m.getName()) == MethodType.STATIC; + if (report) + newType = MethodType.BOTH; + else + newType = MethodType.INSTANCE; + } + + declMethods.put(methodName, newType); + if (report) { + bugReporter.reportBug(new BugInstance(this, "MOM_MISLEADING_OVERLOAD_MODEL", NORMAL_PRIORITY) + .addClass(cls) + .addMethod(XFactory.createXMethod(clsName, m)) + .addString(methodName)); + } + } + } + + /** implements the visitor to do nothing */ + public void report() { + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-09-30 03:06:49
|
Revision: 921 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=921&view=rev Author: dbrosius Date: 2007-09-29 20:06:51 -0700 (Sat, 29 Sep 2007) Log Message: ----------- simplify the problem Modified Paths: -------------- trunk/fb-contrib/samples/SMII_Sample.java Modified: trunk/fb-contrib/samples/SMII_Sample.java =================================================================== --- trunk/fb-contrib/samples/SMII_Sample.java 2007-09-30 02:35:30 UTC (rev 920) +++ trunk/fb-contrib/samples/SMII_Sample.java 2007-09-30 03:06:51 UTC (rev 921) @@ -67,11 +67,6 @@ } public static SMII_Sample testInstanceAsFirstParm(SMII_Sample sample, String s1) { - return sample.testInstanceAsFirstParm(s1); + return sample; } - - public SMII_Sample testInstanceAsFirstParm(String s1) - { - return null; - } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-09-30 02:35:35
|
Revision: 920 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=920&view=rev Author: dbrosius Date: 2007-09-29 19:35:30 -0700 (Sat, 29 Sep 2007) Log Message: ----------- add fp to fix Modified Paths: -------------- trunk/fb-contrib/samples/SMII_Sample.java Modified: trunk/fb-contrib/samples/SMII_Sample.java =================================================================== --- trunk/fb-contrib/samples/SMII_Sample.java 2007-09-27 10:39:13 UTC (rev 919) +++ trunk/fb-contrib/samples/SMII_Sample.java 2007-09-30 02:35:30 UTC (rev 920) @@ -57,7 +57,21 @@ public static class Inner { - private Inner next; - + private Inner next; } + + public void testFPInstance(SMII_Sample sample) + { + SMII_Sample.testInstanceAsFirstParm(sample, ""); + SMII_Sample.testInstanceAsFirstParm(sample, ""); + } + public static SMII_Sample testInstanceAsFirstParm(SMII_Sample sample, String s1) + { + return sample.testInstanceAsFirstParm(s1); + } + + public SMII_Sample testInstanceAsFirstParm(String s1) + { + return null; + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-09-27 10:39:11
|
Revision: 919 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=919&view=rev Author: dbrosius Date: 2007-09-27 03:39:13 -0700 (Thu, 27 Sep 2007) Log Message: ----------- null out fields at each class parse Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2007-09-23 05:16:33 UTC (rev 918) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2007-09-27 10:39:13 UTC (rev 919) @@ -82,6 +82,8 @@ localizableFields = new HashMap<String, FieldInfo>(); visitedBlocks = new BitSet(); clsContext = classContext; + cfg = null; + cpg = null; JavaClass cls = classContext.getJavaClass(); Field[] fields = cls.getFields(); for (Field f : fields) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-09-23 05:16:31
|
Revision: 918 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=918&view=rev Author: dbrosius Date: 2007-09-22 22:16:33 -0700 (Sat, 22 Sep 2007) Log Message: ----------- warnings Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-09-19 05:03:28 UTC (rev 917) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-09-23 05:16:33 UTC (rev 918) @@ -82,7 +82,7 @@ private BugReporter bugReporter; private OpcodeStack stack; - private List<Set<Comparable>> collectionGroups; + private List<Set<Comparable<?>>> collectionGroups; private Map<Integer, Integer> groupToIterator; private Map<Integer, Loop> loops; @@ -106,7 +106,7 @@ try { stack = new OpcodeStack(); - collectionGroups = new ArrayList<Set<Comparable>>(); + collectionGroups = new ArrayList<Set<Comparable<?>>>(); groupToIterator = new HashMap<Integer, Integer>(); loops = new HashMap<Integer, Loop>(); super.visitClassContext(classContext); @@ -241,7 +241,7 @@ groupToIterator.put(id, regIt); } - Set<Comparable> group = collectionGroups.get(id.intValue()); + Set<Comparable<?>> group = collectionGroups.get(id.intValue()); if (group != null) { group.add(Integer14.valueOf(reg)); } @@ -291,8 +291,8 @@ } } - private Comparable getGroupElement(OpcodeStack.Item itm) { - Comparable groupElement = null; + private Comparable<?> getGroupElement(OpcodeStack.Item itm) { + Comparable<?> groupElement = null; int reg = itm.getRegisterNumber(); if (reg >= 0) @@ -315,18 +315,18 @@ if (id != null) return id.intValue(); - Comparable groupElement = getGroupElement(itm); + Comparable<?> groupElement = getGroupElement(itm); if (groupElement != null) { int numGroups = collectionGroups.size(); for (int i = 0; i < numGroups; i++) { - Set<? extends Comparable> group = collectionGroups.get(i); + Set<? extends Comparable<?>> group = collectionGroups.get(i); if (group.contains(groupElement)) { return i; } } if (addIfNotFound) { - Set<Comparable> group = new HashSet<Comparable>(); + Set<Comparable<?>> group = new HashSet<Comparable<?>>(); group.add(groupElement); collectionGroups.add(group); return collectionGroups.size() - 1; @@ -337,9 +337,9 @@ } private void removeFromCollectionGroup(OpcodeStack.Item itm) { - Comparable groupElement = getGroupElement(itm); + Comparable<?> groupElement = getGroupElement(itm); if (groupElement != null) { - for (Set<? extends Comparable> group : collectionGroups) { + for (Set<? extends Comparable<?>> group : collectionGroups) { if (group.contains(groupElement)) { group.remove(groupElement); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-09-19 05:03:25
|
Revision: 917 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=917&view=rev Author: dbrosius Date: 2007-09-18 22:03:28 -0700 (Tue, 18 Sep 2007) Log Message: ----------- It's not good enough to find the nestedSB useritem, the value has to be true (TRINARY fix) 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 2007-09-19 04:45:54 UTC (rev 916) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2007-09-19 05:03:28 UTC (rev 917) @@ -94,7 +94,7 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); nestedSB = (Boolean)itm.getUserValue(); - if (nestedSB != null) { + if ((nestedSB != null) && nestedSB.booleanValue()) { bugReporter.reportBug( new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", NORMAL_PRIORITY) .addClass(this) @@ -140,7 +140,8 @@ if (stack.getStackDepth() > 0) { itm = stack.getStackItem(0); - if (itm.getUserValue() != null) { + Boolean uValue = (Boolean)itm.getUserValue(); + if ((uValue != null) && uValue.booleanValue()) { bugReporter.reportBug( new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY) .addClass(this) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |