Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [888] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/d
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-06-25 22:14:57
|
Revision: 888 http://svn.sourceforge.net/fb-contrib/?rev=888&view=rev Author: dbrosius Date: 2007-06-25 15:14:58 -0700 (Mon, 25 Jun 2007) Log Message: ----------- some fixes - still not working 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-06-24 22:58:05 UTC (rev 887) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-25 22:14:58 UTC (rev 888) @@ -118,8 +118,8 @@ } } } else if ("keySet".equals(methodName) || "values".equals(methodName) || "iterator".equals(methodName) || "next".equals(methodName)) { - if (stack.getStackDepth() > 1) { - OpcodeStack.Item itm = stack.getStackItem(1); + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); reg = isLocalCollection(itm); if (reg >= 0) { sawAlias = true; @@ -132,7 +132,7 @@ reg = isLocalCollection(colItem); if ((reg >= 0) && (valueItem.getUserValue() != null)) { - bugReporter.reportBug(new BugInstance(this, "UTA_USE_ADD_ALL", NORMAL_PRIORITY) + bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", 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...> - 2007-06-26 21:27:24
|
Revision: 890 http://svn.sourceforge.net/fb-contrib/?rev=890&view=rev Author: dbrosius Date: 2007-06-26 14:27:23 -0700 (Tue, 26 Jun 2007) Log Message: ----------- starting to work a little, with many false positives 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-06-25 22:17:43 UTC (rev 889) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-26 21:27:23 UTC (rev 890) @@ -36,7 +36,10 @@ private BugReporter bugReporter; private OpcodeStack stack; - private Map<Integer, Object> userValues; + /** register to alias register */ + private Map<Integer, Integer> userValues; + /** alias register to loop end */ + private Map<Integer, Integer> loops; /** * constructs a UTA detector given the reporter to report bugs on @@ -70,7 +73,7 @@ } /** - * implements the visitor to reset the stack and uservalues + * implements the visitor to reset the stack and userValues and loops * * @param obj the context object of the currently parsed code block */ @@ -78,10 +81,12 @@ public void visitCode(Code obj) { try { stack.resetForMethodEntry(this); - userValues = new HashMap<Integer, Object>(); + userValues = new HashMap<Integer, Integer>(); + loops = new HashMap<Integer, Integer>(); super.visitCode(obj); } finally { userValues = null; + loops = null; } } @@ -93,7 +98,7 @@ @Override public void sawOpcode(int seen) { int reg = -1; - Object uValue = null; + Integer uValue = null; boolean sawAlias = false; boolean sawLoad = false; @@ -101,15 +106,7 @@ if (seen == INVOKEINTERFACE) { String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); - if ("size".equals(methodName) && "()I".equals(signature)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - reg = isLocalCollection(itm); - if (reg >= 0) { - sawAlias = true; - } - } - } else if ("get".equals(methodName) && "(I)Ljava/lang/Object;".equals(signature)) { + if ("get".equals(methodName) && "(I)Ljava/lang/Object;".equals(signature)) { if (stack.getStackDepth() > 1) { OpcodeStack.Item itm = stack.getStackItem(1); reg = isLocalCollection(itm); @@ -117,7 +114,7 @@ sawAlias = true; } } - } else if ("keySet".equals(methodName) || "values".equals(methodName) || "iterator".equals(methodName) || "next".equals(methodName)) { + } 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); @@ -130,41 +127,54 @@ OpcodeStack.Item colItem = stack.getStackItem(1); OpcodeStack.Item valueItem = stack.getStackItem(0); reg = isLocalCollection(colItem); - if ((reg >= 0) - && (valueItem.getUserValue() != null)) { - bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (reg >= 0) { + uValue = (Integer)valueItem.getUserValue(); + if (uValue != null) { + Integer loopEnd = loops.get(uValue); + if ((loopEnd != null) && (getPC() < loopEnd.intValue())) { + 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 = stack.getStackItem(0).getUserValue(); + uValue = (Integer)stack.getStackItem(0).getUserValue(); userValues.put(Integer14.valueOf(RegisterUtils.getStoreReg(this, seen)), uValue); } } else if (((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3))) || ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3)))) { sawLoad = true; - } else if (seen == IF_ICMPGE) { - if (stack.getStackDepth() > 1) { - OpcodeStack.Item itm1 = stack.getStackItem(1); - OpcodeStack.Item itm2 = stack.getStackItem(0); - reg = itm1.getRegisterNumber(); - if ((reg >= 0) && (itm1.couldBeZero())) { - uValue = itm2.getUserValue(); - if (uValue != null) { - userValues.put(Integer14.valueOf(reg), uValue); + } else if (seen == IFEQ) { + if (stack.getStackDepth() > 0) { + if (getBranchOffset() > 0) { + int gotoPos = getBranchTarget() - 3; + byte[] code = getCode().getCode(); + if ((0x00FF & code[gotoPos]) == GOTO) { + short brOffset = (short)(0x0FF & code[gotoPos+1]); + brOffset <<= 8; + brOffset |= (0x0FF & code[gotoPos+2]); + gotoPos += brOffset; + if (brOffset < getPC()) { + OpcodeStack.Item itm = stack.getStackItem(0); + uValue = (Integer)itm.getUserValue(); + if (uValue != null) { + loops.put(uValue, Integer.valueOf(getBranchTarget())); + } + } } } } } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - uValue = itm.getUserValue(); - if (uValue instanceof Integer) { + uValue = (Integer)itm.getUserValue(); + if (uValue != null) { reg = ((Integer)uValue).intValue(); sawAlias = true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-06-26 21:55:46
|
Revision: 891 http://svn.sourceforge.net/fb-contrib/?rev=891&view=rev Author: dbrosius Date: 2007-06-26 14:55:38 -0700 (Tue, 26 Jun 2007) Log Message: ----------- remove false positives when the add is in a conditional (inside the loop) 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-06-26 21:27:23 UTC (rev 890) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-26 21:55:38 UTC (rev 891) @@ -38,8 +38,8 @@ private OpcodeStack stack; /** register to alias register */ private Map<Integer, Integer> userValues; - /** alias register to loop end */ - private Map<Integer, Integer> loops; + /** alias register to loop info */ + private Map<Integer, LoopInfo> loops; /** * constructs a UTA detector given the reporter to report bugs on @@ -82,7 +82,7 @@ try { stack.resetForMethodEntry(this); userValues = new HashMap<Integer, Integer>(); - loops = new HashMap<Integer, Integer>(); + loops = new HashMap<Integer, LoopInfo>(); super.visitCode(obj); } finally { userValues = null; @@ -130,8 +130,8 @@ if (reg >= 0) { uValue = (Integer)valueItem.getUserValue(); if (uValue != null) { - Integer loopEnd = loops.get(uValue); - if ((loopEnd != null) && (getPC() < loopEnd.intValue())) { + LoopInfo loop = loops.get(uValue); + if ((loop != null) && loop.isInLoop(getPC())) { bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) .addClass(this) .addMethod(this) @@ -164,12 +164,24 @@ OpcodeStack.Item itm = stack.getStackItem(0); uValue = (Integer)itm.getUserValue(); if (uValue != null) { - loops.put(uValue, Integer.valueOf(getBranchTarget())); + loops.put(uValue, new LoopInfo(getPC(), getBranchTarget())); } } + } else { + LoopInfo loop = findLoop(getPC()); + if (loop != null) { + loop.addConditionalRange(getPC(), getBranchTarget()); + } } } } + } else if ((seen > IFEQ) && (seen <= IF_ACMPNE)) { + if (getBranchOffset() > 0) { + LoopInfo loop = findLoop(getPC()); + if (loop != null) { + loop.addConditionalRange(getPC(), getBranchTarget()); + } + } } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); @@ -225,4 +237,45 @@ return -1; } + + private LoopInfo findLoop(int pc) { + for (LoopInfo loop : loops.values()) { + if (loop.isInLoop(pc)) + return loop; + } + + return null; + } + + static class LoopInfo + { + private int start; + private int end; + private Map<Integer, Integer> conditionalRanges = new HashMap<Integer, Integer>(); + + public LoopInfo(int loopStart, int loopEnd) + { + start = loopStart; + end = loopEnd; + } + + public void addConditionalRange(int condStart, int condEnd) + { + conditionalRanges.put(Integer14.valueOf(condStart), Integer14.valueOf(condEnd)); + } + + public boolean isInLoop(int pc) + { + if ((pc < start) || (pc > end)) + return false; + + for (Map.Entry<Integer, Integer> entry : conditionalRanges.entrySet()) + { + if ((pc >= entry.getKey().intValue()) && pc <= entry.getValue().intValue()) + return false; + } + + return true; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-06-27 06:03:27
|
Revision: 893 http://svn.sourceforge.net/fb-contrib/?rev=893&view=rev Author: dbrosius Date: 2007-06-26 23:03:27 -0700 (Tue, 26 Jun 2007) Log Message: ----------- ignore conditional else blocks 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-06-26 23:05:51 UTC (rev 892) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-27 06:03:27 UTC (rev 893) @@ -175,7 +175,7 @@ } } } - } else if ((seen > IFEQ) && (seen <= IF_ACMPNE)) { + } else if ((seen > IFEQ) && (seen <= GOTO)) { if (getBranchOffset() > 0) { LoopInfo loop = findLoop(getPC()); if (loop != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-06-29 05:41:11
|
Revision: 894 http://svn.sourceforge.net/fb-contrib/?rev=894&view=rev Author: dbrosius Date: 2007-06-28 22:41:13 -0700 (Thu, 28 Jun 2007) Log Message: ----------- filter out adds inside conditionals guarded by ifnull and ifnonnull 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-06-27 06:03:27 UTC (rev 893) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-29 05:41:13 UTC (rev 894) @@ -175,7 +175,7 @@ } } } - } else if ((seen > IFEQ) && (seen <= GOTO)) { + } else if (((seen > IFEQ) && (seen <= GOTO)) || (seen == IFNULL) || (seen == IFNONNULL)) { if (getBranchOffset() > 0) { LoopInfo loop = findLoop(getPC()); if (loop != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-06-29 05:55:40
|
Revision: 895 http://svn.sourceforge.net/fb-contrib/?rev=895&view=rev Author: dbrosius Date: 2007-06-28 22:55:41 -0700 (Thu, 28 Jun 2007) Log Message: ----------- fix ifeq checking of loops 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-06-29 05:41:13 UTC (rev 894) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-29 05:55:41 UTC (rev 895) @@ -160,7 +160,7 @@ brOffset <<= 8; brOffset |= (0x0FF & code[gotoPos+2]); gotoPos += brOffset; - if (brOffset < getPC()) { + if (gotoPos < getPC()) { OpcodeStack.Item itm = stack.getStackItem(0); uValue = (Integer)itm.getUserValue(); if (uValue != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-06-29 16:54:47
|
Revision: 896 http://svn.sourceforge.net/fb-contrib/?rev=896&view=rev Author: dbrosius Date: 2007-06-29 09:54:46 -0700 (Fri, 29 Jun 2007) Log Message: ----------- better filtering out of conditionals from loops 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-06-29 05:55:41 UTC (rev 895) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-29 16:54:46 UTC (rev 896) @@ -131,7 +131,7 @@ uValue = (Integer)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); - if ((loop != null) && loop.isInLoop(getPC())) { + if ((loop != null) && loop.isInLoop(getPC(), false)) { bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) .addClass(this) .addMethod(this) @@ -151,6 +151,7 @@ || ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3)))) { sawLoad = true; } else if (seen == IFEQ) { + boolean loopFound = false; if (stack.getStackDepth() > 0) { if (getBranchOffset() > 0) { int gotoPos = getBranchTarget() - 3; @@ -166,9 +167,13 @@ if (uValue != null) { loops.put(uValue, new LoopInfo(getPC(), getBranchTarget())); } + loopFound = true; } - } else { - LoopInfo loop = findLoop(getPC()); + } + + if (!loopFound) + { + LoopInfo loop = findLoop(getPC(), true); if (loop != null) { loop.addConditionalRange(getPC(), getBranchTarget()); } @@ -177,7 +182,7 @@ } } else if (((seen > IFEQ) && (seen <= GOTO)) || (seen == IFNULL) || (seen == IFNONNULL)) { if (getBranchOffset() > 0) { - LoopInfo loop = findLoop(getPC()); + LoopInfo loop = findLoop(getPC(), true); if (loop != null) { loop.addConditionalRange(getPC(), getBranchTarget()); } @@ -238,9 +243,9 @@ return -1; } - private LoopInfo findLoop(int pc) { + private LoopInfo findLoop(int pc, boolean ignoreConditionals) { for (LoopInfo loop : loops.values()) { - if (loop.isInLoop(pc)) + if (loop.isInLoop(pc, ignoreConditionals)) return loop; } @@ -264,11 +269,14 @@ conditionalRanges.put(Integer14.valueOf(condStart), Integer14.valueOf(condEnd)); } - public boolean isInLoop(int pc) + public boolean isInLoop(int pc, boolean ignoreConditionals) { if ((pc < start) || (pc > end)) return false; + if (ignoreConditionals) + return true; + for (Map.Entry<Integer, Integer> entry : conditionalRanges.entrySet()) { if ((pc >= entry.getKey().intValue()) && pc <= entry.getValue().intValue()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-09-15 03:02:04
|
Revision: 897 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=897&view=rev Author: dbrosius Date: 2007-09-14 20:02:05 -0700 (Fri, 14 Sep 2007) Log Message: ----------- add copyright 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-06-29 16:54:46 UTC (rev 896) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-09-15 03:02:05 UTC (rev 897) @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxiliary 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.HashMap; 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 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 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...> - 2008-01-20 13:29:49
|
Revision: 988 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=988&view=rev Author: dbrosius Date: 2008-01-20 05:29:48 -0800 (Sun, 20 Jan 2008) Log Message: ----------- type safety 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 2008-01-18 17:09:52 UTC (rev 987) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2008-01-20 13:29:48 UTC (rev 988) @@ -56,9 +56,9 @@ private BugReporter bugReporter; private OpcodeStack stack; /** register/field to alias register/field */ - private Map<Comparable, Comparable> userValues; + private Map<Comparable<?>, Comparable<?>> userValues; /** alias register to loop info */ - private Map<Comparable, LoopInfo> loops; + private Map<Comparable<?>, LoopInfo> loops; private boolean isInstanceMethod; /** @@ -101,8 +101,8 @@ public void visitCode(Code obj) { try { stack.resetForMethodEntry(this); - userValues = new HashMap<Comparable, Comparable>(); - loops = new HashMap<Comparable, LoopInfo>(); + userValues = new HashMap<Comparable<?>, Comparable<?>>(); + loops = new HashMap<Comparable<?>, LoopInfo>(); isInstanceMethod = !getMethod().isStatic(); super.visitCode(obj); } finally { @@ -118,8 +118,8 @@ */ @Override public void sawOpcode(int seen) { - Comparable regOrField = null; - Comparable uValue; + Comparable<?> regOrField = null; + Comparable<?> uValue; boolean sawAlias = false; boolean sawLoad = false; @@ -164,7 +164,7 @@ int reg = isLocalCollection(colItem); if (reg >= 0) { regOrField = Integer14.valueOf(reg); - uValue = (Comparable)valueItem.getUserValue(); + uValue = (Comparable<?>)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); if ((loop != null) && loop.isInLoop(getPC(), false)) { @@ -178,7 +178,7 @@ String field = isFieldCollection(colItem); if (field != null) { regOrField = field; - uValue = (Comparable)valueItem.getUserValue(); + uValue = (Comparable<?>)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); if ((loop != null) && loop.isInLoop(getPC(), false)) { @@ -195,7 +195,7 @@ } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) || ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { if (stack.getStackDepth() > 0) { - uValue = (Comparable)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))) @@ -214,7 +214,7 @@ gotoPos += brOffset; if (gotoPos < getPC()) { OpcodeStack.Item itm = stack.getStackItem(0); - uValue = (Comparable)itm.getUserValue(); + uValue = (Comparable<?>)itm.getUserValue(); if (uValue != null) { loops.put(uValue, new LoopInfo(getPC(), getBranchTarget())); } @@ -235,7 +235,7 @@ if (stack.getStackDepth() > 1) { OpcodeStack.Item item = stack.getStackItem(1); if (item.getRegisterNumber() == 0) { - uValue = (Comparable)stack.getStackItem(0).getUserValue(); + uValue = (Comparable<?>)stack.getStackItem(0).getUserValue(); userValues.put(getNameConstantOperand(), uValue); } } @@ -254,7 +254,7 @@ } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - uValue = (Comparable)itm.getUserValue(); + uValue = (Comparable<?>)itm.getUserValue(); if (uValue != null) { regOrField = uValue; sawAlias = true; @@ -298,7 +298,7 @@ * @throws ClassNotFoundException if the items class cannot be found */ private int isLocalCollection(OpcodeStack.Item item) throws ClassNotFoundException { - Comparable aliasReg = (Comparable)item.getUserValue(); + Comparable<?> aliasReg = (Comparable<?>)item.getUserValue(); if (aliasReg instanceof Integer) return ((Integer)aliasReg).intValue(); @@ -322,7 +322,7 @@ * @throws ClassNotFoundException if the items class cannot be found */ private String isFieldCollection(OpcodeStack.Item item) throws ClassNotFoundException { - Comparable aliasReg = (Comparable)item.getUserValue(); + Comparable<?> aliasReg = (Comparable<?>)item.getUserValue(); if (aliasReg instanceof String) return (String)aliasReg; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-03-09 03:46:47
|
Revision: 992 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=992&view=rev Author: dbrosius Date: 2008-03-08 19:46:50 -0800 (Sat, 08 Mar 2008) Log Message: ----------- Fix for 1909543: Check the result of add for a following POP and only report if the POP is seen. 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 2008-03-09 03:42:54 UTC (rev 991) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2008-03-09 03:46:50 UTC (rev 992) @@ -168,10 +168,12 @@ 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)); + if (this.getCodeByte(getNextPC()) == POP) { + bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } } } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |