Class ReflectiveAccessTracker

java.lang.Object
edu.umd.cs.findbugs.detect.ReflectiveAccessTracker

class ReflectiveAccessTracker extends Object
Tracks the fields accessed through reflection such as VarHandles, MethodHandles and AtomicFieldUpdaters.

Only one shape is recognized, and every condition below has to hold for a field to be tracked:

  • the accessor is created by Lookup.findVarHandle, Lookup.findGetter, Lookup.findSetter, their static counterparts Lookup.findStaticVarHandle, Lookup.findStaticGetter and Lookup.findStaticSetter, or newUpdater on one of the reference, integer and long AtomicFieldUpdater classes.
  • the accessor is stored into a static field by the instruction immediately following the creating call.
  • the accessor is invoked directly on the value loaded from that static field.
  • that static field is assigned at a single creation site (see the known limitation below).

Everything else is invisible here, so such a field keeps whatever UUF/URF/ UWF report the ordinary analysis produces for it. That includes accessors stored into an instance field, kept in a local variable, cached in an array or a map, returned from a factory method or never stored at all; accessors whose accessed class or field name is not a compile-time constant at the creation site; accessors obtained from Lookup.unreflect*, java.lang.reflect.Field or Unsafe; and invocations made on a derived accessor such as the result of MethodHandle.asType, bindTo or VarHandle.toMethodHandle.

Known limitation: if the same static field is assigned at several creation sites, for example in the branches of an if, every invocation is attributed to the first assignment only. The targets of the other assignments are then reported as if their accessors were never used.