Class StringConcatenation

All Implemented Interfaces:
Detector, Priorities, StatelessDetector, Cloneable, org.apache.bcel.classfile.Visitor

public class StringConcatenation extends OpcodeStackDetector implements StatelessDetector
Find occurrences of using the String "+" or "+=" operators within a loop. This is much less efficient than creating a dedicated StringBuffer object outside the loop, and then appending to it.
  • Field Details

    • DEBUG

      private static final boolean DEBUG
    • SEEN_NOTHING

      static final int SEEN_NOTHING
      See Also:
    • SEEN_NEW

      static final int SEEN_NEW
      See Also:
    • SEEN_APPEND1

      static final int SEEN_APPEND1
      See Also:
    • SEEN_APPEND2

      static final int SEEN_APPEND2
      See Also:
    • CONSTRUCTED_STRING_ON_STACK

      static final int CONSTRUCTED_STRING_ON_STACK
      See Also:
    • POSSIBLE_CASE

      static final int POSSIBLE_CASE
      See Also:
    • bugReporter

      private final BugReporter bugReporter
    • reportedThisMethod

      private boolean reportedThisMethod
    • stringSource

      private int stringSource
    • createPC

      private int createPC
    • state

      private int state
    • clobberedRegisters

      private Map<Integer,Integer> clobberedRegisters
  • Constructor Details

    • StringConcatenation

      public StringConcatenation(BugReporter bugReporter)
  • Method Details

    • visit

      public void visit(org.apache.bcel.classfile.Method obj)
      Overrides:
      visit in class BetterVisitor
    • reset

      private void reset()
    • storeIntoRegister

      private boolean storeIntoRegister(int seen, int reg)
    • getRegisterOnStack

      private int getRegisterOnStack()
    • getRegisterOnStack

      private int getRegisterOnStack(int idx)
    • sawOpcode

      public void sawOpcode(int seen)
      Description copied from class: OpcodeStackDetector

      By default, this method will not be called when stack is TOP. To change this behavior, override #beforeOpcode(int) and change to return true even if stack is TOP.

      see Using FindBugs for Research to learn lattice and what TOP means.

      Specified by:
      sawOpcode in class OpcodeStackDetector
      See Also: