Class LocalVariableInfo

java.lang.Object
org.apache.bcel.verifier.statics.LocalVariableInfo

public class LocalVariableInfo extends Object
A utility class holding the information about the name and the type of a local variable in a given slot (== index). This information often changes in course of byte code offsets.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    A contiguous, inclusive range of bytecode offsets sharing one variable name and one type.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The database of ranges, keyed by their start offset.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new LocalVariableInfo.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String name, int startPc, int length, Type type)
    Adds some information about this local variable (slot).
    getName(int offset)
    Returns the name of the local variable that uses this local variable slot at the given bytecode offset.
    getType(int offset)
    Returns the type of the local variable that uses this local variable slot at the given bytecode offset.
    lookup(int offset)
    Returns the range covering the given bytecode offset, or null if no range covers it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ranges

      The database of ranges, keyed by their start offset. Invariant: the stored ranges never overlap each other; additions overlapping an existing range with consistent information are coalesced into it, inconsistent ones are rejected. Storing ranges instead of one entry per offset keeps the work and memory proportional to the number of LocalVariableTable entries: the startPc and length fields are attacker-controlled in a malicious class file and would otherwise amplify each 10-byte table entry into up to 65,536 hashtable operations (CWE-407).
  • Constructor Details

    • LocalVariableInfo

      public LocalVariableInfo()
      Constructs a new LocalVariableInfo.
  • Method Details

    • add

      public void add(String name, int startPc, int length, Type type) throws LocalVariableInfoInconsistentException
      Adds some information about this local variable (slot).
      Parameters:
      name - variable name.
      startPc - Range in which the variable is valid.
      length - length of ...
      type - variable type.
      Throws:
      LocalVariableInfoInconsistentException - Thrown if the new information conflicts with already gathered information.
    • getName

      public String getName(int offset)
      Returns the name of the local variable that uses this local variable slot at the given bytecode offset. Care for legal bytecode offsets yourself, otherwise the return value might be wrong. May return 'null' if nothing is known about the type of this local variable slot at the given bytecode offset.
      Parameters:
      offset - bytecode offset.
      Returns:
      The name of the local variable that uses this local variable slot at the given bytecode offset.
    • getType

      public Type getType(int offset)
      Returns the type of the local variable that uses this local variable slot at the given bytecode offset. Care for legal bytecode offsets yourself, otherwise the return value might be wrong. May return 'null' if nothing is known about the type of this local variable slot at the given bytecode offset.
      Parameters:
      offset - bytecode offset.
      Returns:
      The type of the local variable that uses this local variable slot at the given bytecode offset.
    • lookup

      private LocalVariableInfo.Range lookup(int offset)
      Returns the range covering the given bytecode offset, or null if no range covers it. Since the stored ranges never overlap, only the range with the greatest start offset at or below the given offset can cover it.