Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [403] trunk/fb-contrib/samples
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-07 01:25:31
|
Revision: 403 Author: dbrosius Date: 2006-04-06 18:25:23 -0700 (Thu, 06 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=403&view=rev Log Message: ----------- better detection of when their is a possibility that a variable is owned, or at least may be owned. Modified Paths: -------------- trunk/fb-contrib/samples/NOS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java Modified: trunk/fb-contrib/samples/NOS_Sample.java =================================================================== --- trunk/fb-contrib/samples/NOS_Sample.java 2006-04-06 14:26:33 UTC (rev 402) +++ trunk/fb-contrib/samples/NOS_Sample.java 2006-04-07 01:25:23 UTC (rev 403) @@ -1,8 +1,30 @@ +import java.util.Map; public class NOS_Sample { + private Object lock = new Object(); + public String test(Object o) { synchronized(o) { return o.toString(); } } + + public String test2(Object o) { + synchronized(this) { + return o.toString(); + } + } + + public String test3(Map m) { + String v = (String)m.get("boo"); + synchronized (v) { + return v.substring(0,1); + } + } + + public String test4(Object o) { + synchronized(lock) { + return o.toString(); + } + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-04-06 14:26:33 UTC (rev 402) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-04-07 01:25:23 UTC (rev 403) @@ -67,12 +67,15 @@ */ @Override public void visitCode(Code obj) { - if (prescreen(getMethod())) { + Method method = getMethod(); + if (prescreen(method)) { stack.resetForMethodEntry(this); regPriorities.clear(); - int[] parmRegs = RegisterUtils.getParameterRegisters(getMethod()); + int[] parmRegs = RegisterUtils.getParameterRegisters(method); for (int reg : parmRegs) regPriorities.put(new Integer(reg), NORMAL); + if (!method.isStatic()) + regPriorities.put(new Integer(0), LOW); super.visitCode(obj); } } @@ -122,16 +125,23 @@ break; case INVOKEVIRTUAL: - case INVOKEINTERFACE: - case INVOKESPECIAL: { + case INVOKEINTERFACE: { String sig = getSigConstantOperand(); Type t = Type.getReturnType(sig); if (t.getSignature().startsWith("L")) { int parmCnt = Type.getArgumentTypes(sig).length; if (stack.getStackDepth() >= parmCnt) { OpcodeStack.Item itm = stack.getStackItem(parmCnt); - if (itm.getRegisterNumber() != 0) - tosIsPriority = NORMAL; + Integer priority = (Integer)itm.getUserValue(); + if ((priority != null) && OWNED.equals(priority)) { + tosIsPriority = OWNED; + } else { + int reg = itm.getRegisterNumber(); + if (reg > 0) + tosIsPriority = regPriorities.get(new Integer(reg)); + else + tosIsPriority = OWNED; + } } } } @@ -140,8 +150,15 @@ case INVOKESTATIC: { String sig = getSigConstantOperand(); Type t = Type.getReturnType(sig); - if (t.getSignature().startsWith("L")) { - tosIsPriority = NORMAL; + if (t.getSignature().startsWith("L")) + tosIsPriority = OWNED; // can't be sure + } + break; + + case INVOKESPECIAL: { + String name = getNameConstantOperand(); + if ("<init>".equals(name)) { + tosIsPriority = OWNED; } } break; @@ -150,7 +167,7 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); Integer priority = (Integer)itm.getUserValue(); - if (priority != null) { + if ((priority != null) && (!priority.equals(OWNED))) { bugReporter.reportBug(new BugInstance(this, "NOS_NON_OWNED_SYNCHRONIZATION", priority.intValue()) .addClass(this) .addMethod(this) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-09 20:09:36
|
Revision: 425 Author: dbrosius Date: 2006-04-09 13:09:29 -0700 (Sun, 09 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=425&view=rev Log Message: ----------- ad jsp-api.jar for samples to test NRTL Added Paths: ----------- trunk/fb-contrib/samples/lib/ trunk/fb-contrib/samples/lib/jsp-api.jar Added: trunk/fb-contrib/samples/lib/jsp-api.jar =================================================================== (Binary files differ) Property changes on: trunk/fb-contrib/samples/lib/jsp-api.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-17 00:44:30
|
Revision: 448 Author: dbrosius Date: 2006-04-16 17:44:22 -0700 (Sun, 16 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=448&view=rev Log Message: ----------- always write the source line annotation for the bad write, not the good write. Modified Paths: -------------- trunk/fb-contrib/samples/NRTL_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java Modified: trunk/fb-contrib/samples/NRTL_Sample.java =================================================================== --- trunk/fb-contrib/samples/NRTL_Sample.java 2006-04-15 00:37:03 UTC (rev 447) +++ trunk/fb-contrib/samples/NRTL_Sample.java 2006-04-17 00:44:22 UTC (rev 448) @@ -4,6 +4,7 @@ public class NRTL_Sample extends TagSupport { private String sample; + private String sample2; public void setSample(String s) { sample = s; @@ -12,12 +13,17 @@ public int doStartTag() throws JspException { try { sample += Math.random(); - pageContext.getOut().print(sample); + sample2 += sample; + pageContext.getOut().print(sample2); } catch (Exception ex) { throw new JspTagException("NRTL_Sample: " + ex.getMessage()); } return SKIP_BODY; } + + public void setSample2(String s) { + sample2 = s; + } public int doEndTag() { return EVAL_PAGE; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java 2006-04-15 00:37:03 UTC (rev 447) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java 2006-04-17 00:44:22 UTC (rev 448) @@ -71,7 +71,7 @@ /** * methodname:methodsig -> (fieldname:fieldtype)s */ - private Map<String, Set<String>> methodWrites; + private Map<String, Map<String, SourceLineAnnotation>> methodWrites; private Map<String, FieldAnnotation> fieldAnnotations; /** @@ -109,7 +109,7 @@ attributes = getAttributes(cls); if (attributes.size() > 0) { - methodWrites = new HashMap<String, Set<String>>(); + methodWrites = new HashMap<String, Map<String, SourceLineAnnotation>>(); fieldAnnotations = new HashMap<String, FieldAnnotation>(); super.visitClassContext(classContext); reportBugs(); @@ -172,18 +172,17 @@ public void sawOpcode(int seen) { if (seen == PUTFIELD) { String methodInfo = getMethodName() + ":" + getMethodSig(); - Set<String> fields = methodWrites.get(methodInfo); + Map<String, SourceLineAnnotation> fields = methodWrites.get(methodInfo); if (fields == null) { - fields = new HashSet<String>(); + fields = new HashMap<String, SourceLineAnnotation>(); methodWrites.put(methodInfo, fields); } String fieldName = getNameConstantOperand(); String fieldSig = getSigConstantOperand(); FieldAnnotation fa = new FieldAnnotation(getClassName(), fieldName, fieldSig, false); - fa.setSourceLines(SourceLineAnnotation.fromVisitedInstruction(this)); fieldAnnotations.put(fieldName, fa); - fields.add(fieldName + ":" + fieldSig); + fields.put(fieldName + ":" + fieldSig, SourceLineAnnotation.fromVisitedInstruction(this)); } } @@ -191,32 +190,35 @@ * generates all the bug reports for attributes that are not recycleable */ private void reportBugs() { - for (Map.Entry<String, String> entry : attributes.entrySet()) { - String methodInfo = entry.getKey(); - String attType = entry.getValue(); + for (Map.Entry<String, String> attEntry : attributes.entrySet()) { + String methodInfo = attEntry.getKey(); + String attType = attEntry.getValue(); - Set<String> fields = methodWrites.get(methodInfo); + Map<String, SourceLineAnnotation> fields = methodWrites.get(methodInfo); if ((fields == null) || (fields.size() != 1)) continue; - String fieldInfo = fields.iterator().next(); + + String fieldInfo = fields.keySet().iterator().next(); String fieldName = fieldInfo.substring(0, fieldInfo.indexOf(":")); String fieldType = fieldInfo.substring(fieldInfo.indexOf(":")+1); if (!attType.equals(fieldType)) continue; - int cnt = 0; - for (Set<String> allFields : methodWrites.values()) { - if (allFields.contains(fieldInfo)) - cnt++; + for (Map.Entry<String, Map<String, SourceLineAnnotation>> fwEntry : methodWrites.entrySet()) { + if (fwEntry.getKey().equals(methodInfo)) + continue; + + SourceLineAnnotation sla = fwEntry.getValue().get(fieldInfo); + if (sla != null) { + bugReporter.reportBug(new BugInstance(this, "NRTL_NON_RECYCLEABLE_TAG_LIB", NORMAL_PRIORITY) + .addClass(this) + .addField(fieldAnnotations.get(fieldName)) + .addSourceLine(sla)); + break; + } } - - if (cnt > 1) { - bugReporter.reportBug(new BugInstance(this, "NRTL_NON_RECYCLEABLE_TAG_LIB", NORMAL_PRIORITY) - .addClass(this) - .addField(fieldAnnotations.get(fieldName))); - } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-05-01 01:17:38
|
Revision: 511 Author: dbrosius Date: 2006-04-30 18:17:28 -0700 (Sun, 30 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=511&view=rev Log Message: ----------- reimplement using OpcodeStack Modified Paths: -------------- trunk/fb-contrib/samples/UEC_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java Modified: trunk/fb-contrib/samples/UEC_Sample.java =================================================================== --- trunk/fb-contrib/samples/UEC_Sample.java 2006-04-29 23:38:06 UTC (rev 510) +++ trunk/fb-contrib/samples/UEC_Sample.java 2006-05-01 01:17:28 UTC (rev 511) @@ -8,12 +8,23 @@ public class UEC_Sample { - enum Suite { Spades, Hearts, Clubs, Diamonds }; + public enum Suite { Spades, Hearts, Clubs, Diamonds }; private Set<Suite> wildSuites = new HashSet<Suite>(); private EnumSet<Suite> eWildSuites = EnumSet.noneOf(Suite.class); - public Map<Suite, Integer> deal() { + public UEC_Sample() + { + wildSuites.add(Suite.Spades); + } + + public UEC_Sample(Suite s) + { + wildSuites.add(s); + } + + public Map<Suite, Integer> deal() + { Map<Suite, Integer> hand = new HashMap<Suite, Integer>(); hand.put(Suite.Spades, new Integer(10)); hand.put(Suite.Hearts, new Integer(9)); @@ -21,7 +32,8 @@ return hand; } - public EnumMap<Suite, Integer> eDeal() { + public EnumMap<Suite, Integer> eDeal() + { EnumMap<Suite, Integer> hand = new EnumMap(Suite.class); hand.put(Suite.Spades, new Integer(10)); hand.put(Suite.Hearts, new Integer(9)); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-04-29 23:38:06 UTC (rev 510) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-05-01 01:17:28 UTC (rev 511) @@ -7,6 +7,7 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.ba.ClassContext; /** @@ -14,13 +15,9 @@ * more efficient to use EnumSet or EnumMap. It is a jdk1.5 only detector. */ public class UseEnumCollections extends BytecodeScanningDetector -{ - private static final int SEEN_NOTHING = 0; - private static final int SEEN_BIPUSH = 1; - private static final int SEEN_NEWINT = 2; - +{ private BugReporter bugReporter; - private int state; + private OpcodeStack stack; private boolean methodReported; /** * constructs a UEC detector given the reporter to report bugs on @@ -31,7 +28,7 @@ } /** - * implements the visitor to check that the class is greater or equal than 1.5 + * implements the visitor to check that the class is greater or equal than 1.5, and set and clear the stack * * @param classContext the context object for the currently parsed class */ @@ -39,10 +36,11 @@ try { JavaClass cls = classContext.getJavaClass(); if (cls.getMajor() >= Constants.MAJOR_1_5) { + stack = new OpcodeStack(); super.visitClassContext(classContext); } } finally { - + stack = null; } } @@ -52,57 +50,54 @@ * @param obj the context object for the currently parsed method */ public void visitMethod(Method obj) { - state = SEEN_NOTHING; + stack.resetForMethodEntry(this); methodReported = false; super.visitMethod(obj); } public void sawOpcode(int seen) { - if (methodReported) - return; - - switch (state) { - case SEEN_NOTHING: - if (seen == BIPUSH) - state = SEEN_BIPUSH; - break; + try { - case SEEN_BIPUSH: - if ((seen == INVOKESPECIAL) - && ("java/lang/Integer".equals(getClassConstantOperand()) - && ("<init>".equals(getNameConstantOperand()) - && ("(I)V".equals(getSigConstantOperand()))))) - state = SEEN_NEWINT; - else - state = SEEN_NOTHING; - break; - - case SEEN_NEWINT: + stack.mergeJumps(this); + if (methodReported) + return; + + if (seen == INVOKEINTERFACE) { boolean bug = false; - if (seen == INVOKEINTERFACE) { - String clsName = getClassConstantOperand(); - String methodName = getNameConstantOperand(); - String signature = getSigConstantOperand(); - if (("java/util/Map".equals(clsName)) - && ("put".equals(methodName)) - && ("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;".equals(signature))) { - bug = true; - } else if (("java/util/Set".equals(clsName)) - && ("add".equals(methodName)) - && ("(Ljava/lang/Object;)Ljava/lang/Object;".equals(signature))) { - bug = true; - } - - if (bug) { - bugReporter.reportBug(new BugInstance(this, "UEC_USE_ENUM_COLLECTIONS", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - methodReported = true; - } + String clsName = getClassConstantOperand(); + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + if (("java/util/Map".equals(clsName)) + && ("put".equals(methodName)) + && ("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;".equals(signature))) { + bug = isEnum(1); + } else if (("java/util/Set".equals(clsName)) + && ("add".equals(methodName)) + && ("(Ljava/lang/Object;)Z".equals(signature))) { + bug = isEnum(0); } - state = SEEN_NOTHING; - break; + + if (bug) { + bugReporter.reportBug(new BugInstance(this, "UEC_USE_ENUM_COLLECTIONS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + methodReported = true; + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + } finally { + stack.sawOpcode(this, seen); } } + + private boolean isEnum(int stackPos) throws ClassNotFoundException { + if (stack.getStackDepth() > stackPos) { + OpcodeStack.Item item = stack.getStackItem(stackPos); + if (item.getSignature().charAt(0) == 'L') + return (item.getJavaClass().isEnum()); + } + return false; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <dbr...@us...> - 2006-05-11 04:43:49
|
Revision: 530 Author: dbrosius Date: 2006-05-10 21:43:40 -0700 (Wed, 10 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=530&view=rev Log Message: ----------- more tests 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-11 04:20:36 UTC (rev 529) +++ trunk/fb-contrib/samples/NMCS_Sample.java 2006-05-11 04:43:40 UTC (rev 530) @@ -1,6 +1,8 @@ +import java.util.HashSet; import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Vector; public class NMCS_Sample @@ -14,6 +16,8 @@ private Map<String, String> test2 = new Hashtable<String, String>(); + private Set<String> test3 = new HashSet<String>(); + public String test1() { StringBuffer sb = new StringBuffer(); @@ -35,4 +39,11 @@ return test2.get("foo"); } + public Set<String> test3() + { + Set<String> temp = test3; + temp.add("Foo"); + return temp; + } + } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-11 04:20:36 UTC (rev 529) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-11 04:43:40 UTC (rev 530) @@ -178,6 +178,7 @@ case IN_METHOD: sawMethodOpcode(seen); + break; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-05-12 04:36:48
|
Revision: 532 Author: dbrosius Date: 2006-05-11 21:36:39 -0700 (Thu, 11 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=532&view=rev Log Message: ----------- fix false positive when a field is 'returned' from the first part of a trinary. 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-11 23:32:58 UTC (rev 531) +++ trunk/fb-contrib/samples/NMCS_Sample.java 2006-05-12 04:36:39 UTC (rev 532) @@ -18,6 +18,8 @@ private Set<String> test3 = new HashSet<String>(); + private List<String> test4 = new Vector<String>(); + public String test1() { StringBuffer sb = new StringBuffer(); @@ -46,4 +48,9 @@ return temp; } + public List<String> test4(boolean b) + { + return b ? test4 : new Vector<String>(); + } + } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-11 23:32:58 UTC (rev 531) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-12 04:36:39 UTC (rev 532) @@ -266,10 +266,18 @@ String fieldName = getNameConstantOperand(); collectionFields.remove(fieldName); break; + + case GOTO: + case GOTO_W: + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + FieldAnnotation fa = item.getField(); + if (fa != null) { + collectionFields.remove(fa.getFieldName()); + } + } + 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) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-19 05:48:06
|
Revision: 567 Author: dbrosius Date: 2006-06-18 22:47:54 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=567&view=rev Log Message: ----------- allow iterators Modified Paths: -------------- trunk/fb-contrib/samples/UTA_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java Modified: trunk/fb-contrib/samples/UTA_Sample.java =================================================================== --- trunk/fb-contrib/samples/UTA_Sample.java 2006-06-19 05:28:38 UTC (rev 566) +++ trunk/fb-contrib/samples/UTA_Sample.java 2006-06-19 05:47:54 UTC (rev 567) @@ -1,3 +1,4 @@ +import java.util.Iterator; import java.util.List; public class UTA_Sample @@ -20,4 +21,14 @@ return data; } + + public Long[] testList3(List<Long> l) + { + Iterator<Long> it = l.iterator(); + Long[] data = new Long[l.size()]; + for (int i = 0; i < l.size(); i++) + data[i] = it.next(); + + return data; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-06-19 05:28:38 UTC (rev 566) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-06-19 05:47:54 UTC (rev 567) @@ -116,6 +116,14 @@ sawAlias = true; } } + } else if ("keySet".equals(methodName) || "values".equals(methodName) || "iterator".equals(methodName) || "next".equals(methodName)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); + reg = isLocalCollection(itm); + if (reg >= 0) { + sawAlias = true; + } + } } } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) || ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-28 19:07:15
|
Revision: 573 Author: dbrosius Date: 2006-06-28 11:59:10 -0700 (Wed, 28 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=573&view=rev Log Message: ----------- If a java.lang.Object method is called on an instance of a jdbc class, that's ok - don't report Modified Paths: -------------- trunk/fb-contrib/samples/JVR_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java Modified: trunk/fb-contrib/samples/JVR_Sample.java =================================================================== --- trunk/fb-contrib/samples/JVR_Sample.java 2006-06-21 02:08:15 UTC (rev 572) +++ trunk/fb-contrib/samples/JVR_Sample.java 2006-06-28 18:59:10 UTC (rev 573) @@ -13,6 +13,12 @@ VendorBlob vb = (VendorBlob)rs.getBlob(1); return vb.convertBlobToString(); } + + public String falsePositive(ResultSet rs) throws SQLException + { + Blob vb = rs.getBlob(1); + return vb.getClass().getName(); + } } class VendorBlob implements Blob Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2006-06-21 02:08:15 UTC (rev 572) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2006-06-28 18:59:10 UTC (rev 573) @@ -98,7 +98,7 @@ if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { String clsName = getClassConstantOperand(); - if (!isJDBCClass(clsName)) { + if (!"java/lang/Object".equals(clsName) && !isJDBCClass(clsName)) { int parmCnt = Type.getArgumentTypes(getSigConstantOperand()).length; if (stack.getStackDepth() > parmCnt) { OpcodeStack.Item itm = stack.getStackItem(parmCnt); @@ -158,7 +158,7 @@ if (clsName.endsWith(";")) clsName = clsName.substring(1, clsName.length() - 1); clsName = clsName.replace('.', '/'); - + if (!clsName.startsWith("java/sql/") && !clsName.startsWith("javax/sql/")) return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 03:19:54
|
Revision: 589 Author: dbrosius Date: 2006-08-07 20:19:37 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=589&view=rev Log Message: ----------- start working on LEST detector Added Paths: ----------- trunk/fb-contrib/samples/LEST_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Added: trunk/fb-contrib/samples/LEST_Sample.java =================================================================== --- trunk/fb-contrib/samples/LEST_Sample.java (rev 0) +++ trunk/fb-contrib/samples/LEST_Sample.java 2006-08-08 03:19:37 UTC (rev 589) @@ -0,0 +1,20 @@ +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class LEST_Sample +{ + public Date testLest1(String input) + { + try + { + DateFormat df = new SimpleDateFormat("YYYY"); + return df.parse(input); + } + catch (ParseException pe) + { + throw new IllegalArgumentException(pe.getMessage()); + } + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 03:19:37 UTC (rev 589) @@ -0,0 +1,114 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 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.BitSet; + +import org.apache.bcel.Constants; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; +import org.apache.bcel.classfile.ExceptionTable; +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for methods that catch exceptions, and rethrow another exception without encapsulating + * the original exception within it. Doing this loses the stack history, and where the original + * problem occurred. This makes finding and fixing errors difficult. + */ +public class LostExceptionStackTrace extends BytecodeScanningDetector +{ + private BugReporter bugReporter; + private OpcodeStack stack; + + /** + * constructs a LEST detector given the reporter to report bugs on + + * @param bugReporter the sync of bug reports + */ + public LostExceptionStackTrace(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * implements the visitor to make sure the jdk is 1.4 or better + * + * @param classContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + int majorVersion = classContext.getJavaClass().getMajor(); + if (majorVersion >= Constants.MAJOR_1_4) { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } + } finally { + stack = null; + } + } + + /** + * looks for methods that contain a catch block and an ATHROW opcode + * + * @param code the context object of the current code block + * @param method the context object of the current method + * @return if the class throws exceptions + */ + public boolean prescreen(Code code, Method method) { + CodeException[] ce = code.getExceptionTable(); + if ((ce == null) || (ce.length == 0)) + return false; + + BitSet bytecodeSet = getClassContext().getBytecodeSet(method); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.ATHROW)); + } + + /** + * implements the visitor to filter out methods that don't throw exceptions + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + if (prescreen(obj, getMethod())) { + stack.resetForMethodEntry(this); + super.visitCode(obj); + } + } + + /** + * implements the visitor to find throwing alternative exceptions from a catch block, without + * forwarding along the original exception + */ + @Override + public void sawOpcode(int seen) { + try { + stack.mergeJumps(this); + + } + finally { + stack.sawOpcode(this, seen); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-08 05:06:48
|
Revision: 591 Author: dbrosius Date: 2006-08-07 22:06:38 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=591&view=rev Log Message: ----------- LEST is starting to work (with many false positives) Modified Paths: -------------- trunk/fb-contrib/samples/LEST_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/samples/LEST_Sample.java =================================================================== --- trunk/fb-contrib/samples/LEST_Sample.java 2006-08-08 03:59:39 UTC (rev 590) +++ trunk/fb-contrib/samples/LEST_Sample.java 2006-08-08 05:06:38 UTC (rev 591) @@ -17,4 +17,17 @@ throw new IllegalArgumentException(pe.getMessage()); } } + + public Date testLest2(String input) + { + try + { + DateFormat df = new SimpleDateFormat("YYYY"); + return df.parse(input); + } + catch (ParseException pe) + { + throw new IllegalArgumentException(pe.getMessage(), pe); + } + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 03:59:39 UTC (rev 590) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-08 05:06:38 UTC (rev 591) @@ -19,13 +19,20 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.BitSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; import org.apache.bcel.Constants; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.CodeException; -import org.apache.bcel.classfile.ExceptionTable; +import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + +import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; @@ -38,8 +45,19 @@ */ public class LostExceptionStackTrace extends BytecodeScanningDetector { + private static JavaClass exceptionClass; + static { + try { + exceptionClass = Repository.lookupClass("java/lang/Exception"); + } catch (ClassNotFoundException cnfe) { + exceptionClass = null; + } + } + private BugReporter bugReporter; private OpcodeStack stack; + private CodeException[] exceptions; + private Set<CatchInfo> catchInfos; /** * constructs a LEST detector given the reporter to report bugs on @@ -59,12 +77,15 @@ public void visitClassContext(ClassContext classContext) { try { int majorVersion = classContext.getJavaClass().getMajor(); - if (majorVersion >= Constants.MAJOR_1_4) { + if ((exceptionClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { stack = new OpcodeStack(); + catchInfos = new HashSet<CatchInfo>(); super.visitClassContext(classContext); } } finally { stack = null; + catchInfos = null; + exceptions = null; } } @@ -93,6 +114,7 @@ public void visitCode(Code obj) { if (prescreen(obj, getMethod())) { stack.resetForMethodEntry(this); + exceptions = obj.getExceptionTable(); super.visitCode(obj); } } @@ -103,12 +125,107 @@ */ @Override public void sawOpcode(int seen) { + boolean markAsValid = false; + try { stack.mergeJumps(this); + int pc = getPC(); + for (CodeException ex : exceptions) { + if (pc == ex.getEndPC()) { + if ((seen >= IRETURN) && (seen <= RETURN)) { + addCatchBlock(ex.getHandlerPC(), Integer.MAX_VALUE); + } else if ((seen == GOTO) || (seen == GOTO_W)) + addCatchBlock(ex.getHandlerPC(), this.getBranchTarget()); + return; + } + } + Iterator<CatchInfo> it = catchInfos.iterator(); + while (it.hasNext()) { + try { + CatchInfo catchInfo = it.next(); + if (pc == catchInfo.getStart()) { + if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + catchInfo.setReg(RegisterUtils.getAStoreReg(this, seen)); + break; + } + } else if (pc > catchInfo.getFinish()) { + it.remove(); + break; + } else if ((pc > catchInfo.getStart()) && (pc <= catchInfo.getFinish())) { + if ((seen == INVOKESPECIAL) && ("<init>".equals(getNameConstantOperand()))) { + String className = getClassConstantOperand(); + JavaClass exClass = Repository.lookupClass(className); + if (exClass.instanceOf(exceptionClass)) { + String sig = getSigConstantOperand(); + if ((sig.indexOf("Exception") >= 0) + || (sig.indexOf("Throwable") >= 0)) { + markAsValid = true; + break; + } + } + } else if (seen == ATHROW) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + if ((itm.getRegisterNumber() != catchInfo.getRegister()) + && (itm.getUserValue() == null)) { + bugReporter.reportBug(new BugInstance(this, "LEST_LOST_EXCEPTION_STACK_TRACE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + it.remove(); + break; + } + } + } + } + } catch (ClassNotFoundException cnfe) { + bugReporter.reportMissingClass(cnfe); + it.remove(); + } + } } finally { stack.sawOpcode(this, seen); + if (markAsValid) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + itm.setUserValue(Boolean.TRUE); + } + } } } + + private void addCatchBlock(int start, int finish) { + CatchInfo ci = new CatchInfo(start, finish); + catchInfos.add(ci); + } + + private static class CatchInfo { + private int catchStart; + private int catchFinish; + private int exReg; + + public CatchInfo(int start, int finish) { + catchStart = start; + catchFinish = finish; + exReg = -1; + } + + public void setReg(int reg) { + exReg = reg; + } + + public int getStart() { + return catchStart; + } + + public int getFinish() { + return catchFinish; + } + + public int getRegister() { + return exReg; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-12 01:15:35
|
Revision: 608 Author: dbrosius Date: 2006-08-11 18:15:27 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=608&view=rev Log Message: ----------- fix some false positives with LEST Modified Paths: -------------- trunk/fb-contrib/samples/LEST_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/samples/LEST_Sample.java =================================================================== --- trunk/fb-contrib/samples/LEST_Sample.java 2006-08-12 00:47:46 UTC (rev 607) +++ trunk/fb-contrib/samples/LEST_Sample.java 2006-08-12 01:15:27 UTC (rev 608) @@ -30,4 +30,32 @@ throw new IllegalArgumentException(pe.getMessage(), pe); } } + + public Date testLestFP1(String input) throws ParseException + { + try + { + DateFormat df = new SimpleDateFormat("YYYY"); + return df.parse(input); + } + catch (ParseException pe) + { + throw pe; + } + } + + public Date testLestFP2(String input) + { + try + { + DateFormat df = new SimpleDateFormat("YYYY"); + return df.parse(input); + } + catch (ParseException pe) + { + IllegalArgumentException iae = new IllegalArgumentException(pe.getMessage()); + iae.initCause(pe); + throw iae; + } + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-12 00:47:46 UTC (rev 607) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-08-12 01:15:27 UTC (rev 608) @@ -20,9 +20,11 @@ import java.util.ArrayList; import java.util.BitSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.bcel.Constants; @@ -32,6 +34,7 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -60,6 +63,7 @@ private OpcodeStack stack; private CodeException[] exceptions; private Set<CatchInfo> catchInfos; + private Map<Integer, Boolean> exReg; /** * constructs a LEST detector given the reporter to report bugs on @@ -82,12 +86,14 @@ if ((throwableClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { stack = new OpcodeStack(); catchInfos = new HashSet<CatchInfo>(); + exReg = new HashMap<Integer, Boolean>(); super.visitClassContext(classContext); } } finally { stack = null; catchInfos = null; exceptions = null; + exReg = null; } } @@ -121,6 +127,7 @@ stack.resetForMethodEntry(this); catchInfos.clear(); exceptions = collectExceptions(obj.getExceptionTable()); + exReg.clear(); super.visitCode(obj); } } @@ -168,7 +175,9 @@ CatchInfo catchInfo = it.next(); if (pc == catchInfo.getStart()) { if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { - catchInfo.setReg(RegisterUtils.getAStoreReg(this, seen)); + int reg = RegisterUtils.getAStoreReg(this, seen); + catchInfo.setReg(reg); + exReg.put(Integer14.valueOf(reg), Boolean.TRUE); break; } } else if (pc > catchInfo.getFinish()) { @@ -190,7 +199,13 @@ String className = getClassConstantOperand(); JavaClass exClass = Repository.lookupClass(className); if (exClass.instanceOf(throwableClass)) { - markAsValid = true; + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); + int reg = itm.getRegisterNumber(); + if (reg >= 0) + exReg.put(Integer14.valueOf(reg), Boolean.TRUE); + markAsValid = true; // Fixes javac generated code + } } } else if (seen == ATHROW) { if (stack.getStackDepth() > 0) { @@ -205,6 +220,15 @@ break; } } + } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + exReg.put(Integer14.valueOf(RegisterUtils.getAStoreReg(this, seen)), (Boolean)itm.getUserValue()); + } + } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { + Boolean valid = exReg.get(Integer14.valueOf(RegisterUtils.getALoadReg(this, seen))); + if (valid != null) + markAsValid = valid.booleanValue(); } } } catch (ClassNotFoundException cnfe) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-18 03:59:44
|
Revision: 619 Author: dbrosius Date: 2006-08-17 20:59:33 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=619&view=rev Log Message: ----------- Fix [ 1540989 ] UEC does not see EnumSet by checking real type, not static type Modified Paths: -------------- trunk/fb-contrib/samples/UEC_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java Modified: trunk/fb-contrib/samples/UEC_Sample.java =================================================================== --- trunk/fb-contrib/samples/UEC_Sample.java 2006-08-16 04:21:25 UTC (rev 618) +++ trunk/fb-contrib/samples/UEC_Sample.java 2006-08-18 03:59:33 UTC (rev 619) @@ -9,6 +9,7 @@ public class UEC_Sample { public enum Suite { Spades, Hearts, Clubs, Diamonds }; + public enum FalsePositive { A, B, C }; private Set<Suite> wildSuites = new HashSet<Suite>(); private EnumSet<Suite> eWildSuites = EnumSet.noneOf(Suite.class); @@ -40,4 +41,11 @@ return hand; } + + public void uecFP() + { + Set<FalsePositive> testSet = EnumSet.of(FalsePositive.A); + + testSet.add(FalsePositive.B); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-08-16 04:21:25 UTC (rev 618) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java 2006-08-18 03:59:33 UTC (rev 619) @@ -95,11 +95,11 @@ if (("java/util/Map".equals(clsName)) && ("put".equals(methodName)) && ("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;".equals(signature))) { - bug = isEnum(1) && alreadyReported(2); + bug = isEnum(1) && !isEnumCollection(1) && alreadyReported(2); } else if (("java/util/Set".equals(clsName)) && ("add".equals(methodName)) && ("(Ljava/lang/Object;)Z".equals(signature))) { - bug = isEnum(0) && alreadyReported(1); + bug = isEnum(0) && !isEnumCollection(1) && alreadyReported(1); } if (bug) { @@ -135,6 +135,22 @@ } /** + * returns whether the item at the stackpos location is an instance of an EnumSet or EnumMap + * + * @param stackPos the posotion on the opstack to check + * + * @return whether the class is an EnumSet or EnumMap + */ + private boolean isEnumCollection(int stackPos) { + if (stack.getStackDepth() <= stackPos) + return false; + + OpcodeStack.Item item = stack.getStackItem(stackPos); + String realClass = item.getSignature(); + return "Ljava/util/EnumSet;".equals(realClass) || "Ljava/util/EnumMap;".equals(realClass); + } + + /** * returns whether the collection has already been reported on * * @param stackPos the position on the opstack to check This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-05-21 10:45:31
|
Revision: 1020 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1020&view=rev Author: dbrosius Date: 2008-05-21 03:45:22 -0700 (Wed, 21 May 2008) Log Message: ----------- add fps Modified Paths: -------------- trunk/fb-contrib/samples/MRC_Sample.java trunk/fb-contrib/samples/SPP_Sample.java Modified: trunk/fb-contrib/samples/MRC_Sample.java =================================================================== --- trunk/fb-contrib/samples/MRC_Sample.java 2008-04-18 06:08:46 UTC (rev 1019) +++ trunk/fb-contrib/samples/MRC_Sample.java 2008-05-21 10:45:22 UTC (rev 1020) @@ -1,4 +1,7 @@ +import java.util.Iterator; +import java.util.List; + public class MRC_Sample { private int getValue() { @@ -50,4 +53,19 @@ { sb.append("Foo"); } + + private int getCount(List<String> l) + { + int count = 0; + Iterator<String> it = l.iterator(); + while(it.hasNext()) + { + if("Foo".equals(it.next())) + { + count += 1; + } + } + + return count; + } } Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2008-04-18 06:08:46 UTC (rev 1019) +++ trunk/fb-contrib/samples/SPP_Sample.java 2008-05-21 10:45:22 UTC (rev 1020) @@ -3,6 +3,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.StringTokenizer; public class SPP_Sample { @@ -164,4 +165,21 @@ else if (sb.toString().equals("")) System.out.println("Booya"); } + + public String cpNullOrZero(StringTokenizer tokenizer) + { + while (tokenizer.hasMoreTokens()) + { + String sField = tokenizer.nextToken(); + + if ((sField == null) || (sField.length() == 0)) + { + continue; + } + + return sField; + } + + return null; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |