[Fb-contrib-commit] SF.net SVN: fb-contrib: [650] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-09-15 22:44:13
|
Revision: 650 http://svn.sourceforge.net/fb-contrib/?rev=650&view=rev Author: dbrosius Date: 2006-09-15 15:44:04 -0700 (Fri, 15 Sep 2006) Log Message: ----------- add risky classes to ignore as well, especially ByteBuffer Modified Paths: -------------- trunk/fb-contrib/samples/RMC_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java Modified: trunk/fb-contrib/samples/RMC_Sample.java =================================================================== --- trunk/fb-contrib/samples/RMC_Sample.java 2006-09-14 04:57:15 UTC (rev 649) +++ trunk/fb-contrib/samples/RMC_Sample.java 2006-09-15 22:44:04 UTC (rev 650) @@ -1,3 +1,4 @@ +import java.nio.ByteBuffer; import java.util.Calendar; import java.util.Date; @@ -11,4 +12,10 @@ long j = e.getTime(); return l == j; } + + public void rmcFP(ByteBuffer bb) + { + int i = bb.getInt(); + int j = bb.getInt(); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-09-14 04:57:15 UTC (rev 649) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/RedundantMethodCalls.java 2006-09-15 22:44:04 UTC (rev 650) @@ -46,7 +46,8 @@ */ public class RedundantMethodCalls extends BytecodeScanningDetector { - public static final String RMC_RISKY_USER_KEY = "fbcontrib.RMC.riskynames"; + public static final String RMC_RISKY_FIELD_USER_KEY = "fbcontrib.RMC.riskynames"; + public static final String RMC_RISKY_CLASS_USER_KEY = "fbcontrib.RMC.riskyclasses"; private static Set<String> riskyMethodNameContents = new HashSet<String>(); static { @@ -61,13 +62,26 @@ riskyMethodNameContents.add("pop"); riskyMethodNameContents.add("clone"); - String userNameProp = System.getProperty(RMC_RISKY_USER_KEY); + String userNameProp = System.getProperty(RMC_RISKY_FIELD_USER_KEY); if (userNameProp != null) { String[] userNames = userNameProp.split("\\s*,\\s*"); for (String name : userNames) riskyMethodNameContents.add(name.toLowerCase()); } } + private static Set<String> riskyClassNames = new HashSet<String>(); + static { + riskyClassNames.add("java/nio/ByteBuffer"); + riskyClassNames.add("java/io/DataInputStream"); + riskyClassNames.add("java/io/ObjectInputStream"); + String userNameProp = System.getProperty(RMC_RISKY_CLASS_USER_KEY); + if (userNameProp != null) { + String[] userNames = userNameProp.split("\\s*,\\s*"); + for (String name : userNames) + riskyClassNames.add(name); + } + } + private BugReporter bugReporter; private OpcodeStack stack = null; private Map<Integer, MethodCall> localMethodCalls = null; @@ -146,6 +160,7 @@ } else if (seen == PUTFIELD) { fieldMethodCalls.remove(getNameConstantOperand()); } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { + String className = getClassConstantOperand(); String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); int parmCount = Type.getArgumentTypes(signature).length; @@ -170,7 +185,7 @@ return; if (mc != null) { - if (!signature.endsWith("V") && methodName.equals(mc.getName()) && signature.equals(mc.getSignature()) && !isRiskyName(methodName)) { + if (!signature.endsWith("V") && methodName.equals(mc.getName()) && signature.equals(mc.getSignature()) && !isRiskyName(className, methodName)) { Object[] parms = mc.getParms(); if (Arrays.equals(parms, parmConstants)) { Statistics statistics = Statistics.getStatistics(); @@ -201,12 +216,16 @@ } /** - * returns true if the method name contains a pattern that is considered likely to be this modifying + * returns true if the class or method name contains a pattern that is considered likely to be this modifying * + * @param className the class name to check * @param methodName the method name to check * @return whether the method sounds like it modifies this */ - private boolean isRiskyName(String methodName) { + private boolean isRiskyName(String className, String methodName) { + if (riskyClassNames.contains(className)) + return true; + methodName = methodName.toLowerCase(Locale.ENGLISH); for (String riskyName : riskyMethodNameContents) { if (methodName.indexOf(riskyName) >= 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |