Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib:[1195] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2009-05-09 21:07:42
|
Revision: 1195 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1195&view=rev Author: dbrosius Date: 2009-05-09 21:07:41 +0000 (Sat, 09 May 2009) Log Message: ----------- use the Type from BCEL not sun Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-09 21:06:27 UTC (rev 1194) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-09 21:07:41 UTC (rev 1195) @@ -22,9 +22,8 @@ import java.util.Set; import org.apache.bcel.classfile.Code; +import org.apache.bcel.generic.Type; -import com.sun.org.apache.bcel.internal.generic.Type; - import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-05-09 22:48:16
|
Revision: 1196 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1196&view=rev Author: dbrosius Date: 2009-05-09 22:48:08 +0000 (Sat, 09 May 2009) Log Message: ----------- ignore map.puts Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-09 21:07:41 UTC (rev 1195) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-09 22:48:08 UTC (rev 1196) @@ -36,6 +36,10 @@ * method. It doesn't report method calls where the arguments are constants. */ public class StutteredMethodArguments extends BytecodeScanningDetector { + private static Set<String> ignorableSignatures = new HashSet<String>(); + static { + ignorableSignatures.add("java/util/Map:put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + } private final BugReporter bugReporter; private OpcodeStack stack; @@ -90,15 +94,20 @@ case INVOKESTATIC: case INVOKEINTERFACE: case INVOKESPECIAL: + String clsName = getClassConstantOperand(); + String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); - Type[] args = Type.getArgumentTypes(signature); - if (args.length > 1) { - if (stack.getStackDepth() > args.length) { - if (duplicateArguments(stack, args.length)) { - bugReporter.reportBug(new BugInstance(this, "SMA_STUTTERED_METHOD_ARGUMENTS", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + String methodInfo = clsName + ":" + methodName + signature; + if (!ignorableSignatures.contains(methodInfo)) { + Type[] args = Type.getArgumentTypes(signature); + if (args.length > 1) { + if (stack.getStackDepth() > args.length) { + if (duplicateArguments(stack, args.length)) { + bugReporter.reportBug(new BugInstance(this, "SMA_STUTTERED_METHOD_ARGUMENTS", 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...> - 2009-05-09 23:35:18
|
Revision: 1199 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1199&view=rev Author: dbrosius Date: 2009-05-09 23:35:15 +0000 (Sat, 09 May 2009) Log Message: ----------- differentiate this.a and foo.a when this and foo are of the same class Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-09 23:17:00 UTC (rev 1198) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-09 23:35:15 UTC (rev 1199) @@ -88,6 +88,8 @@ */ @Override public void sawOpcode(int seen) { + String fieldSource = null; + try { switch (seen) { case INVOKEVIRTUAL: @@ -112,9 +114,32 @@ } } break; + + case GETFIELD: + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + int reg = item.getRegisterNumber(); + if (reg >= 0) + fieldSource = String.valueOf(reg); + else { + XField f = item.getXField(); + if (f != null) { + fieldSource = f.getClassName() + ':' + f.getName(); + } else { + fieldSource = ""; + } + } + } + break; } } finally { stack.sawOpcode(this, seen); + if (fieldSource != null) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(fieldSource); + } + } } } @@ -139,7 +164,10 @@ } else { XField f = item.getXField(); if (f != null) { - arg = f.getName(); + String fieldSource = (String)item.getUserValue(); + if (fieldSource == null) + fieldSource = ""; + arg = fieldSource + '|' + f.getClassName() + ':' + f.getName(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-05-10 00:01:45
|
Revision: 1200 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1200&view=rev Author: dbrosius Date: 2009-05-10 00:01:44 +0000 (Sun, 10 May 2009) Log Message: ----------- filter out primitives Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-09 23:35:15 UTC (rev 1199) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 00:01:44 UTC (rev 1200) @@ -132,6 +132,8 @@ } break; } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); } finally { stack.sawOpcode(this, seen); if (fieldSource != null) { @@ -150,13 +152,13 @@ * @param length the number of arguments * @return if there are duplicates */ - private boolean duplicateArguments(OpcodeStack stack, int length) + private boolean duplicateArguments(OpcodeStack stack, int length) throws ClassNotFoundException { Set<String> args = new HashSet<String>(); for (int i = 0; i < length; i++) { OpcodeStack.Item item = stack.getStackItem(i); - if (item.getConstant() == null) { + if ((item.getSignature().startsWith("L")) && (item.getConstant() == null)) { String arg = null; int reg = item.getRegisterNumber(); if (reg >= 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-05-10 02:02:14
|
Revision: 1203 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1203&view=rev Author: dbrosius Date: 2009-05-10 01:57:46 +0000 (Sun, 10 May 2009) Log Message: ----------- should be !starts with Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 01:56:59 UTC (rev 1202) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 01:57:46 UTC (rev 1203) @@ -159,7 +159,7 @@ OpcodeStack.Item item = stack.getStackItem(i); String signature = item.getSignature(); - if (signature.startsWith("L") && signature.startsWith("Ljava/lang/") && (item.getConstant() == null)) { + if (signature.startsWith("L") && !signature.startsWith("Ljava/lang/") && (item.getConstant() == null)) { String arg = null; int reg = item.getRegisterNumber(); if (reg >= 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-05-10 02:22:18
|
Revision: 1202 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1202&view=rev Author: dbrosius Date: 2009-05-10 01:56:59 +0000 (Sun, 10 May 2009) Log Message: ----------- rule out classes from java/lang/... Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 00:01:59 UTC (rev 1201) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 01:56:59 UTC (rev 1202) @@ -158,7 +158,8 @@ for (int i = 0; i < length; i++) { OpcodeStack.Item item = stack.getStackItem(i); - if ((item.getSignature().startsWith("L")) && (item.getConstant() == null)) { + String signature = item.getSignature(); + if (signature.startsWith("L") && signature.startsWith("Ljava/lang/") && (item.getConstant() == null)) { String arg = null; int reg = item.getRegisterNumber(); if (reg >= 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-05-10 15:14:15
|
Revision: 1204 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1204&view=rev Author: dbrosius Date: 2009-05-10 15:14:13 +0000 (Sun, 10 May 2009) Log Message: ----------- don't report SMA when the parameter types for which the same arguments are passed, are different Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 01:57:46 UTC (rev 1203) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 15:14:13 UTC (rev 1204) @@ -101,10 +101,10 @@ String signature = getSigConstantOperand(); String methodInfo = clsName + ":" + methodName + signature; if (!ignorableSignatures.contains(methodInfo)) { - Type[] args = Type.getArgumentTypes(signature); - if (args.length > 1) { - if (stack.getStackDepth() > args.length) { - if (duplicateArguments(stack, args.length)) { + Type[] parms = Type.getArgumentTypes(signature); + if (parms.length > 1) { + if (stack.getStackDepth() > parms.length) { + if (duplicateArguments(stack, parms)) { bugReporter.reportBug(new BugInstance(this, "SMA_STUTTERED_METHOD_ARGUMENTS", NORMAL_PRIORITY) .addClass(this) .addMethod(this) @@ -149,13 +149,13 @@ * looks for duplicate arguments that are not constants * * @param stack the stack to look thru - * @param length the number of arguments + * @param parms the arguments to the method being called * @return if there are duplicates */ - private boolean duplicateArguments(OpcodeStack stack, int length) throws ClassNotFoundException + private boolean duplicateArguments(OpcodeStack stack, Type[] parms) throws ClassNotFoundException { Set<String> args = new HashSet<String>(); - for (int i = 0; i < length; i++) { + for (int i = 0; i < parms.length; i++) { OpcodeStack.Item item = stack.getStackItem(i); String signature = item.getSignature(); @@ -175,6 +175,7 @@ } if (arg != null) { + arg += "--" + parms[i].getSignature(); if (args.contains(arg)) return true; args.add(arg); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-05-10 15:22:30
|
Revision: 1205 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1205&view=rev Author: dbrosius Date: 2009-05-10 15:22:28 +0000 (Sun, 10 May 2009) Log Message: ----------- don't report when calling an overloaded method Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 15:14:13 UTC (rev 1204) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 15:22:28 UTC (rev 1205) @@ -42,6 +42,7 @@ } private final BugReporter bugReporter; private OpcodeStack stack; + private String processedMethodName; /** * constructs a SMA detector given the reporter to report bugs on. @@ -77,6 +78,7 @@ @Override public void visitCode(Code obj) { stack.resetForMethodEntry(this); + processedMethodName = getMethod().getName(); super.visitCode(obj); } @@ -100,7 +102,7 @@ String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); String methodInfo = clsName + ":" + methodName + signature; - if (!ignorableSignatures.contains(methodInfo)) { + if ((!processedMethodName.equals(methodName)) && !ignorableSignatures.contains(methodInfo)) { Type[] parms = Type.getArgumentTypes(signature); if (parms.length > 1) { if (stack.getStackDepth() > parms.length) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-05-10 23:38:54
|
Revision: 1207 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1207&view=rev Author: dbrosius Date: 2009-05-10 23:38:50 +0000 (Sun, 10 May 2009) Log Message: ----------- make sure caller and callee are in the same basic package Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 15:22:44 UTC (rev 1206) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 23:38:50 UTC (rev 1207) @@ -24,6 +24,8 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.SignatureUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -42,6 +44,7 @@ } private final BugReporter bugReporter; private OpcodeStack stack; + private String processedPackageName; private String processedMethodName; /** @@ -64,9 +67,11 @@ { try { stack = new OpcodeStack(); + processedPackageName = classContext.getJavaClass().getPackageName(); super.visitClassContext(classContext); } finally { stack = null; + processedPackageName = null; } } @@ -77,9 +82,14 @@ */ @Override public void visitCode(Code obj) { - stack.resetForMethodEntry(this); - processedMethodName = getMethod().getName(); - super.visitCode(obj); + try { + stack.resetForMethodEntry(this); + processedMethodName = getMethod().getName(); + super.visitCode(obj); + } finally { + processedMethodName = null; + } + } /** @@ -99,18 +109,27 @@ case INVOKEINTERFACE: case INVOKESPECIAL: String clsName = getClassConstantOperand(); - String methodName = getNameConstantOperand(); - String signature = getSigConstantOperand(); - String methodInfo = clsName + ":" + methodName + signature; - if ((!processedMethodName.equals(methodName)) && !ignorableSignatures.contains(methodInfo)) { - Type[] parms = Type.getArgumentTypes(signature); - if (parms.length > 1) { - if (stack.getStackDepth() > parms.length) { - if (duplicateArguments(stack, parms)) { - bugReporter.reportBug(new BugInstance(this, "SMA_STUTTERED_METHOD_ARGUMENTS", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + String packageName; + int slashPos = clsName.lastIndexOf('/'); + if (slashPos >= 0) + packageName = clsName.substring(0, slashPos); + else + packageName = ""; + + if (SignatureUtils.similarPackages(processedPackageName, packageName, 2)) { + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + String methodInfo = clsName + ":" + methodName + signature; + if ((!processedMethodName.equals(methodName)) && !ignorableSignatures.contains(methodInfo)) { + Type[] parms = Type.getArgumentTypes(signature); + if (parms.length > 1) { + if (stack.getStackDepth() > parms.length) { + if (duplicateArguments(stack, parms)) { + bugReporter.reportBug(new BugInstance(this, "SMA_STUTTERED_METHOD_ARGUMENTS", 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...> - 2009-05-11 16:49:19
|
Revision: 1208 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1208&view=rev Author: dbrosius Date: 2009-05-11 16:49:10 +0000 (Mon, 11 May 2009) Log Message: ----------- add GETSTATIC Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-10 23:38:50 UTC (rev 1207) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-05-11 16:49:10 UTC (rev 1208) @@ -112,9 +112,13 @@ String packageName; int slashPos = clsName.lastIndexOf('/'); if (slashPos >= 0) + { packageName = clsName.substring(0, slashPos); + } else + { packageName = ""; + } if (SignatureUtils.similarPackages(processedPackageName, packageName, 2)) { String methodName = getNameConstantOperand(); @@ -137,11 +141,14 @@ break; case GETFIELD: + case GETSTATIC: if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); int reg = item.getRegisterNumber(); if (reg >= 0) + { fieldSource = String.valueOf(reg); + } else { XField f = item.getXField(); if (f != null) { @@ -190,7 +197,9 @@ if (f != null) { String fieldSource = (String)item.getUserValue(); if (fieldSource == null) + { fieldSource = ""; + } arg = fieldSource + '|' + f.getClassName() + ':' + f.getName(); } } @@ -198,7 +207,9 @@ if (arg != null) { arg += "--" + parms[i].getSignature(); if (args.contains(arg)) + { return true; + } args.add(arg); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2009-09-06 04:03:47
|
Revision: 1254 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1254&view=rev Author: dbrosius Date: 2009-09-06 04:03:39 +0000 (Sun, 06 Sep 2009) Log Message: ----------- don't catch exception that isn't thrown Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-09-06 04:02:51 UTC (rev 1253) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StutteredMethodArguments.java 2009-09-06 04:03:39 UTC (rev 1254) @@ -160,8 +160,6 @@ } break; } - } catch (ClassNotFoundException cnfe) { - bugReporter.reportMissingClass(cnfe); } finally { stack.sawOpcode(this, seen); if (fieldSource != null) { @@ -180,7 +178,7 @@ * @param parms the arguments to the method being called * @return if there are duplicates */ - private boolean duplicateArguments(OpcodeStack stack, Type[] parms) throws ClassNotFoundException + private boolean duplicateArguments(OpcodeStack stack, Type[] parms) { Set<String> args = new HashSet<String>(); for (int i = 0; i < parms.length; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |