[Fb-contrib-commit] SF.net SVN: fb-contrib: [529] trunk/fb-contrib/samples
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-05-11 04:20:44
|
Revision: 529 Author: dbrosius Date: 2006-05-10 21:20:36 -0700 (Wed, 10 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=529&view=rev Log Message: ----------- stores to fields in regular methods make then ineligible for reporting on. Modified Paths: -------------- trunk/fb-contrib/samples/NMCS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java Modified: trunk/fb-contrib/samples/NMCS_Sample.java =================================================================== --- trunk/fb-contrib/samples/NMCS_Sample.java 2006-05-10 04:20:11 UTC (rev 528) +++ trunk/fb-contrib/samples/NMCS_Sample.java 2006-05-11 04:20:36 UTC (rev 529) @@ -1,20 +1,24 @@ +import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.Vector; public class NMCS_Sample { - private static List<String> test = new Vector<String>(); + private static List<String> test1 = new Vector<String>(); static { - test.add("one"); - test.add("two"); - test.add("three"); + test1.add("one"); + test1.add("two"); + test1.add("three"); } + private Map<String, String> test2 = new Hashtable<String, String>(); + public String test1() { StringBuffer sb = new StringBuffer(); String comma = ""; - for (String s : test) + for (String s : test1) { sb.append(comma); comma = ","; @@ -24,4 +28,11 @@ return sb.toString(); } + public String test2() + { + test2 = new Hashtable<String, String>(); + + return test2.get("foo"); + } + } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-10 04:20:11 UTC (rev 528) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-11 04:20:36 UTC (rev 529) @@ -218,8 +218,10 @@ } private void sawMethodOpcode(int seen) { + boolean isSyncCollection = false; try { stack.mergeJumps(this); + isSyncCollection = isSyncCollectionCreation(seen); switch (seen) { case INVOKEVIRTUAL: @@ -257,12 +259,24 @@ } } break; + + case PUTFIELD: + case PUTSTATIC: + String fieldName = getNameConstantOperand(); + collectionFields.remove(fieldName); + break; } //look for code that alters the collection, passes it to a method, returns it, etc //watch out for aliases } finally { stack.sawOpcode(this, seen); + if (isSyncCollection) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(Boolean.TRUE); + } + } } } @@ -287,10 +301,12 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() != null) { - FieldInfo fi = collectionFields.get(fieldName); - if (fi != null) { - fi.getFieldAnnotation().setSourceLines(SourceLineAnnotation.fromVisitedInstruction(this)); - fi.setSynchronized(); + if (fieldName != null) { + FieldInfo fi = collectionFields.get(fieldName); + if (fi != null) { + fi.getFieldAnnotation().setSourceLines(SourceLineAnnotation.fromVisitedInstruction(this)); + fi.setSynchronized(); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |