Class ReflectionExecutor

java.lang.Object
proguard.evaluation.executor.ReflectionExecutor
All Implemented Interfaces:
Executor
Direct Known Subclasses:
StringReflectionExecutor

public abstract class ReflectionExecutor extends Object implements Executor
This Executor provides an implementation for Executor.getMethodResult(proguard.evaluation.executor.MethodExecutionInfo, proguard.evaluation.ValueCalculator) which tries to resolve the method at runtime and execute it using Java's reflection API java.lang.reflect.
  • Constructor Details

    • ReflectionExecutor

      public ReflectionExecutor()
  • Method Details

    • getMethodResult

      public MethodResult getMethodResult(MethodExecutionInfo methodExecutionInfo, ValueCalculator valueCalculator)
      Description copied from interface: Executor
      Calculate the result of a given method. This is the return value for a non-constructor method (null if it returns void) and the instantiated object for a constructor.
      Specified by:
      getMethodResult in interface Executor
      Parameters:
      methodExecutionInfo - Information about the called method.
      valueCalculator - a function mapping the result of a method invocation (can be an Object with the result if the executor calculates a real value or a Model) to the appropriate Value used by the analysis. Should also be used to create values of unknown value since the executor might be able to provide additional information on them even if the value itself is not known (e.g., on the identifier of the returned value).
      Returns:
      The result of the method call, including information on the returned value or values or arguments on which side effects happened during the method execution. If the executor is not able to provide any additional information for any reason the returned value should be MethodResult.invalidResult(), so that the caller can know that execution failed and just provide its best approximation of the result.
    • getInstanceOrCopyIfMutable

      protected abstract Optional<ReflectionExecutor.InstanceCopyResult> getInstanceOrCopyIfMutable(ReferenceValue instanceValue)
      Get an object which will act as the calling instance. If we know that executing the method does not modify the instance this can just be the same value. Otherwise, a copy should be returned in order to not change the reference whose state may be of interest at the end of an analysis.
      Parameters:
      instanceValue - The ReferenceValue of the instance.
      Returns:
      The new calling instance.
    • getDefaultInstanceHandler

      protected abstract ExecutorInstanceHandler getDefaultInstanceHandler()
      Provides a default instance handler used by the executor in case the reflective execution fails.

      The handler carries information on whether a method returns the same object as its instance.

      Returns:
      the default instance handler.