[Fb-contrib-commit] SF.net SVN: fb-contrib: [862] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-02-17 08:20:21
|
Revision: 862 http://svn.sourceforge.net/fb-contrib/?rev=862&view=rev Author: dbrosius Date: 2007-02-17 00:20:21 -0800 (Sat, 17 Feb 2007) Log Message: ----------- attempt #2: fix fp sb.append(ISB_Sample.getBigger(a + b, d)); Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2007-02-17 07:43:47 UTC (rev 861) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2007-02-17 08:20:21 UTC (rev 862) @@ -75,6 +75,7 @@ @Override public void sawOpcode(final int seen) { + Boolean nestedSB = null; try { stack.mergeJumps(this); @@ -85,12 +86,8 @@ && "<init>".equals(getNameConstantOperand()) && "()V".equals(getSigConstantOperand())) { OpcodeStack.Item itm = getStringBufferItemAt(2); - if ((itm != null) && (itm.getUserValue() == null)) { - bugReporter.reportBug( - new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (itm != null) { + nestedSB = Boolean.TRUE; } } } else if (seen == INVOKEVIRTUAL) { @@ -119,11 +116,36 @@ } } } + String calledClass = getClassConstantOperand(); + if (("java/lang/StringBuffer".equals(calledClass) + || "java/lang/StringBuilder".equals(calledClass))) { + String methodName = getNameConstantOperand(); + if ("append".equals(methodName)) { + OpcodeStack.Item itm = getStringBufferItemAt(1); + nestedSB = (itm == null) ? null : (Boolean)itm.getUserValue(); + + if (stack.getStackDepth() > 0) { + itm = stack.getStackItem(0); + if (itm.getUserValue() != null) { + bugReporter.reportBug( + new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + + } + } + } else if ("toString".equals(methodName)) { + OpcodeStack.Item itm = getStringBufferItemAt(0); + nestedSB = (itm == null) ? null : (Boolean)itm.getUserValue(); + } + } + } else if (seen == GOTO) { int depth = stack.getStackDepth(); for (int i = 0; i < depth; i++) { OpcodeStack.Item itm = stack.getStackItem(i); - itm.setUserValue(Boolean.TRUE); + itm.setUserValue(Boolean.FALSE); } } else if (seen == LDC) { Constant c = getConstantRefOperand(); @@ -135,6 +157,12 @@ } } finally { stack.sawOpcode(this, seen); + if (nestedSB != null) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + itm.setUserValue(nestedSB); + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |