fb-contrib-commit Mailing List for fb-contrib (Page 16)
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...> - 2010-01-11 03:38:28
|
Revision: 1466 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1466&view=rev Author: dbrosius Date: 2010-01-11 03:38:21 +0000 (Mon, 11 Jan 2010) Log Message: ----------- remove deprecations 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 2010-01-10 17:58:57 UTC (rev 1465) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-01-11 03:38:21 UTC (rev 1466) @@ -227,7 +227,7 @@ } else if (seen == IFEQ) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - lastIfEqWasBoolean = "Z".equals(itm.getElementSignature()); + lastIfEqWasBoolean = "Z".equals(itm.getSignature()); } byte[] bytes = getCode().getCode(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 17:59:04
|
Revision: 1465 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1465&view=rev Author: dbrosius Date: 2010-01-10 17:58:57 +0000 (Sun, 10 Jan 2010) Log Message: ----------- add GOTO/GOTO_W support Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-10 17:39:51 UTC (rev 1464) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-10 17:58:57 UTC (rev 1465) @@ -172,7 +172,7 @@ { int insTarget = -1; - if ((seen >= IFEQ) && (seen <= IF_ACMPNE)) { + if (((seen >= IFEQ) && (seen <= IF_ACMPNE)) || (seen == GOTO) || (seen == GOTO_W)) { insTarget = getBranchTarget(); if (insTarget < getPC()) insTarget = -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 17:39:57
|
Revision: 1464 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1464&view=rev Author: dbrosius Date: 2010-01-10 17:39:51 +0000 (Sun, 10 Jan 2010) Log Message: ----------- fix branching guard checks Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-10 17:33:17 UTC (rev 1463) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-10 17:39:51 UTC (rev 1464) @@ -169,14 +169,20 @@ state = State.SAW_NOTHING; break; } - if (downwardBranchTarget == -1) { + + { + int insTarget = -1; if ((seen >= IFEQ) && (seen <= IF_ACMPNE)) { - downwardBranchTarget = getBranchTarget(); - if (downwardBranchTarget < getPC()) - downwardBranchTarget = -1; + insTarget = getBranchTarget(); + if (insTarget < getPC()) + insTarget = -1; } else if ((seen == LOOKUPSWITCH) || (seen == TABLESWITCH)) { - downwardBranchTarget = this.getDefaultSwitchOffset() + getPC(); + insTarget = this.getDefaultSwitchOffset() + getPC(); } + + if (insTarget > downwardBranchTarget) { + downwardBranchTarget = insTarget; + } } } else { state = State.SAW_NOTHING; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 17:33:23
|
Revision: 1463 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1463&view=rev Author: dbrosius Date: 2010-01-10 17:33:17 +0000 (Sun, 10 Jan 2010) Log Message: ----------- don't report in a lookup or table switch Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-10 17:16:34 UTC (rev 1462) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-10 17:33:17 UTC (rev 1463) @@ -169,19 +169,20 @@ state = State.SAW_NOTHING; break; } - if ((seen >= IFEQ) && (seen <= IF_ACMPNE)) { - downwardBranchTarget = getBranchTarget(); - if (downwardBranchTarget < getPC()) - downwardBranchTarget = -1; + if (downwardBranchTarget == -1) { + if ((seen >= IFEQ) && (seen <= IF_ACMPNE)) { + downwardBranchTarget = getBranchTarget(); + if (downwardBranchTarget < getPC()) + downwardBranchTarget = -1; + } else if ((seen == LOOKUPSWITCH) || (seen == TABLESWITCH)) { + downwardBranchTarget = this.getDefaultSwitchOffset() + getPC(); + } } } else { state = State.SAW_NOTHING; if (getPC() >= downwardBranchTarget) downwardBranchTarget = -1; } - - - } private static class BugInfo { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 17:16:40
|
Revision: 1462 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1462&view=rev Author: dbrosius Date: 2010-01-10 17:16:34 +0000 (Sun, 10 Jan 2010) Log Message: ----------- get fps to show up Modified Paths: -------------- trunk/fb-contrib/samples/PDP_Sample.java Modified: trunk/fb-contrib/samples/PDP_Sample.java =================================================================== --- trunk/fb-contrib/samples/PDP_Sample.java 2010-01-10 17:04:32 UTC (rev 1461) +++ trunk/fb-contrib/samples/PDP_Sample.java 2010-01-10 17:16:34 UTC (rev 1462) @@ -33,12 +33,12 @@ ArrayList<String> aal = (ArrayList<String>) l; } - public void testFPDerivableMethod(List<String> l) + protected void testFPDerivableMethod(List<String> l) { al = (ArrayList<String>) l; } - public void testMultiCasts(String key, Object o) { + public static void testMultiCasts(String key, Object o) { if (key.equals("Foo")) { double d = ((Double) o).doubleValue(); } @@ -47,7 +47,7 @@ } } - public String testFPFlimsyIfGuard(Comparable<?> c, boolean isNumber) { + public static String testFPFlimsyIfGuard(Comparable<?> c, boolean isNumber) { String s = c.toString(); if (isNumber) { Number n = (Number)c; @@ -57,8 +57,8 @@ return s; } - public String testFPTableSwitchGuard(Comparable<?> c, int type) { - String s = c.toString(); + private String testFPTableSwitchGuard(Comparable<?> c, int type) { + String s = ""; switch (type) { @@ -91,8 +91,8 @@ return s; } - public String testFPLookupSwitch(Comparable<?> c, int type) { - String s = c.toString(); + private String testFPLookupSwitch(Comparable<?> c, int type) { + String s = ""; switch (type) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 17:04:38
|
Revision: 1461 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1461&view=rev Author: dbrosius Date: 2010-01-10 17:04:32 +0000 (Sun, 10 Jan 2010) Log Message: ----------- add tableswitch Modified Paths: -------------- trunk/fb-contrib/samples/PDP_Sample.java Modified: trunk/fb-contrib/samples/PDP_Sample.java =================================================================== --- trunk/fb-contrib/samples/PDP_Sample.java 2010-01-10 17:01:50 UTC (rev 1460) +++ trunk/fb-contrib/samples/PDP_Sample.java 2010-01-10 17:04:32 UTC (rev 1461) @@ -57,7 +57,7 @@ return s; } - public String testFPFlimsySwitchGuard(Comparable<?> c, int type) { + public String testFPTableSwitchGuard(Comparable<?> c, int type) { String s = c.toString(); switch (type) @@ -70,6 +70,22 @@ case 1: s += s; break; + + case 2: + s += "0"; + break; + + case 3: + s +='3'; + break; + + case 4: + s = null; + break; + + case 5: + s = s.substring(0, 1); + break; } return s; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 17:01:56
|
Revision: 1460 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1460&view=rev Author: dbrosius Date: 2010-01-10 17:01:50 +0000 (Sun, 10 Jan 2010) Log Message: ----------- add a lookup switch case Modified Paths: -------------- trunk/fb-contrib/samples/PDP_Sample.java Modified: trunk/fb-contrib/samples/PDP_Sample.java =================================================================== --- trunk/fb-contrib/samples/PDP_Sample.java 2010-01-10 16:56:41 UTC (rev 1459) +++ trunk/fb-contrib/samples/PDP_Sample.java 2010-01-10 17:01:50 UTC (rev 1460) @@ -74,4 +74,26 @@ return s; } + + public String testFPLookupSwitch(Comparable<?> c, int type) { + String s = c.toString(); + + switch (type) + { + case 0: + Number n = (Number)c; + s += n.intValue(); + break; + + case 1000: + s += s; + break; + + case 10000: + s += "0"; + break; + } + + return s; + } } \ 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...> - 2010-01-10 16:56:47
|
Revision: 1459 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1459&view=rev Author: dbrosius Date: 2010-01-10 16:56:41 +0000 (Sun, 10 Jan 2010) Log Message: ----------- marginally better engrish Modified Paths: -------------- trunk/fb-contrib/htdocs/index.shtml Modified: trunk/fb-contrib/htdocs/index.shtml =================================================================== --- trunk/fb-contrib/htdocs/index.shtml 2010-01-10 16:54:46 UTC (rev 1458) +++ trunk/fb-contrib/htdocs/index.shtml 2010-01-10 16:56:41 UTC (rev 1459) @@ -86,7 +86,7 @@ <span style="color: #0000FF;">--contributed by Chris Peterson - THANKS!</span></li> <li><b>[SNG] Suspicious Null Guard</b><br/> Looks for code that checks to see if a field or local variable is not null, - before entering a code block either an if, or while statement, and then doesn't + before entering a code block (either an if, or while statement) and then doesn't reference that field or local in the block of code that is guarded by the null check. Instead it references another object of the same type. It is likely that null check is being done on the wrong variable, either because of a copy/paste error, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 16:54:52
|
Revision: 1458 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1458&view=rev Author: dbrosius Date: 2010-01-10 16:54:46 +0000 (Sun, 10 Jan 2010) Log Message: ----------- add SNG back in Modified Paths: -------------- trunk/fb-contrib/htdocs/index.shtml Modified: trunk/fb-contrib/htdocs/index.shtml =================================================================== --- trunk/fb-contrib/htdocs/index.shtml 2010-01-10 16:51:57 UTC (rev 1457) +++ trunk/fb-contrib/htdocs/index.shtml 2010-01-10 16:54:46 UTC (rev 1458) @@ -84,6 +84,13 @@ Looks for a variety of questionable method calls that will cause problems, are unsafe or use practices that might lead to bugs. <span style="color: #0000FF;">--contributed by Chris Peterson - THANKS!</span></li> + <li><b>[SNG] Suspicious Null Guard</b><br/> + Looks for code that checks to see if a field or local variable is not null, + before entering a code block either an if, or while statement, and then doesn't + reference that field or local in the block of code that is guarded by the null + check. Instead it references another object of the same type. It is likely that null + check is being done on the wrong variable, either because of a copy/paste error, + or a change in implementation.</li> </ul> </div> <hr/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 16:52:03
|
Revision: 1457 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1457&view=rev Author: dbrosius Date: 2010-01-10 16:51:57 +0000 (Sun, 10 Jan 2010) Log Message: ----------- rename WrongNullGuard to SuspiciousNullGuard Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml Added Paths: ----------- trunk/fb-contrib/samples/SNG_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java Removed Paths: ------------- trunk/fb-contrib/samples/WNG_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2010-01-10 02:14:08 UTC (rev 1456) +++ trunk/fb-contrib/etc/findbugs.xml 2010-01-10 16:51:57 UTC (rev 1457) @@ -313,8 +313,8 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField" speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" /> - <Detector class="com.mebigfatguy.fbcontrib.detect.WrongNullGuard" - speed="fast" hidden="true" reports="WNG_WRONG_NULL_FIELD_GUARD,WNG_WRONG_NULL_LOCAL_GUARD" /> + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard" + speed="fast" reports="SNG_WRONG_NULL_FIELD_GUARD,SNG_WRONG_NULL_LOCAL_GUARD" /> <Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods" speed="fast" @@ -570,9 +570,9 @@ category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="NFF" type="NFF_NON_FUNCTIONAL_FIELD" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="WNG" type="WNG_WRONG_NULL_FIELD_GUARD" + <BugPattern abbrev="SNG" type="SNG_WRONG_NULL_FIELD_GUARD" category="CORRECTNESS" experimental="true" /> - <BugPattern abbrev="WNG" type="WNG_WRONG_NULL_LOCAL_GUARD" + <BugPattern abbrev="SNG" type="SNG_WRONG_NULL_LOCAL_GUARD" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="MDM" type="MDM_RUNTIME_EXIT_OR_HALT" category="CORRECTNESS" experimental="true" /> Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2010-01-10 02:14:08 UTC (rev 1456) +++ trunk/fb-contrib/etc/messages.xml 2010-01-10 16:51:57 UTC (rev 1457) @@ -1078,7 +1078,7 @@ </Details> </Detector> - <Detector class="com.mebigfatguy.fbcontrib.detect.WrongNullGuard"> + <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard"> <Details> <![CDATA[ <p>looks for code that checks to see if a field or local variable is not null, @@ -2822,7 +2822,7 @@ </Details> </BugPattern> - <BugPattern type="WNG_WRONG_NULL_FIELD_GUARD"> + <BugPattern type="SNG_WRONG_NULL_FIELD_GUARD"> <ShortDescription>method tests a field for null as guard for code that doesn't use it</ShortDescription> <LongDescription>method {1} tests a field for null as guard for code that doesn't use it</LongDescription> <Details> @@ -2835,7 +2835,7 @@ </Details> </BugPattern> - <BugPattern type="WNG_WRONG_NULL_LOCAL_GUARD"> + <BugPattern type="SNG_WRONG_NULL_LOCAL_GUARD"> <ShortDescription>method tests a local variable for null as guard for code that doesn't use it</ShortDescription> <LongDescription>method {1} tests a local variable for null as guard for code that doesn't use it</LongDescription> <Details> @@ -3087,6 +3087,6 @@ <BugCode abbrev="NSE">Non Symmetric Equals</BugCode> <BugCode abbrev="CVAA">Contravariant Array Assignment</BugCode> <BugCode abbrev="NFF">Non Functional Field</BugCode> - <BugCode abbrev="WNG">Wrong Null Guard</BugCode> + <BugCode abbrev="SNG">Wrong Null Guard</BugCode> <BugCode abbrev="MDM">More Dumb Methods</BugCode> </MessageCollection> Copied: trunk/fb-contrib/samples/SNG_Sample.java (from rev 1453, trunk/fb-contrib/samples/WNG_Sample.java) =================================================================== --- trunk/fb-contrib/samples/SNG_Sample.java (rev 0) +++ trunk/fb-contrib/samples/SNG_Sample.java 2010-01-10 16:51:57 UTC (rev 1457) @@ -0,0 +1,73 @@ +import java.io.File; + + +public class SNG_Sample +{ + private static byte[] EMPTY_BYTE_ARRAY = new byte[0]; + private Object f1 = null; + private Object f2 = null; + private File file = null; + private byte[] buffer = null; + + public String badSNGFields() + { + if (f1 != null) + return f2.toString(); + + return null; + } + + public String badSNGLocals(Object l1, Object l2) + { + if (l1 != null) + return l2.toString(); + + return null; + } + + public boolean fpReturn(Object o) { + return o != null; + } + + public boolean fpAssign(Object o) { + boolean b = o != null; + return b; + } + + public boolean fpField() { + if (f1 != null) + return true; + + return false; + } + + public void fpAssert() { + assert f1 != null && f1.equals(f2); + } + + public Object fpSetNull(Object o) { + if (o != null) + o = null; + + return o; + } + + public void fpSetMemberNull() { + if (f1 != null) + f1 = null; + } + + public void fpDual(Object o1, Object o2) { + if (o1 == null || o2 == null) { + throw new IllegalArgumentException("o1/o2 can not be null"); + } + } + + public void discard() { + if (file != null) { + file.delete(); + } else if (buffer != null) { + buffer = EMPTY_BYTE_ARRAY; + } + } +} Deleted: trunk/fb-contrib/samples/WNG_Sample.java =================================================================== --- trunk/fb-contrib/samples/WNG_Sample.java 2010-01-10 02:14:08 UTC (rev 1456) +++ trunk/fb-contrib/samples/WNG_Sample.java 2010-01-10 16:51:57 UTC (rev 1457) @@ -1,73 +0,0 @@ -import java.io.File; - - -public class WNG_Sample -{ - private static byte[] EMPTY_BYTE_ARRAY = new byte[0]; - private Object f1 = null; - private Object f2 = null; - private File file = null; - private byte[] buffer = null; - - public String badWNGFields() - { - if (f1 != null) - return f2.toString(); - - return null; - } - - public String badWNGLocals(Object l1, Object l2) - { - if (l1 != null) - return l2.toString(); - - return null; - } - - public boolean fpReturn(Object o) { - return o != null; - } - - public boolean fpAssign(Object o) { - boolean b = o != null; - return b; - } - - public boolean fpField() { - if (f1 != null) - return true; - - return false; - } - - public void fpAssert() { - assert f1 != null && f1.equals(f2); - } - - public Object fpSetNull(Object o) { - if (o != null) - o = null; - - return o; - } - - public void fpSetMemberNull() { - if (f1 != null) - f1 = null; - } - - public void fpDual(Object o1, Object o2) { - if (o1 == null || o2 == null) { - throw new IllegalArgumentException("o1/o2 can not be null"); - } - } - - public void discard() { - if (file != null) { - file.delete(); - } else if (buffer != null) { - buffer = EMPTY_BYTE_ARRAY; - } - } -} Copied: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java (from rev 1451, trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java) =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-01-10 16:51:57 UTC (rev 1457) @@ -0,0 +1,279 @@ +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2010 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.LocalVariable; +import org.apache.bcel.classfile.LocalVariableTable; + +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; +import edu.umd.cs.findbugs.ba.ClassContext; +import edu.umd.cs.findbugs.ba.XField; + +/** + * looks for code that checks to see if a field or local variable is not null, + * before entering a code block either an if, or while statement, and then doesn't + * reference that field or local in the block of code that is guarded by the null + * check. It is likely that null check is being done on the wrong variable, either + * because of a copy/paste error, or a change in implementation. + */ +public class SuspiciousNullGuard extends BytecodeScanningDetector { + + private BugReporter bugReporter; + private OpcodeStack stack; + private LocalVariableTable lvt; + private Map<Integer, NullGuard> nullGuards; + + /** + * constructs a SNG detector given the reporter to report bugs on + * @param bugReporter the sync of bug reports + */ + public SuspiciousNullGuard(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * overrides the visitor to initialize and tear down the opcode stack + * + * @param classContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + nullGuards = new HashMap<Integer, NullGuard>(); + super.visitClassContext(classContext); + } finally { + stack = null; + } + } + + /** + * overrides the visitor to reset the stack + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + try { + stack.resetForMethodEntry(this); + lvt = getMethod().getLocalVariableTable(); + nullGuards.clear(); + super.visitCode(obj); + } finally { + lvt = null; + } + } + + /** + * overrides the visitor to look for bad null guards + * + * @param seen the opcode of the currently visited instruction + */ + @Override + public void sawOpcode(int seen) { + try { + Integer pc = Integer.valueOf(getPC()); + NullGuard guard = nullGuards.remove(pc); + if ((guard != null) && guard.sawSignatureOfGuard()) { + boolean localBug = guard.getRegister() >= 0; + bugReporter.reportBug(new BugInstance(this, localBug ? "SNG_WRONG_NULL_LOCAL_GUARD" : "SNG_WRONG_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this, guard.getLocation())); + } + + switch (seen) { + case IFNULL: { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + int reg = item.getRegisterNumber(); + Integer target = Integer.valueOf(getBranchTarget()); + if (reg >= 0) { + nullGuards.put(target, new NullGuard(reg, pc.intValue(), item.getSignature())); + } else { + XField xf = item.getXField(); + if (xf != null) { + nullGuards.put(target, new NullGuard(xf, pc.intValue(), item.getSignature())); + } + } + } + } + break; + + case ALOAD: + case ALOAD_0: + case ALOAD_1: + case ALOAD_2: + case ALOAD_3: { + if (lvt != null) { + LocalVariable lv = lvt.getLocalVariable(RegisterUtils.getALoadReg(this, seen), getNextPC()); + if (lv != null) { + markNullGuards(lv.getSignature()); + } + } + } + break; + + case ASTORE: + case ASTORE_0: + case ASTORE_1: + case ASTORE_2: + case ASTORE_3: { + removeGuardForRegister(RegisterUtils.getAStoreReg(this, seen)); + } + break; + + case GETFIELD: { + markNullGuards(getSigConstantOperand()); + } + break; + + case PUTFIELD: { + removeGuardForField(getXField()); + } + break; + + case INVOKEVIRTUAL: + case INVOKEINTERFACE: { + if (nullGuards.size() > 0) { + String clsName = getClassConstantOperand(); + String methodName = getNameConstantOperand(); + if ("java/io/PrintStream".equals(clsName) && methodName.startsWith("print")) { + nullGuards.clear(); + } + } + } + break; + + case IFNONNULL: + case ATHROW: { + nullGuards.clear(); + } + break; + + case GOTO: { + if (stack.getStackDepth() > 0) { + nullGuards.clear(); + } + } + break; + } + } finally { + stack.sawOpcode(this, seen); + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + int reg = item.getRegisterNumber(); + if (reg >= 0) { + removeGuardForRegister(reg); + } else { + XField field = item.getXField(); + if (field != null) + removeGuardForField(field); + } + } + } + } + + private void markNullGuards(String signature) { + for (NullGuard ng : nullGuards.values()) { + if (ng.getSignature().equals(signature)) { + ng.markSignatureOfGuard(); + } + } + } + + private void removeGuardForRegister(int reg) { + Iterator<NullGuard> it = nullGuards.values().iterator(); + while (it.hasNext()) { + NullGuard guard = it.next(); + if (reg == guard.getRegister()) { + it.remove(); + } + } + } + + private void removeGuardForField(XField field) { + Iterator<NullGuard> it = nullGuards.values().iterator(); + while (it.hasNext()) { + NullGuard guard = it.next(); + if (field != null) { + if (field.equals(guard.getField())) { + it.remove(); + } + } + } + } + + static class NullGuard { + int register; + XField field; + int location; + String signature; + boolean sawSignature = false; + + public NullGuard(int reg, int start, String guardSignature) { + register = reg; + field = null; + location = start; + signature = guardSignature; + } + + + public NullGuard(XField xf, int start, String guardSignature) { + register = -1; + field = xf; + location = start; + signature = guardSignature; + } + + public int getRegister() { + return register; + } + + public XField getField() { + return field; + } + + public int getLocation() { + return location; + } + + public String getSignature() { + return signature; + } + + public void markSignatureOfGuard() { + sawSignature = true; + } + + public boolean sawSignatureOfGuard() { + return sawSignature; + } + } +} Deleted: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java 2010-01-10 02:14:08 UTC (rev 1456) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java 2010-01-10 16:51:57 UTC (rev 1457) @@ -1,279 +0,0 @@ -/* - * fb-contrib - Auxiliary detectors for Java programs - * Copyright (C) 2005-2010 Dave Brosius - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package com.mebigfatguy.fbcontrib.detect; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.apache.bcel.classfile.Code; -import org.apache.bcel.classfile.LocalVariable; -import org.apache.bcel.classfile.LocalVariableTable; - -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; -import edu.umd.cs.findbugs.ba.ClassContext; -import edu.umd.cs.findbugs.ba.XField; - -/** - * looks for code that checks to see if a field or local variable is not null, - * before entering a code block either an if, or while statement, and then doesn't - * reference that field or local in the block of code that is guarded by the null - * check. It is likely that null check is being done on the wrong variable, either - * because of a copy/paste error, or a change in implementation. - */ -public class WrongNullGuard extends BytecodeScanningDetector { - - private BugReporter bugReporter; - private OpcodeStack stack; - private LocalVariableTable lvt; - private Map<Integer, NullGuard> nullGuards; - - /** - * constructs a WNG detector given the reporter to report bugs on - * @param bugReporter the sync of bug reports - */ - public WrongNullGuard(BugReporter bugReporter) { - this.bugReporter = bugReporter; - } - - /** - * overrides the visitor to initialize and tear down the opcode stack - * - * @param classContext the context object of the currently parsed class - */ - @Override - public void visitClassContext(ClassContext classContext) { - try { - stack = new OpcodeStack(); - nullGuards = new HashMap<Integer, NullGuard>(); - super.visitClassContext(classContext); - } finally { - stack = null; - } - } - - /** - * overrides the visitor to reset the stack - * - * @param obj the context object of the currently parsed code block - */ - @Override - public void visitCode(Code obj) { - try { - stack.resetForMethodEntry(this); - lvt = getMethod().getLocalVariableTable(); - nullGuards.clear(); - super.visitCode(obj); - } finally { - lvt = null; - } - } - - /** - * overrides the visitor to look for bad null guards - * - * @param seen the opcode of the currently visited instruction - */ - @Override - public void sawOpcode(int seen) { - try { - Integer pc = Integer.valueOf(getPC()); - NullGuard guard = nullGuards.remove(pc); - if ((guard != null) && guard.sawSignatureOfGuard()) { - boolean localBug = guard.getRegister() >= 0; - bugReporter.reportBug(new BugInstance(this, localBug ? "WNG_WRONG_NULL_LOCAL_GUARD" : "WNG_WRONG_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this, guard.getLocation())); - } - - switch (seen) { - case IFNULL: { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - int reg = item.getRegisterNumber(); - Integer target = Integer.valueOf(getBranchTarget()); - if (reg >= 0) { - nullGuards.put(target, new NullGuard(reg, pc.intValue(), item.getSignature())); - } else { - XField xf = item.getXField(); - if (xf != null) { - nullGuards.put(target, new NullGuard(xf, pc.intValue(), item.getSignature())); - } - } - } - } - break; - - case ALOAD: - case ALOAD_0: - case ALOAD_1: - case ALOAD_2: - case ALOAD_3: { - if (lvt != null) { - LocalVariable lv = lvt.getLocalVariable(RegisterUtils.getALoadReg(this, seen), getNextPC()); - if (lv != null) { - markNullGuards(lv.getSignature()); - } - } - } - break; - - case ASTORE: - case ASTORE_0: - case ASTORE_1: - case ASTORE_2: - case ASTORE_3: { - removeGuardForRegister(RegisterUtils.getAStoreReg(this, seen)); - } - break; - - case GETFIELD: { - markNullGuards(getSigConstantOperand()); - } - break; - - case PUTFIELD: { - removeGuardForField(getXField()); - } - break; - - case INVOKEVIRTUAL: - case INVOKEINTERFACE: { - if (nullGuards.size() > 0) { - String clsName = getClassConstantOperand(); - String methodName = getNameConstantOperand(); - if ("java/io/PrintStream".equals(clsName) && methodName.startsWith("print")) { - nullGuards.clear(); - } - } - } - break; - - case IFNONNULL: - case ATHROW: { - nullGuards.clear(); - } - break; - - case GOTO: { - if (stack.getStackDepth() > 0) { - nullGuards.clear(); - } - } - break; - } - } finally { - stack.sawOpcode(this, seen); - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - int reg = item.getRegisterNumber(); - if (reg >= 0) { - removeGuardForRegister(reg); - } else { - XField field = item.getXField(); - if (field != null) - removeGuardForField(field); - } - } - } - } - - private void markNullGuards(String signature) { - for (NullGuard ng : nullGuards.values()) { - if (ng.getSignature().equals(signature)) { - ng.markSignatureOfGuard(); - } - } - } - - private void removeGuardForRegister(int reg) { - Iterator<NullGuard> it = nullGuards.values().iterator(); - while (it.hasNext()) { - NullGuard guard = it.next(); - if (reg == guard.getRegister()) { - it.remove(); - } - } - } - - private void removeGuardForField(XField field) { - Iterator<NullGuard> it = nullGuards.values().iterator(); - while (it.hasNext()) { - NullGuard guard = it.next(); - if (field != null) { - if (field.equals(guard.getField())) { - it.remove(); - } - } - } - } - - static class NullGuard { - int register; - XField field; - int location; - String signature; - boolean sawSignature = false; - - public NullGuard(int reg, int start, String guardSignature) { - register = reg; - field = null; - location = start; - signature = guardSignature; - } - - - public NullGuard(XField xf, int start, String guardSignature) { - register = -1; - field = xf; - location = start; - signature = guardSignature; - } - - public int getRegister() { - return register; - } - - public XField getField() { - return field; - } - - public int getLocation() { - return location; - } - - public String getSignature() { - return signature; - } - - public void markSignatureOfGuard() { - sawSignature = true; - } - - public boolean sawSignatureOfGuard() { - return sawSignature; - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 02:14:16
|
Revision: 1456 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1456&view=rev Author: dbrosius Date: 2010-01-10 02:14:08 +0000 (Sun, 10 Jan 2010) Log Message: ----------- if the target type is java.lang.Object, then ignore Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2010-01-10 02:05:50 UTC (rev 1455) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2010-01-10 02:14:08 UTC (rev 1456) @@ -115,19 +115,21 @@ if(!value.isNull()) { String sourceSignature = value.getSignature(); String targetSignature = arrayref.getSignature(); - try{ - if(Type.getType(sourceSignature) instanceof ObjectType ) { - ObjectType sourceType = (ObjectType) Type.getType(sourceSignature); - ObjectType targetType = (ObjectType) ((ArrayType) Type.getType(targetSignature)).getBasicType(); - if(!sourceType.equals(targetType) && !sourceType.subclassOf(targetType)){ - bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT", HIGH_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (!"Ljava/lang/Object;".equals(targetSignature)) { + try{ + if(Type.getType(sourceSignature) instanceof ObjectType ) { + ObjectType sourceType = (ObjectType) Type.getType(sourceSignature); + ObjectType targetType = (ObjectType) ((ArrayType) Type.getType(targetSignature)).getBasicType(); + if(!sourceType.equals(targetType) && !sourceType.subclassOf(targetType)){ + bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT", HIGH_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); } - } catch (ClassNotFoundException cnfe) { - bugReporter.reportMissingClass(cnfe); } } break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-10 02:05:58
|
Revision: 1455 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1455&view=rev Author: dbrosius Date: 2010-01-10 02:05:50 +0000 (Sun, 10 Jan 2010) Log Message: ----------- split CVAA into two bug patterns, one for array assignment, one for element assignment Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2010-01-10 01:19:04 UTC (rev 1454) +++ trunk/fb-contrib/etc/findbugs.xml 2010-01-10 02:05:50 UTC (rev 1455) @@ -308,7 +308,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment" - speed="fast" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT" /> + speed="fast" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" /> <Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField" speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" /> @@ -566,6 +566,8 @@ category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" + category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="NFF" type="NFF_NON_FUNCTIONAL_FIELD" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="WNG" type="WNG_WRONG_NULL_FIELD_GUARD" Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2010-01-10 01:19:04 UTC (rev 1454) +++ trunk/fb-contrib/etc/messages.xml 2010-01-10 02:05:50 UTC (rev 1455) @@ -2782,13 +2782,33 @@ B[] b = new B[2]; A[] a = b; + </pre> + <p>It is a fast detector</p> + ]]> + </Details> + </BugPattern> + + <BugPattern type="CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT"> + <ShortDescription>method performs a contravariant array element assignment</ShortDescription> + <LongDescription>method {1} performs a contravariant array element assignment</LongDescription> + <Details> + <![CDATA[ + <p>This method contains a contravariant array element assignment. Since arrays are mutable + data structures, their use must be restricted to covariant or invariant usage</p> + + <pre> + class A {} + class B extends A {} + + B[] b = new B[2]; + A[] a = b; a[0] = new A(); // results in ArrayStoreException (Runtime) </pre> <p>It is a fast detector</p> ]]> </Details> </BugPattern> - + <BugPattern type="NFF_NON_FUNCTIONAL_FIELD"> <ShortDescription>serializable class defines a final transient field</ShortDescription> <LongDescription>serializable class {0} defines a final transient field</LongDescription> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2010-01-10 01:19:04 UTC (rev 1454) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2010-01-10 02:05:50 UTC (rev 1455) @@ -153,22 +153,15 @@ return; } - if(isArrayType(sourceSignature)) { - if(!isArrayType(targetSignature)){ - bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT", LOW_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - } else { - if(isObjectType(sourceSignature) && isObjectType(targetSignature)){ - ObjectType sourceType = (ObjectType) ((ArrayType) Type.getType(sourceSignature)).getBasicType(); - ObjectType targetType = (ObjectType) ((ArrayType) Type.getType(targetSignature)).getBasicType(); - if(!targetType.equals(sourceType) && !targetType.subclassOf(sourceType)) { - bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - } + if(isArrayType(sourceSignature) && isArrayType(targetSignature)) { + if(isObjectType(sourceSignature) && isObjectType(targetSignature)) { + ObjectType sourceType = (ObjectType) ((ArrayType) Type.getType(sourceSignature)).getBasicType(); + ObjectType targetType = (ObjectType) ((ArrayType) Type.getType(targetSignature)).getBasicType(); + if(!targetType.equals(sourceType) && !targetType.subclassOf(sourceType)) { + bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT", NORMAL_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...> - 2010-01-10 01:19:12
|
Revision: 1454 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1454&view=rev Author: dbrosius Date: 2010-01-10 01:19:04 +0000 (Sun, 10 Jan 2010) Log Message: ----------- if the store target is an java.lang.Object, just ignore Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2010-01-09 17:27:53 UTC (rev 1453) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2010-01-10 01:19:04 UTC (rev 1454) @@ -149,6 +149,10 @@ private void checkSignatures(String sourceSignature, String targetSignature) { try{ + if ("Ljava/lang/Object;".equals(targetSignature)) { + return; + } + if(isArrayType(sourceSignature)) { if(!isArrayType(targetSignature)){ bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT", LOW_PRIORITY) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-09 17:28:00
|
Revision: 1453 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1453&view=rev Author: dbrosius Date: 2010-01-09 17:27:53 +0000 (Sat, 09 Jan 2010) Log Message: ----------- more tests Modified Paths: -------------- trunk/fb-contrib/samples/WNG_Sample.java Modified: trunk/fb-contrib/samples/WNG_Sample.java =================================================================== --- trunk/fb-contrib/samples/WNG_Sample.java 2010-01-09 04:54:06 UTC (rev 1452) +++ trunk/fb-contrib/samples/WNG_Sample.java 2010-01-09 17:27:53 UTC (rev 1453) @@ -1,8 +1,13 @@ +import java.io.File; + public class WNG_Sample { + private static byte[] EMPTY_BYTE_ARRAY = new byte[0]; private Object f1 = null; private Object f2 = null; + private File file = null; + private byte[] buffer = null; public String badWNGFields() { @@ -57,4 +62,12 @@ throw new IllegalArgumentException("o1/o2 can not be null"); } } + + public void discard() { + if (file != null) { + file.delete(); + } else if (buffer != null) { + buffer = EMPTY_BYTE_ARRAY; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-09 04:54:12
|
Revision: 1452 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1452&view=rev Author: dbrosius Date: 2010-01-09 04:54:06 +0000 (Sat, 09 Jan 2010) Log Message: ----------- more fps Modified Paths: -------------- trunk/fb-contrib/samples/WNG_Sample.java Modified: trunk/fb-contrib/samples/WNG_Sample.java =================================================================== --- trunk/fb-contrib/samples/WNG_Sample.java 2010-01-09 04:24:17 UTC (rev 1451) +++ trunk/fb-contrib/samples/WNG_Sample.java 2010-01-09 04:54:06 UTC (rev 1452) @@ -47,6 +47,11 @@ return o; } + public void fpSetMemberNull() { + if (f1 != null) + f1 = null; + } + public void fpDual(Object o1, Object o2) { if (o1 == null || o2 == null) { throw new IllegalArgumentException("o1/o2 can not be null"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-09 04:24:28
|
Revision: 1451 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1451&view=rev Author: dbrosius Date: 2010-01-09 04:24:17 +0000 (Sat, 09 Jan 2010) Log Message: ----------- only report WNG if another variable with the same signature as the nonnull guard variable is loaded in the if block guarded by a non null statement Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java 2010-01-05 09:04:32 UTC (rev 1450) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java 2010-01-09 04:24:17 UTC (rev 1451) @@ -23,6 +23,8 @@ import java.util.Map; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.LocalVariable; +import org.apache.bcel.classfile.LocalVariableTable; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; @@ -44,6 +46,7 @@ private BugReporter bugReporter; private OpcodeStack stack; + private LocalVariableTable lvt; private Map<Integer, NullGuard> nullGuards; /** @@ -77,9 +80,14 @@ */ @Override public void visitCode(Code obj) { - stack.resetForMethodEntry(this); - nullGuards.clear(); - super.visitCode(obj); + try { + stack.resetForMethodEntry(this); + lvt = getMethod().getLocalVariableTable(); + nullGuards.clear(); + super.visitCode(obj); + } finally { + lvt = null; + } } /** @@ -92,7 +100,7 @@ try { Integer pc = Integer.valueOf(getPC()); NullGuard guard = nullGuards.remove(pc); - if (guard != null) { + if ((guard != null) && guard.sawSignatureOfGuard()) { boolean localBug = guard.getRegister() >= 0; bugReporter.reportBug(new BugInstance(this, localBug ? "WNG_WRONG_NULL_LOCAL_GUARD" : "WNG_WRONG_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY) .addClass(this) @@ -107,17 +115,31 @@ int reg = item.getRegisterNumber(); Integer target = Integer.valueOf(getBranchTarget()); if (reg >= 0) { - nullGuards.put(target, new NullGuard(reg, pc.intValue())); + nullGuards.put(target, new NullGuard(reg, pc.intValue(), item.getSignature())); } else { XField xf = item.getXField(); if (xf != null) { - nullGuards.put(target, new NullGuard(xf, pc.intValue())); + nullGuards.put(target, new NullGuard(xf, pc.intValue(), item.getSignature())); } } } } break; + case ALOAD: + case ALOAD_0: + case ALOAD_1: + case ALOAD_2: + case ALOAD_3: { + if (lvt != null) { + LocalVariable lv = lvt.getLocalVariable(RegisterUtils.getALoadReg(this, seen), getNextPC()); + if (lv != null) { + markNullGuards(lv.getSignature()); + } + } + } + break; + case ASTORE: case ASTORE_0: case ASTORE_1: @@ -127,6 +149,11 @@ } break; + case GETFIELD: { + markNullGuards(getSigConstantOperand()); + } + break; + case PUTFIELD: { removeGuardForField(getXField()); } @@ -150,27 +177,6 @@ } break; - case IRETURN: - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - Integer value = (Integer)item.getConstant(); - if (value != null) { - int val = value.intValue(); - if ((val == 0) || (val == 1)) - nullGuards.clear(); - } - } - //FALL_THRU - - case FRETURN: - case DRETURN: - case ARETURN: - case LRETURN: - case RETURN: { - nullGuards.remove(Integer.valueOf(getPC() + 1)); - } - break; - case GOTO: { if (stack.getStackDepth() > 0) { nullGuards.clear(); @@ -194,6 +200,14 @@ } } + private void markNullGuards(String signature) { + for (NullGuard ng : nullGuards.values()) { + if (ng.getSignature().equals(signature)) { + ng.markSignatureOfGuard(); + } + } + } + private void removeGuardForRegister(int reg) { Iterator<NullGuard> it = nullGuards.values().iterator(); while (it.hasNext()) { @@ -220,18 +234,22 @@ int register; XField field; int location; + String signature; + boolean sawSignature = false; - public NullGuard(int reg, int start) { + public NullGuard(int reg, int start, String guardSignature) { register = reg; field = null; location = start; + signature = guardSignature; } - public NullGuard(XField xf, int start) { + public NullGuard(XField xf, int start, String guardSignature) { register = -1; field = xf; location = start; + signature = guardSignature; } public int getRegister() { @@ -245,5 +263,17 @@ public int getLocation() { return location; } + + public String getSignature() { + return signature; + } + + public void markSignatureOfGuard() { + sawSignature = true; + } + + public boolean sawSignatureOfGuard() { + return sawSignature; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 09:04:38
|
Revision: 1450 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1450&view=rev Author: dbrosius Date: 2010-01-05 09:04:32 +0000 (Tue, 05 Jan 2010) Log Message: ----------- using 1.5 now --> use enums Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-05 09:03:16 UTC (rev 1449) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PoorlyDefinedParameter.java 2010-01-05 09:04:32 UTC (rev 1450) @@ -43,16 +43,14 @@ */ public class PoorlyDefinedParameter extends BytecodeScanningDetector { - private static final int SAW_NOTHING = 0; - private static final int SAW_LOAD = 1; - private static final int SAW_CHECKCAST = 2; + enum State {SAW_NOTHING, SAW_LOAD, SAW_CHECKCAST} BugReporter bugReporter; Map<Integer, String> parmSigs; Map<Integer, BugInfo> bugs; int loadedReg; String parmSig; - int state; + State state; String castClass; int downwardBranchTarget; @@ -76,7 +74,7 @@ if (m.isStatic() || m.isPrivate() || "<init>".equals(m.getName())) { parmSigs = SignatureUtils.getParameterSignatures(m); if ((parmSigs.size() > 0) && prescreen(m)) { - state = SAW_NOTHING; + state = State.SAW_NOTHING; bugs = new HashMap<Integer, BugInfo>(); downwardBranchTarget = -1; super.visitCode(obj); @@ -117,7 +115,7 @@ parmSig = parmSigs.get(Integer.valueOf(loadedReg)); if (parmSig != null) { parmSig = parmSig.substring(1, parmSig.length() - 1); - state = SAW_LOAD; + state = State.SAW_LOAD; } } break; @@ -126,14 +124,14 @@ if (seen == CHECKCAST) { castClass = getClassConstantOperand(); if (!castClass.equals(parmSig)) { - state = SAW_CHECKCAST; + state = State.SAW_CHECKCAST; return; } } else if (seen == INSTANCEOF) { // probably an if guard... assume the code is reasonable parmSigs.remove(Integer.valueOf(loadedReg)); } - state = SAW_NOTHING; + state = State.SAW_NOTHING; break; case SAW_CHECKCAST: @@ -168,7 +166,7 @@ } - state = SAW_NOTHING; + state = State.SAW_NOTHING; break; } if ((seen >= IFEQ) && (seen <= IF_ACMPNE)) { @@ -177,7 +175,7 @@ downwardBranchTarget = -1; } } else { - state = SAW_NOTHING; + state = State.SAW_NOTHING; if (getPC() >= downwardBranchTarget) downwardBranchTarget = -1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 09:03:25
|
Revision: 1449 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1449&view=rev Author: dbrosius Date: 2010-01-05 09:03:16 +0000 (Tue, 05 Jan 2010) Log Message: ----------- using 1.5 now --> use enums Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverzealousCasting.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverzealousCasting.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverzealousCasting.java 2010-01-05 09:02:06 UTC (rev 1448) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverzealousCasting.java 2010-01-05 09:03:16 UTC (rev 1449) @@ -41,12 +41,10 @@ public class OverzealousCasting extends BytecodeScanningDetector { - public static final int SAW_NOTHING = 0; - public static final int SAW_NEXT = 1; - public static final int SAW_CHECKCAST = 2; + enum State {SAW_NOTHING, SAW_NEXT, SAW_CHECKCAST} BugReporter bugReporter; - int state; + State state; LocalVariableTable lvt; String castClass; @@ -65,7 +63,7 @@ */ @Override public void visitCode(Code obj) { - state = SAW_NOTHING; + state = State.SAW_NOTHING; lvt = obj.getLocalVariableTable(); if (lvt != null && prescreen(getMethod())) super.visitCode(obj); @@ -93,19 +91,19 @@ case SAW_NOTHING: if (seen == CHECKCAST) { castClass = getClassConstantOperand(); - state = SAW_CHECKCAST; + state = State.SAW_CHECKCAST; } else if (seen == INVOKEINTERFACE) { //enhanced for loops add an incorrect checkcast instruction, so ignore checkcasts after iterator.next() String clsName = getClassConstantOperand(); String methodName = getNameConstantOperand(); if ("java/util/Iterator".equals(clsName) && "next".equals(methodName)) { - state = SAW_NEXT; + state = State.SAW_NEXT; } } break; case SAW_NEXT: - state = SAW_NOTHING; + state = State.SAW_NOTHING; break; case SAW_CHECKCAST: @@ -137,11 +135,11 @@ .addSourceLine(this)); } } - state = SAW_NOTHING; + state = State.SAW_NOTHING; break; default: - state = SAW_NOTHING; + state = State.SAW_NOTHING; break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 09:02:18
|
Revision: 1448 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1448&view=rev Author: dbrosius Date: 2010-01-05 09:02:06 +0000 (Tue, 05 Jan 2010) Log Message: ----------- using 1.5 now --> use enums Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2010-01-05 08:45:36 UTC (rev 1447) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java 2010-01-05 09:02:06 UTC (rev 1448) @@ -33,13 +33,11 @@ */ public class NeedlessInstanceRetrieval extends BytecodeScanningDetector { - private static final int SEEN_NOTHING = 0; - private static final int SEEN_INVOKE = 1; - private static final int SEEN_POP = 2; + enum State {SEEN_NOTHING, SEEN_INVOKE, SEEN_POP} private BugReporter bugReporter; private LineNumberTable lnTable; - private int state; + private State state; private int invokePC; /** * constructs a NIR detector given the reporter to report bugs on @@ -59,7 +57,7 @@ try { lnTable = obj.getLineNumberTable(); if (lnTable != null) { - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; super.visitCode(obj); } } finally { @@ -87,7 +85,7 @@ if (!"java/lang/Object".equals(clsName) && !"java/lang/String".equals(clsName)) { invokePC = getPC(); - state = SEEN_INVOKE; + state = State.SEEN_INVOKE; } } } @@ -95,9 +93,9 @@ case SEEN_INVOKE: if (seen == POP) - state = SEEN_POP; + state = State.SEEN_POP; else - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; break; case SEEN_POP: @@ -109,11 +107,11 @@ .addSourceLine(this)); } } - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; break; default: - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 08:45:44
|
Revision: 1447 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1447&view=rev Author: dbrosius Date: 2010-01-05 08:45:36 +0000 (Tue, 05 Jan 2010) Log Message: ----------- using 1.5 now --> use enums Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java 2010-01-05 08:44:17 UTC (rev 1446) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessCustomSerialization.java 2010-01-05 08:45:36 UTC (rev 1447) @@ -34,11 +34,7 @@ */ public class NeedlessCustomSerialization extends BytecodeScanningDetector { - private static final int SEEN_NOTHING = 0; - private static final int SEEN_ALOAD1 = 1; - private static final int SEEN_INVOKEVIRTUAL = 2; - private static final int SEEN_RETURN = 3; - private static final int SEEN_INVALID = 4; + enum State {SEEN_NOTHING, SEEN_ALOAD1, SEEN_INVOKEVIRTUAL, SEEN_RETURN, SEEN_INVALID} private static JavaClass serializableClass; static { @@ -51,7 +47,7 @@ private BugReporter bugReporter; private boolean inReadObject; private boolean inWriteObject; - private int state; + private State state; /** * constructs a NCS detector given the reporter to report bugs on @@ -92,9 +88,9 @@ } if (inReadObject || inWriteObject) { - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; super.visitCode(obj); - if (state != SEEN_INVALID) { + if (state != State.SEEN_INVALID) { bugReporter.reportBug(new BugInstance(this, "NCS_NEEDLESS_CUSTOM_SERIALIZATION", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(this, 1)); @@ -107,31 +103,31 @@ switch (state) { case SEEN_NOTHING: if (seen == ALOAD_1) - state = SEEN_ALOAD1; + state = State.SEEN_ALOAD1; else - state = SEEN_INVALID; + state = State.SEEN_INVALID; break; case SEEN_ALOAD1: - state = SEEN_INVALID; + state = State.SEEN_INVALID; if (seen == INVOKEVIRTUAL) { String nameAndSignature = getNameConstantOperand() + getSigConstantOperand(); if ((inReadObject && "defaultReadObject()V".equals(nameAndSignature)) || (inWriteObject && "defaultWriteObject()V".equals(nameAndSignature))) { - state = SEEN_INVOKEVIRTUAL; + state = State.SEEN_INVOKEVIRTUAL; } } break; case SEEN_INVOKEVIRTUAL: if (seen == RETURN) - state = SEEN_RETURN; + state = State.SEEN_RETURN; else - state = SEEN_INVALID; + state = State.SEEN_INVALID; break; case SEEN_RETURN: - state = SEEN_INVALID; + state = State.SEEN_INVALID; break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 08:44:24
|
Revision: 1446 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1446&view=rev Author: dbrosius Date: 2010-01-05 08:44:17 +0000 (Tue, 05 Jan 2010) Log Message: ----------- using 1.5 now --> use enums Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2010-01-05 08:37:18 UTC (rev 1445) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2010-01-05 08:44:17 UTC (rev 1446) @@ -34,15 +34,7 @@ */ public class NeedlessAutoboxing extends BytecodeScanningDetector { - private static final int SEEN_NOTHING = 0; - private static final int SEEN_VALUE = 1; - private static final int SEEN_VALUEOFSTRING = 2; - private static final int SEEN_PARSE = 3; - private static final int SEEN_CTOR = 4; - private static final int SEEN_VALUEOFPRIMITIVE = 5; - private static final int SEEN_GOTO = 6; - private static final int SEEN_ICONST = 7; - private static final int SEEN_GETSTATIC = 8; + enum State {SEEN_NOTHING, SEEN_VALUE, SEEN_VALUEOFSTRING, SEEN_PARSE, SEEN_CTOR, SEEN_VALUEOFPRIMITIVE, SEEN_GOTO, SEEN_ICONST, SEEN_GETSTATIC} private static final Map<String, String[]> boxClasses = new HashMap<String, String[]>(); static { @@ -68,7 +60,7 @@ } private BugReporter bugReporter; - private int state; + private State state; private String boxClass; /** @@ -81,7 +73,7 @@ @Override public void visitMethod(Method obj) { - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; } @Override @@ -96,7 +88,7 @@ if (boxSigs != null) { String methodInfo = getNameConstantOperand() + getSigConstantOperand(); if (boxSigs[0].equals(methodInfo)) { - state = SEEN_VALUE; + state = State.SEEN_VALUE; } } } else if (seen == INVOKESTATIC) { @@ -107,16 +99,16 @@ String sig = getSigConstantOperand(); if (sig.startsWith("(Ljava/lang/String;)")) { if (!"java/lang/Boolean".equals(boxClass) || (getClassContext().getJavaClass().getMajor() >= Constants.MAJOR_1_5)) - state = SEEN_VALUEOFSTRING; + state = State.SEEN_VALUEOFSTRING; } else if (!sig.startsWith("(Ljava/lang/String;")) { - state = SEEN_VALUEOFPRIMITIVE; + state = State.SEEN_VALUEOFPRIMITIVE; } } else { String parseSig = parseClasses.get(boxClass); if (parseSig != null) { String methodInfo = getNameConstantOperand() + getSigConstantOperand(); if (parseSig.equals(methodInfo)) { - state = SEEN_PARSE; + state = State.SEEN_PARSE; } } } @@ -126,21 +118,21 @@ String[] boxSigs = boxClasses.get(boxClass); if (boxSigs != null) { if ("<init>".equals(getNameConstantOperand()) && boxSigs[1].equals(getSigConstantOperand())) { - state = SEEN_CTOR; + state = State.SEEN_CTOR; } } } else if ((seen == ICONST_0) || (seen == ICONST_1)) { - if (state == SEEN_NOTHING) - state = SEEN_ICONST; + if (state == State.SEEN_NOTHING) + state = State.SEEN_ICONST; } else if (seen == GETSTATIC) { String clsName = getClassConstantOperand(); if ("java/lang/Boolean".equals(clsName)) { String fldName = getNameConstantOperand(); if ("TRUE".equals(fldName) || "FALSE".equals(fldName)) - state = SEEN_GETSTATIC; + state = State.SEEN_GETSTATIC; } } else if ((seen == GOTO) || (seen == GOTO_W)) { - state = SEEN_GOTO; + state = State.SEEN_GOTO; } break; @@ -174,7 +166,7 @@ } } } - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; break; case SEEN_CTOR: @@ -193,7 +185,7 @@ .addSourceLine(this)); } } - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; break; case SEEN_VALUEOFSTRING: @@ -206,7 +198,7 @@ .addSourceLine(this)); } } - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; break; case SEEN_PARSE: @@ -227,7 +219,7 @@ .addSourceLine(this)); } } - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; break; case SEEN_ICONST: @@ -241,7 +233,7 @@ .addSourceLine(this)); } } - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; sawOpcode(seen); break; @@ -256,7 +248,7 @@ .addSourceLine(this)); } } - state = SEEN_NOTHING; + state = State.SEEN_NOTHING; sawOpcode(seen); break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 08:37:24
|
Revision: 1445 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1445&view=rev Author: dbrosius Date: 2010-01-05 08:37:18 +0000 (Tue, 05 Jan 2010) Log Message: ----------- more tests Modified Paths: -------------- trunk/fb-contrib/samples/SPP_Sample.java Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2010-01-05 08:35:57 UTC (rev 1444) +++ trunk/fb-contrib/samples/SPP_Sample.java 2010-01-05 08:37:18 UTC (rev 1445) @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Random; import java.util.Set; import java.util.StringTokenizer; @@ -282,4 +283,13 @@ return false; } + + public void castRandomToInt() { + int i = (int)Math.random(); + + Random r = new Random(); + i = (int) r.nextDouble(); + + i = (int) r.nextFloat(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 08:36:06
|
Revision: 1444 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1444&view=rev Author: dbrosius Date: 2010-01-05 08:35:57 +0000 (Tue, 05 Jan 2010) Log Message: ----------- update from Chris Peterson to fix the {2}'s showing up in the gui description panels Modified Paths: -------------- trunk/fb-contrib/etc/messages.xml Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2010-01-05 07:11:47 UTC (rev 1443) +++ trunk/fb-contrib/etc/messages.xml 2010-01-05 08:35:57 UTC (rev 1444) @@ -2828,7 +2828,7 @@ </BugPattern> <BugPattern type="MDM_RUNTIME_EXIT_OR_HALT"> - <ShortDescription>Method calls {2}</ShortDescription> + <ShortDescription>Method calls Runtime.exit() or Runtime.halt()</ShortDescription> <LongDescription>Method {1} calls {2}</LongDescription> <Details> <![CDATA[ @@ -2838,11 +2838,11 @@ </BugPattern> <BugPattern type="MDM_RUNFINALIZATION"> - <ShortDescription>Method calls {2}</ShortDescription> - <LongDescription>Method {1} calls {2}</LongDescription> + <ShortDescription>Method triggers finalization</ShortDescription> + <LongDescription>Method {1} triggers finalization when calling {2}</LongDescription> <Details> <![CDATA[ - <p>Triggering finalization can result in serious performance problems and may indicate incorrect resource cleanup.</p> + <p>Manually triggering finalization can result in serious performance problems and may be masking resource cleanup bugs.</p> ]]> </Details> </BugPattern> @@ -2898,18 +2898,18 @@ </BugPattern> <BugPattern type="MDM_THREAD_PRIORITIES"> - <ShortDescription>Method calls non-portable method {2}</ShortDescription> - <LongDescription>Method {1} calls non-portable method {2}</LongDescription> + <ShortDescription>Method uses suspicious thread priorities</ShortDescription> + <LongDescription>Method {1} uses suspicious thread priorities by calling method {2}</LongDescription> <Details> <![CDATA[ - <p>Getting or setting thread priorities is not portable and could indicate race conditions.</p> + <p>Getting or setting thread priorities is not portable and could cause or mask race conditions.</p> ]]> </Details> </BugPattern> <BugPattern type="MDM_THREAD_YIELD"> - <ShortDescription>Method calls non-portable method {2}</ShortDescription> - <LongDescription>Method {1} calls non-portable method {2}</LongDescription> + <ShortDescription>Method attempts to manually schedule threads</ShortDescription> + <LongDescription>Method {1} attempts to manually schedule threads by calling method {2}</LongDescription> <Details> <![CDATA[ <p>Manual thread scheduling with <code>Thread.sleep()</code> or <code>Thread.yield()</code> has no guaranteed semantics and is often used to mask race conditions.</p> @@ -2919,7 +2919,7 @@ <BugPattern type="MDM_WAIT_WITHOUT_TIMEOUT"> <ShortDescription>Method sleeps without timeout</ShortDescription> - <LongDescription>Method {1} calls {2} without timeout</LongDescription> + <LongDescription>Method {1} sleeps without timeout when calling {2}</LongDescription> <Details> <![CDATA[ <p>Calling <code>{2}</code> without timeout could block forever. Consider using a timeout to detect deadlocks or performance problems. Thread.join() Object.wait() Condition.await() Lock.lock() Lock.lockInterruptibly()</p> @@ -2928,7 +2928,7 @@ </BugPattern> <BugPattern type="MDM_THREAD_FAIRNESS"> - <ShortDescription>Method ignores Lock's fairness settings by calling {2}</ShortDescription> + <ShortDescription>Method ignores Lock's fairness settings by calling tryLock()</ShortDescription> <LongDescription>Method {1} ignores Lock's fairness settings by calling {2}</LongDescription> <Details> <![CDATA[ @@ -2949,7 +2949,7 @@ <BugPattern type="MDM_LOCK_ISLOCKED"> <ShortDescription>Method tests if a lock is locked</ShortDescription> - <LongDescription>Method {1} calls {2} to test if the lock is locked</LongDescription> + <LongDescription>Method {1} tests if a lock is locked by calling {2}</LongDescription> <Details> <![CDATA[ <p>Calling <code>ReentrantLock.isLocked()</code> or <code>ReentrantLock.isHeldByCurrentThread()</code> might indicate race conditions or incorrect locking. These methods are designed for use in debug code or monitoring of the system state, not for synchronization control.</p> @@ -2958,7 +2958,7 @@ </BugPattern> <BugPattern type="MDM_STRING_BYTES_ENCODING"> - <ShortDescription>Encoding String bytes without specifying the character encoding</ShortDescription> + <ShortDescription>Method encodes String bytes without specifying the character encoding</ShortDescription> <LongDescription>Method {1} encodes String bytes without specifying the character encoding</LongDescription> <Details> <![CDATA[ @@ -3069,4 +3069,4 @@ <BugCode abbrev="NFF">Non Functional Field</BugCode> <BugCode abbrev="WNG">Wrong Null Guard</BugCode> <BugCode abbrev="MDM">More Dumb Methods</BugCode> -</MessageCollection> \ No newline at end of file +</MessageCollection> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 07:11:58
|
Revision: 1443 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1443&view=rev Author: dbrosius Date: 2010-01-05 07:11:47 +0000 (Tue, 05 Jan 2010) Log Message: ----------- using 1.5 now --> use enums Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java 2010-01-05 07:09:39 UTC (rev 1442) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java 2010-01-05 07:11:47 UTC (rev 1443) @@ -33,12 +33,7 @@ */ public class ManualArrayCopy extends BytecodeScanningDetector { - public static final int SEEN_NOTHING = 0; - public static final int SEEN_ARRAY1_LOAD = 1; - public static final int SEEN_ARRAY1_INDEX = 2; - public static final int SEEN_ARRAY2_LOAD = 3; - public static final int SEEN_ARRAY2_INDEX = 4; - public static final int SEEN_ELEM_LOAD = 5; + enum State {SAW_NOTHING, SAW_ARRAY1_LOAD, SAW_ARRAY1_INDEX, SAW_ARRAY2_LOAD, SAW_ARRAY2_INDEX, SAW_ELEM_LOAD} private static final BitSet arrayLoadOps = new BitSet(); static { arrayLoadOps.set(AALOAD); @@ -51,7 +46,7 @@ arrayLoadOps.set(FALOAD); } private BugReporter bugReporter; - private int state; + private State state; private int arrayIndexReg; private int loadInstruction; @@ -82,7 +77,7 @@ @Override public void visitCode(Code obj) { if (prescreen(getMethod())) { - state = SEEN_NOTHING; + state = State.SAW_NOTHING; super.visitCode(obj); } } @@ -90,45 +85,45 @@ @Override public void sawOpcode(int seen) { switch (state) { - case SEEN_NOTHING: + case SAW_NOTHING: if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) - state = SEEN_ARRAY1_LOAD; + state = State.SAW_ARRAY1_LOAD; break; - case SEEN_ARRAY1_LOAD: + case SAW_ARRAY1_LOAD: if (seen == ILOAD) { arrayIndexReg = getRegisterOperand(); - state = SEEN_ARRAY1_INDEX; + state = State.SAW_ARRAY1_INDEX; } else if ((seen >= ILOAD_0) && (seen <= ILOAD_3)) { arrayIndexReg = seen - ILOAD_0; - state = SEEN_ARRAY1_INDEX; + state = State.SAW_ARRAY1_INDEX; } else - state = SEEN_NOTHING; + state = State.SAW_NOTHING; break; - case SEEN_ARRAY1_INDEX: + case SAW_ARRAY1_INDEX: if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) - state = SEEN_ARRAY2_LOAD; + state = State.SAW_ARRAY2_LOAD; else - state = SEEN_NOTHING; + state = State.SAW_NOTHING; break; - case SEEN_ARRAY2_LOAD: + case SAW_ARRAY2_LOAD: if (seen == ILOAD) { if (arrayIndexReg == this.getRegisterOperand()) - state = SEEN_ARRAY2_INDEX; + state = State.SAW_ARRAY2_INDEX; else - state = SEEN_NOTHING; + state = State.SAW_NOTHING; } else if ((seen >= ILOAD_0) && (seen <= ILOAD_3)) { if (arrayIndexReg == (seen - ILOAD_0)) - state = SEEN_ARRAY2_INDEX; + state = State.SAW_ARRAY2_INDEX; else - state = SEEN_NOTHING; + state = State.SAW_NOTHING; } else - state = SEEN_NOTHING; + state = State.SAW_NOTHING; break; - case SEEN_ARRAY2_INDEX: + case SAW_ARRAY2_INDEX: if ((seen == AALOAD) || (seen == BALOAD) || (seen == CALOAD) @@ -138,13 +133,13 @@ || (seen == DALOAD) || (seen == FALOAD)) { loadInstruction = seen; - state = SEEN_ELEM_LOAD; + state = State.SAW_ELEM_LOAD; } else - state = SEEN_NOTHING; + state = State.SAW_NOTHING; break; - case SEEN_ELEM_LOAD: + case SAW_ELEM_LOAD: if ((seen == AASTORE) || (seen == BASTORE) || (seen == CASTORE) @@ -160,7 +155,7 @@ .addSourceLine(this)); } } - state = SEEN_NOTHING; + state = State.SAW_NOTHING; break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2010-01-05 07:09:46
|
Revision: 1442 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1442&view=rev Author: dbrosius Date: 2010-01-05 07:09:39 +0000 (Tue, 05 Jan 2010) Log Message: ----------- using 1.5 now --> use enums Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2010-01-05 07:05:04 UTC (rev 1441) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2010-01-05 07:09:39 UTC (rev 1442) @@ -41,22 +41,15 @@ */ public class ListIndexedIterating extends BytecodeScanningDetector { - private static final int SEEN_NOTHING = 0; - private static final int SEEN_IINC = 1; + enum State {SAW_NOTHING, SAW_IINC} + enum LoopState {LOOP_NOT_STARTED, LOOP_INDEX_LOADED_FOR_TEST, LOOP_IN_BODY, LOOP_IN_BODY_WITH_GET} + enum Stage {FIND_LOOP_STAGE, FIND_BUG_STAGE} - private static final int LOOP_NOT_STARTED = 0; - private static final int LOOP_INDEX_LOADED_FOR_TEST = 1; - private static final int LOOP_IN_BODY = 2; - private static final int LOOP_IN_BODY_WITH_GET = 3; - - private static final int FIND_LOOP_STAGE = 0; - private static final int FIND_BUG_STAGE = 1; - private BugReporter bugReporter; private OpcodeStack stack; private Set<ForLoop> possibleForLoops; - private int stage; - private int state; + private Stage stage; + private State state; private int loopReg; private boolean sawListSize; @@ -108,14 +101,14 @@ sawListSize = false; stack.resetForMethodEntry(this); - state = SEEN_NOTHING; - stage = FIND_LOOP_STAGE; + state = State.SAW_NOTHING; + stage = Stage.FIND_LOOP_STAGE; super.visitCode(obj); if (sawListSize) { stack.resetForMethodEntry(this); - state = SEEN_NOTHING; - stage = FIND_BUG_STAGE; + state = State.SAW_NOTHING; + stage = Stage.FIND_BUG_STAGE; super.visitCode(obj); } } @@ -128,7 +121,7 @@ */ @Override public void sawOpcode(final int seen) { - if (stage == FIND_LOOP_STAGE) + if (stage == Stage.FIND_LOOP_STAGE) sawOpcodeLoop(seen); else sawOpcodeBug(seen); @@ -144,14 +137,14 @@ stack.mergeJumps(this); switch (state) { - case SEEN_NOTHING: + case SAW_NOTHING: if ((seen == IINC) && (getIntConstant() == 1)) { loopReg = getRegisterOperand(); - state = SEEN_IINC; + state = State.SAW_IINC; } break; - case SEEN_IINC: + case SAW_IINC: if ((seen == GOTO) || (seen == GOTO_W)) { int branchTarget = getBranchTarget(); int pc = getPC(); @@ -159,7 +152,7 @@ possibleForLoops.add(new ForLoop( branchTarget, pc, loopReg)); } } - state = SEEN_NOTHING; + state = State.SAW_NOTHING; break; } @@ -191,7 +184,7 @@ if (getPC() == fl.getLoopStart()) { if ((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3))) { if (getReg(seen, ILOAD, ILOAD_0) == fl.getLoopReg()) { - fl.setLoopState(LOOP_INDEX_LOADED_FOR_TEST); + fl.setLoopState(LoopState.LOOP_INDEX_LOADED_FOR_TEST); continue; } } @@ -214,7 +207,7 @@ } int branchTarget = getBranchTarget(); if ((branchTarget >= (fl.getLoopEnd() + 3)) && (branchTarget <= (fl.getLoopEnd() + 5))) { - fl.setLoopState(LOOP_IN_BODY); + fl.setLoopState(LoopState.LOOP_IN_BODY); continue; } } @@ -222,7 +215,7 @@ case LOOP_IN_BODY: case LOOP_IN_BODY_WITH_GET: - if ((getPC() == fl.getLoopEnd()) && (fl.getLoopState() == LOOP_IN_BODY_WITH_GET)) { + if ((getPC() == fl.getLoopEnd()) && (fl.getLoopState() == LoopState.LOOP_IN_BODY_WITH_GET)) { bugReporter.reportBug(new BugInstance( this, "LII_LIST_INDEXED_ITERATING", NORMAL_PRIORITY ) .addClass(this) .addMethod(this) @@ -245,7 +238,7 @@ if (!sawGet) { it.remove(); } else { - fl.setLoopState(LOOP_IN_BODY_WITH_GET); + fl.setLoopState(LoopState.LOOP_IN_BODY_WITH_GET); if (stack.getStackDepth() > 1) { OpcodeStack.Item itm = stack.getStackItem(0); if (!itm.couldBeZero()) @@ -291,7 +284,7 @@ private int loopStart; private int loopEnd; private int loopReg; - private int loopState; + private LoopState loopState; private boolean loopRegLoaded; private OpcodeStack.Item loopCollectionItem; @@ -306,7 +299,7 @@ loopStart = start; loopEnd = end; loopReg = reg; - loopState = LOOP_NOT_STARTED; + loopState = LoopState.LOOP_NOT_STARTED; loopRegLoaded = false; loopCollectionItem = null; } @@ -343,7 +336,7 @@ * * @param state the new state */ - public void setLoopState(final int state) { + public void setLoopState(final LoopState state) { loopState = state; } @@ -352,7 +345,7 @@ * * @return the current state */ - public int getLoopState() { + public LoopState getLoopState() { return loopState; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |