Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [397] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-04 15:22:38
|
Revision: 397 Author: dbrosius Date: 2006-04-04 08:22:32 -0700 (Tue, 04 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=397&view=rev Log Message: ----------- Fix for bug: [ 1462290 ] FCBL: infinite recursion? (stack overflow) Convert FCBL's algorithm from recursive to iterative, to avoid stack overflow problems. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-04 14:38:03 UTC (rev 396) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-04 15:22:32 UTC (rev 397) @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.Map; import java.util.Set; @@ -184,65 +185,127 @@ * @param uncheckedFields the list of fields to look for */ private void checkBlock(BasicBlock bb, Set<String> uncheckedFields) { - visitedBlocks.set(bb.getId()); - InstructionIterator ii = bb.instructionIterator(); - while (ii.hasNext()) { - InstructionHandle ih = ii.next(); - Instruction ins = ih.getInstruction(); - if (ins instanceof FieldInstruction) { - FieldInstruction fi = (FieldInstruction) ins; - String fieldName = fi.getFieldName(cpg); - uncheckedFields.remove(fieldName); - - if (ins instanceof GETFIELD) { - localizableFields.remove(fieldName); - if (localizableFields.size() == 0) - return; - } else { - FieldInfo finfo = localizableFields.get(fieldName); - if (finfo != null) - finfo.setSrcLineAnnotation(SourceLineAnnotation.fromVisitedInstruction(clsContext, this, ih.getPosition())); - } - if (uncheckedFields.size() == 0) - return; - } - } + LinkedList<BlockState> toBeProcessed = new LinkedList<BlockState>(); + toBeProcessed.add(new BlockState(bb, uncheckedFields)); - if (uncheckedFields.size() > 0) { - Iterator<Edge> oei = cfg.outgoingEdgeIterator(bb); - while (oei.hasNext()) { - Edge e = oei.next(); - BasicBlock cb = e.getTarget(); - if (!visitedBlocks.get(cb.getId())) { - Set<String> subCheckedFields = new HashSet<String>(uncheckedFields); - checkBlock(cb, subCheckedFields); - if (localizableFields.size() == 0) + while (toBeProcessed.size() > 0) { + if (localizableFields.size() == 0) + return; + BlockState bState = toBeProcessed.removeFirst(); + bb = bState.getBasicBlock(); + uncheckedFields = bState.getUncheckedFields(); + + visitedBlocks.set(bb.getId()); + InstructionIterator ii = bb.instructionIterator(); + while (ii.hasNext()) { + InstructionHandle ih = ii.next(); + Instruction ins = ih.getInstruction(); + if (ins instanceof FieldInstruction) { + FieldInstruction fi = (FieldInstruction) ins; + String fieldName = fi.getFieldName(cpg); + uncheckedFields.remove(fieldName); + + if (ins instanceof GETFIELD) { + localizableFields.remove(fieldName); + if (localizableFields.size() == 0) + return; + } else { + FieldInfo finfo = localizableFields.get(fieldName); + if (finfo != null) + finfo.setSrcLineAnnotation(SourceLineAnnotation.fromVisitedInstruction(clsContext, this, ih.getPosition())); + } + if (uncheckedFields.size() == 0) return; + } + } + + if (uncheckedFields.size() > 0) { + Iterator<Edge> oei = cfg.outgoingEdgeIterator(bb); + while (oei.hasNext()) { + Edge e = oei.next(); + BasicBlock cb = e.getTarget(); + if (!visitedBlocks.get(cb.getId())) { + toBeProcessed.addLast(new BlockState(cb, uncheckedFields)); + } } } } } + /** + * holds information about a field and it's first usage + */ private static class FieldInfo { private FieldAnnotation fieldAnnotation; private SourceLineAnnotation srcLineAnnotation; + /** + * creates a FieldInfo from an annotation, and assumes no source line information + * @param fa the field annotation for this field + */ public FieldInfo(FieldAnnotation fa) { fieldAnnotation = fa; srcLineAnnotation = null; } + /** + * set the source line annotation of first use for this field + * @param sla the source line annotation + */ public void setSrcLineAnnotation(SourceLineAnnotation sla) { if (srcLineAnnotation == null) srcLineAnnotation = sla; } + /** + * get the field annotation for this field + * @return the field annotation + */ public FieldAnnotation getFieldAnnotation() { return fieldAnnotation; } + /** + * get the source line annotation for the first use of this field + * @return the source line annotation + */ public SourceLineAnnotation getSrcLineAnnotation() { return srcLineAnnotation; } } + + /** + * holds the parse state of the current basic block, and what fields are left to be checked + */ + private static class BlockState { + private BasicBlock basicBlock; + private Set<String> uncheckedFields; + + /** + * creates a BlockState consisting of the next basic block to parse, + * and what fields are to be checked + * @param bb the basic block to parse + * @param fields the fields to look for first use + */ + public BlockState(BasicBlock bb, Set<String> fields) { + basicBlock = bb; + uncheckedFields = new HashSet<String>(fields); + } + + /** + * get the basic block to parse + * @return the basic block + */ + public BasicBlock getBasicBlock() { + return basicBlock; + } + + /** + * get the unchecked fields to look for + * @return the unchecked fields + */ + public Set<String> getUncheckedFields() { + return uncheckedFields; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-04 21:31:46
|
Revision: 398 Author: dbrosius Date: 2006-04-04 14:31:41 -0700 (Tue, 04 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=398&view=rev Log Message: ----------- remove unused Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-04 15:22:32 UTC (rev 397) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-04 21:31:41 UTC (rev 398) @@ -93,7 +93,6 @@ localizableFields.clear(); clsContext = classContext; JavaClass cls = classContext.getJavaClass(); - boolean clsIsFinal = cls.isFinal(); Field[] fields = cls.getFields(); for (Field f : fields) { if ((!f.isStatic() && f.getName().indexOf("$") < 0) && f.isPrivate()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-04 21:36:20
|
Revision: 399 Author: dbrosius Date: 2006-04-04 14:36:11 -0700 (Tue, 04 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=399&view=rev Log Message: ----------- add finals Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-04 21:31:41 UTC (rev 398) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-04 21:36:11 UTC (rev 399) @@ -242,7 +242,7 @@ * creates a FieldInfo from an annotation, and assumes no source line information * @param fa the field annotation for this field */ - public FieldInfo(FieldAnnotation fa) { + public FieldInfo(final FieldAnnotation fa) { fieldAnnotation = fa; srcLineAnnotation = null; } @@ -251,7 +251,7 @@ * set the source line annotation of first use for this field * @param sla the source line annotation */ - public void setSrcLineAnnotation(SourceLineAnnotation sla) { + public void setSrcLineAnnotation(final SourceLineAnnotation sla) { if (srcLineAnnotation == null) srcLineAnnotation = sla; } @@ -286,7 +286,7 @@ * @param bb the basic block to parse * @param fields the fields to look for first use */ - public BlockState(BasicBlock bb, Set<String> fields) { + public BlockState(final BasicBlock bb, final Set<String> fields) { basicBlock = bb; uncheckedFields = new HashSet<String>(fields); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-09 23:17:57
|
Revision: 435 Author: dbrosius Date: 2006-04-09 16:17:52 -0700 (Sun, 09 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=435&view=rev Log Message: ----------- prescreen for PUTFIELD and GETFIELD Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-09 23:13:10 UTC (rev 434) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-09 23:17:52 UTC (rev 435) @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Set; +import org.apache.bcel.Constants; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.JavaClass; @@ -37,6 +38,8 @@ import org.apache.bcel.generic.Instruction; import org.apache.bcel.generic.InstructionHandle; +import com.mebigfatguy.fbcontrib.utils.VersionTransition; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -143,6 +146,17 @@ } /** + * looks for methods that contain a GETFIELD or PUTFIELD opcodes + * + * @param method the context object of the current method + * @return if the class uses synchronization + */ + public boolean prescreen(Method method) { + BitSet bytecodeSet = VersionTransition.getBytecodeSet(getClassContext(), method); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.PUTFIELD) || bytecodeSet.get(Constants.GETFIELD)); + } + + /** * implements the visitor to pass through constructors and static initializers to the * byte code scanning code. These methods are not reported, but are used to build * SourceLineAnnotations for fields, if accessed. @@ -151,12 +165,14 @@ */ @Override public void visitCode(Code obj) { - String methodName = getMethodName(); - if ("<clinit".equals(methodName) || "<init>".equals(methodName)) - super.visitCode(obj); + Method m = getMethod(); + if (prescreen(m)) { + String methodName = m.getName(); + if ("<clinit".equals(methodName) || "<init>".equals(methodName)) + super.visitCode(obj); + } } - /** * implements the visitor to add SourceLineAnnotations for fields in constructors and static * initializers. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-15 00:34:55
|
Revision: 444 Author: dbrosius Date: 2006-04-14 17:34:50 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=444&view=rev Log Message: ----------- add copyright Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-15 00:34:07 UTC (rev 443) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-15 00:34:50 UTC (rev 444) @@ -1,7 +1,6 @@ /* - * FindBugs - Find bugs in Java programs - * Copyright (C) 2005 Dave Brosius <dbr...@us...> - * Copyright (C) 2005 University of Maryland + * 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-22 13:18:13
|
Revision: 496 Author: dbrosius Date: 2006-04-22 06:18:00 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=496&view=rev Log Message: ----------- fix false positive due to incomplete changeover to iterative Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-19 01:07:38 UTC (rev 495) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-22 13:18:00 UTC (rev 496) @@ -204,7 +204,7 @@ visitedBlocks.set(bb.getId()); InstructionIterator ii = bb.instructionIterator(); - while (ii.hasNext()) { + while ((uncheckedFields.size() > 0) && ii.hasNext()) { InstructionHandle ih = ii.next(); Instruction ins = ih.getInstruction(); if (ins instanceof FieldInstruction) { @@ -221,8 +221,6 @@ if (finfo != null) finfo.setSrcLineAnnotation(SourceLineAnnotation.fromVisitedInstruction(clsContext, this, ih.getPosition())); } - if (uncheckedFields.size() == 0) - return; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-22 19:20:17
|
Revision: 497 Author: dbrosius Date: 2006-04-22 12:20:11 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=497&view=rev Log Message: ----------- more explicit exception catching Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-22 13:18:00 UTC (rev 496) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-22 19:20:11 UTC (rev 497) @@ -44,6 +44,7 @@ import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.BasicBlock; import edu.umd.cs.findbugs.ba.CFG; +import edu.umd.cs.findbugs.ba.CFGBuilderException; import edu.umd.cs.findbugs.ba.ClassContext; import edu.umd.cs.findbugs.ba.Edge; import edu.umd.cs.findbugs.ba.BasicBlock.InstructionIterator; @@ -129,7 +130,7 @@ visitedBlocks.clear(); checkBlock(bb, uncheckedFields); } - catch (Exception e) { + catch (CFGBuilderException cbe) { localizableFields.clear(); } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |