/**
   * Verifies the list of copied values against the subreport.
   *
   * @throws JRException
   */
  private void checkReturnValues() throws JRException {
    if (returnValues != null && returnValues.length > 0) {
      for (int i = 0; i < returnValues.length; i++) {
        JRSubreportReturnValue returnValue = returnValues[i];
        String subreportVariableName = returnValue.getSubreportVariable();
        JRVariable subrepVariable = subreportFiller.getVariable(subreportVariableName);
        if (subrepVariable == null) {
          throw new JRException("Subreport variable " + subreportVariableName + " not found.");
        }

        JRVariable variable = filler.getVariable(returnValue.getToVariable());
        if (returnValue.getCalculationValue() == CalculationEnum.COUNT
            || returnValue.getCalculationValue() == CalculationEnum.DISTINCT_COUNT) {
          if (!Number.class.isAssignableFrom(variable.getValueClass())) {
            throw new JRException(
                "Variable " + returnValue.getToVariable() + " must have a numeric type.");
          }
        } else if (!variable.getValueClass().isAssignableFrom(subrepVariable.getValueClass())
            && !(Number.class.isAssignableFrom(variable.getValueClass())
                && Number.class.isAssignableFrom(subrepVariable.getValueClass()))) {
          throw new JRException(
              "Variable "
                  + returnValue.getToVariable()
                  + " is not assignable from subreport variable "
                  + subreportVariableName);
        }
      }
    }
  }