CPD Results

The following document contains the results of PMD's CPD 5.0.2.

Duplications

File Line
de\smartics\exceptions\i18n\AbstractMessageException.java 133
de\smartics\exceptions\i18n\AbstractMessageRuntimeException.java 134
  protected AbstractMessageException(final MessageBean messageBean)
  {
    super(messageBean.getCause(), messageBean.getCode());
    this.messageBean = messageBean;
  }

  // ****************************** Inner Classes *****************************

  // ********************************* Methods ********************************

  // --- init -----------------------------------------------------------------

  // --- get&set --------------------------------------------------------------

  /**
   * Returns the message information for the exception.
   * <p>
   * Allowed to be overridden to return covariant.
   * </p>
   *
   * @return the message information for the exception.
   */
  public MessageBean getMessageBean()
  {
    return messageBean;
  }

  // --- business -------------------------------------------------------------

  // ... get message ..........................................................

  /**
   * {@inheritDoc}
   * <p>
   * Returns the localized message for the default locale.
   * </p>
   */
  @Override
  public final String getMessage()
  {
    return getLocalizedMessage();
  }

  /**
   * Calls
   * {@link de.smartics.exceptions.i18n.AbstractMessageException#getMessage(java.util.Locale, de.smartics.exceptions.i18n.message.MessageType)}
   * with argument list ({@link Locale#getDefault()}, &lt;messageType&gt;).
   *
   * @param messageType the type of message to fetch.
   * @return the message for the given type.
   * @see de.smartics.exceptions.i18n.AbstractMessageException#getMessage(java.util.Locale,
   *      de.smartics.exceptions.i18n.message.MessageType)
   */
  public final String getMessage(final MessageType messageType)
  {
    return getMessage(Locale.getDefault(), messageType);
  }

  @Override
  public final String getMessage(final Locale locale,
      final MessageType messageType)
  {
    return getLocalizedMessage(messageBean.getLocalizedInfo().getResourceKey(),
        locale, messageType, null); // , null);
  }

  // ... throwable standard message

  /**
   * Returns the localized message for the given locale.
   * <p>
   * Calls {@link #getLocalizedMessage(java.util.Locale)} with argument list (
   * {@link Locale#getDefault()}).
   * </p>
   *
   * @return returns the localized message of this exception.
   * @see de.smartics.exceptions.i18n.AbstractMessageException#getLocalizedMessage(java.util.Locale)
   */
  @Override
  public final String getLocalizedMessage()
  {
    return getLocalizedMessage(Locale.getDefault());
  }

  /**
   * Returns the localized message for the given locale.
   * <p>
   * Calls {@link #getLocalizedMessage(java.util.Locale,ClassLoader)} with
   * argument list (&lt;locale&gt;, <code>null</code>).
   * </p>
   *
   * @param locale locale the locale for which the message is requested.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(java.util.Locale, ClassLoader)
   */
  public final String getLocalizedMessage(final Locale locale)
  {
    return getLocalizedMessage(locale, getClassLoader()); // , null);
  }

  /**
   * Returns the localized message for the given locale.
   * <p>
   * Calls
   * {@link #getLocalizedMessage(String,java.util.Locale,de.smartics.exceptions.i18n.message.MessageType,java.lang.ClassLoader)}
   * with argument list (<code>null</code>, &lt;locale&gt;, MessageType.SUMMARY,
   * &lt;loader&gt;).
   *
   * @param locale locale the locale for which the message is requested.
   * @param loader loader the loader to read the message bundle.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(String,java.util.Locale,de.smartics.exceptions.i18n.message.MessageType,java.lang.ClassLoader)
   */
  public final String getLocalizedMessage(final Locale locale,
      final ClassLoader loader)
  {
    return messageBean.getLocalizedInfo().getLocalizedMessage(getBean(), locale,
        loader);
  }

  /**
   * Returns the localized message for the given locale.
   *
   * @param keyPrefix the prefix of the key to load from the bundle.
   * @param locale the locale for which the message is requested.
   * @param messageType the type of message to localize.
   * @param loader the loader to read the message bundle.
   * @return returns the localized message of this exception.
   */
  public final String getLocalizedMessage(final String keyPrefix,
      final Locale locale, final MessageType messageType,
      final ClassLoader loader)
  {
    final String message =
        messageBean.getLocalizedInfo().getLocalizedMessage(getBean(), keyPrefix,
            locale, messageType, loader);
    return message;
  }

  // ... throwable standard message as text

  /**
   * Returns the localized message for the given locale as formatted multi-line
   * text.
   *
   * @return returns the localized message of this exception.
   * @see de.smartics.exceptions.i18n.AbstractMessageException#getLocalizedMessage(java.util.Locale)
   */
  public final String getLocalizedTextMessage()
  {
    return getLocalizedTextMessage(Locale.getDefault());
  }

  /**
   * Returns the localized message for the given locale as formatted multi-line
   * text.
   *
   * @param locale locale the locale for which the message is requested.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(java.util.Locale, ClassLoader)
   */
  public final String getLocalizedTextMessage(final Locale locale)
  {
    return getLocalizedTextMessage(locale, getClassLoader());
  }

  /**
   * Returns the localized message for the given locale as formatted multi-line
   * text.
   *
   * @param locale locale the locale for which the message is requested.
   * @param loader loader the loader to read the message bundle.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(String,java.util.Locale,de.smartics.exceptions.i18n.message.MessageType,java.lang.ClassLoader)
   */
  public final String getLocalizedTextMessage(final Locale locale,
      final ClassLoader loader)
  {
    final String message =
        messageBean.getLocalizedInfo().getLocalizedTextMessage(getBean(), locale,
            loader);
    return message;
  }

  private Object getBean()
  {
    return messageBean.getClass() != WrapperMessageBean.class ? messageBean
        : this;
  }

  @Override
  public final String getMessages()
  {
    return getMessages(Locale.getDefault());
  }

  @Override
  public final String getMessages(final Locale locale)
  {
    final StringBuilder buffer = new StringBuilder();
    for (MessageType type : MessageType.values())
    {
      buffer.append(type.name()).append('=').append(getMessage(locale, type))
          .append('\n');
    }
    return StringUtils.chop(buffer.toString());
  }

  @Override
  public final Messages createMessages()
  {
    return createMessages(Locale.getDefault());
  }

  @Override
  public final Messages createMessages(final Locale locale)
  {
    final Messages.Builder builder = new Messages.Builder();
    final String keyPrefix = getCode().getCode();
    for (MessageType type : MessageType.values())
    {
      builder.put(
          type,
          messageBean.getLocalizedInfo().createLocalizedMessage(getBean(),
              keyPrefix, locale, type, null));
    }

    return builder.build();
  }

  @Override
  public final CauseTrailMessages getCauseTrail()
  {
    return getCauseTrail(Locale.getDefault());
  }

  @Override
  public final CauseTrailMessages getCauseTrail(final Locale locale)
  {
    return messageBean.getCauseTrail(locale);
  }

  // --- object basics --------------------------------------------------------

  /**
   * Returns the string representation of the exception.
   * <p>
   * May be overridden by subclasses in an application (not a library) to change
   * the string representation. Usually an implementation of
   * {@code I18nCodeMessageFormatter} should be set to the
   * {@link de.smartics.exceptions.core.ExceptionContext}.
   * </p>
   *
   * @return the string representation of the object.
   */
  @Override
  public String toString()
  {
    final I18nCodeMessageFormatter formatter =
        I18nExceptionContextManager.getFormatter(getClassLoader());
    final String string = formatter.format(this, getBean());
    return string;
  }
}
File Line
de\smartics\exceptions\i18n\message\DefaultMessageComposer.java 620
de\smartics\exceptions\i18n\message\IcuMessageComposer.java 352
  }

  /**
   * Returns the value returned by calling the getter method with the given
   * name.
   *
   * @param bean the instance whose method is invoked.
   * @param propertyName the name of the property to get the value for.
   * @param methodName the name of the method to invoke. It is expected that the
   *          method requires no arguments and returns a value (is a getter).
   * @return the value returned by calling the method.
   * @throws MethodAccessConfigurationException if there is a problem using the
   *           method to access the requested method.
   */
  private static Object getValue(final Object bean, final String propertyName,
      final String methodName) throws MethodAccessConfigurationException
  {
    try
    {
      final Method method = bean.getClass().getMethod(methodName, new Class[0]);
      final Object value = method.invoke(bean, new Object[0]);
      return value;
    }
    catch (final SecurityException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_SECURITY, propertyName,
          bean.getClass(), methodName);
    }
    catch (final NoSuchMethodException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_MISSING_GETTER,
          propertyName, bean.getClass(), methodName);
    }
    catch (final IllegalArgumentException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_NOARG, propertyName,
          bean.getClass(), methodName);
    }
    catch (final IllegalAccessException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_MISSING_GETTER,
          propertyName, bean.getClass(), methodName);
    }
    catch (final InvocationTargetException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_RUNTIME_ACCESS,
          propertyName, bean.getClass(), methodName);
    }
  }

  /**
   * Returns the property value. The getter method derived from the property
   * name is called to access the value.
   *
   * @param bean the instance whose property value is requested.
   * @param propertyName the name of the property.
   * @return the value of the property.
   * @throws PropertyAccessConfigurationException if there is a problem using
   *           the method to access the requested property.
   */
  private static Object getProperty(final Object bean, final String propertyName)
File Line
de\smartics\exceptions\i18n\message\DefaultMessageComposer.java 487
de\smartics\exceptions\i18n\message\IcuMessageComposer.java 309
  private Object evaluateOgnl(final Object bean, final String fieldName,
      final Object value, final String ognlPath)
    throws PropertyAccessConfigurationException
  {
    try
    {
      final OgnlExpression expression = new OgnlExpression(ognlPath);
      final OgnlContext context = new OgnlContext();
      return expression.getValue(context, value);
    }
    catch (final OgnlException e)
    {
      throw new PropertyAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_OGNL_SYNTAX_ERROR,
          fieldName, bean.getClass());
    }
  }

  /**
   * Returns the value of the given field by either calling the getter method
   * specified in the annotation {@link PropertyInfo} to the given field, by
   * accessing the field directly (if accessible) or by deriving the getter
   * method's name from the name of the property.
   *
   * @param bean the instance whose value is requested.
   * @param field the field the value is requested.
   * @return the value of the field.
   * @throws ConfigurationException if there is a problem using the method to
   *           access the requested method.
   */
  private static Object getValue(final Object bean, final Field field)
    throws ConfigurationException
  {
    final PropertyInfo propertyInfo = field.getAnnotation(PropertyInfo.class);
    final Object value;
    if (propertyInfo != null && !"".equals(propertyInfo.getter()))
    {
      final String getter = propertyInfo.getter();
      value = getValue(bean, field.getName(), getter);
    }
    else
    {
      final boolean accessible = field.isAccessible();
      try
      {
        field.setAccessible(true);
        value = getFieldValue(bean, field);
      }
      finally
      {
        field.setAccessible(accessible);
      }

      // if (field.isAccessible())
      // {
      // }
      // else
      // {
      // final String fieldName = field.getName();
      // value = getProperty(bean, fieldName);
      // }
    }

    return value;
  }

  private static Object getValue(final Object bean, final Method method)
File Line
de\smartics\exceptions\i18n\AbstractLocalizedException.java 401
de\smartics\exceptions\i18n\AbstractLocalizedRuntimeException.java 325
          .append('\n');
    }
    return StringUtils.chop(buffer.toString());
  }

  @Override
  public final Messages createMessages()
  {
    return createMessages(Locale.getDefault());
  }

  @Override
  public final Messages createMessages(final Locale locale)
  {
    final Messages.Builder builder = new Messages.Builder();
    final String keyPrefix = getCode().getCode();
    for (MessageType type : MessageType.values())
    {
      builder.put(type, localizedInfo.createLocalizedMessage(this, keyPrefix,
          locale, type, null));
    }

    return builder.build();
  }

  @Override
  public final CauseTrailMessages getCauseTrail()
  {
    return getCauseTrail(Locale.getDefault());
  }

  @Override
  public final CauseTrailMessages getCauseTrail(final Locale locale)
  {
    return localizedInfo.getCauseTrail(locale);
  }

  // --- object basics --------------------------------------------------------

  /**
   * Returns the string representation of the exception.
   * <p>
   * May be overridden by subclasses in an application (not a library) to change
   * the string representation. Usually an implementation of
   * {@code I18nCodeMessageFormatter} should be set to the
   * {@link de.smartics.exceptions.core.ExceptionContext}.
   * </p>
   *
   * @return the string representation of the object.
   */
  @Override
  public String toString()
  {
    final I18nCodeMessageFormatter formatter =
        I18nExceptionContextManager.getFormatter(getClassLoader());
    final String string = formatter.format(this);
    return string;
  }
}
File Line
de\smartics\exceptions\i18n\AbstractLocalizedException.java 220
de\smartics\exceptions\i18n\AbstractMessageBean.java 217
  public final String getLocalizedMessage()
  {
    return getLocalizedMessage(Locale.getDefault());
  }

  /**
   * Returns the localized message for the given locale.
   * <p>
   * Calls {@link #getLocalizedMessage(java.util.Locale,ClassLoader)} with
   * argument list (&lt;locale&gt;, <code>null</code>).
   * </p>
   *
   * @param locale locale the locale for which the message is requested.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(java.util.Locale, ClassLoader)
   */
  public final String getLocalizedMessage(final Locale locale)
  {
    return getLocalizedMessage(locale, getClassLoader()); // , null);
  }

  /**
   * Returns the localized message for the given locale.
   * <p>
   * Calls
   * {@link #getLocalizedMessage(String,java.util.Locale,de.smartics.exceptions.i18n.message.MessageType,java.lang.ClassLoader)}
   * with argument list (<code>null</code>, &lt;locale&gt;, MessageType.SUMMARY,
   * &lt;loader&gt;).
   *
   * @param locale locale the locale for which the message is requested.
   * @param loader loader the loader to read the message bundle.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(String,java.util.Locale,de.smartics.exceptions.i18n.message.MessageType,java.lang.ClassLoader)
   */
  public final String getLocalizedMessage(final Locale locale,
      final ClassLoader loader)
  {
    return localizedInfo.getLocalizedMessage(this, locale, loader);
  }

  // /**
  // * Returns the localized message for the given locale.
  // *
  // * @param locale the locale for which the message is requested.
  // * @param control the controller to load the resource bundle.
  // * @return returns the localized message of this exception.
  // * @todo Should we really provide these methods with class loader and
  // control?
  // * What is the user scenario for this?
  // */
  // public String getLocalizedMessage(
  // final Locale locale,
  // final ResourceBundle.Control control)
  // {
  // return getLocalizedMessage(locale, null, control);
  // }

  // /**
  // * Returns the localized message for the given locale.
  // *
  // * @param locale the locale for which the message is requested.
  // * @param loader the loader to read the message bundle.
  // * @param control the controller to load the resource bundle.
  // * @return returns the localized message of this exception.
  // * @todo Should we really provide these methods with class loader and
  // control?
  // * What is the user scenario for this?
  // */
  // public String getLocalizedMessage(
  // final Locale locale,
  // final ClassLoader loader,
  // final ResourceBundle.Control control)
  // {
  // final String message = messageBean.getLocalizedMessage(this, locale,
  // loader, control);
  // return message;
  // }

  // ... fetcher for all messages

  // /**
  // * Returns the localized message for the given locale.
  // *
  // * @param keyPrefix the prefix of the key to load from the bundle.
  // * @param locale the locale for which the message is requested.
  // * @param messageType the type of message to localize.
  // * @param loader the loader to read the message bundle.
  // * @param control the controller to load the resource bundle.
  // * @return returns the localized message of this exception.
  // * @todo Should we really provide these methods with class loader and
  // control?
  // * What is the user scenario for this?
  // */
  // public String getLocalizedMessage(
  // final String keyPrefix,
  // final Locale locale,
  // final MessageType messageType,
  // final ClassLoader loader,
  // final ResourceBundle.Control control)
  // {
  // final String message = messageBean.getLocalizedMessage(this, keyPrefix,
  // locale, messageType, loader, control);
  // return message;
  // }

  /**
   * Returns the localized message for the given locale.
   *
   * @param keyPrefix the prefix of the key to load from the bundle.
   * @param locale the locale for which the message is requested.
   * @param messageType the type of message to localize.
   * @param loader the loader to read the message bundle.
   * @return returns the localized message of this exception.
   */
  public final String getLocalizedMessage(final String keyPrefix,
      final Locale locale, final MessageType messageType,
      final ClassLoader loader)
  {
    final String message =
        localizedInfo.getLocalizedMessage(this, keyPrefix, locale, messageType,
            loader);
    return message;
  }

  // ... throwable standard message as text

  /**
   * Returns the localized message for the given locale as formatted multi-line
   * text.
   *
   * @return returns the localized message of this exception.
   * @see de.smartics.exceptions.i18n.AbstractLocalizedException#getLocalizedMessage(java.util.Locale)
   */
  public final String getLocalizedTextMessage()
  {
    return getLocalizedTextMessage(Locale.getDefault());
  }

  /**
   * Returns the localized message for the given locale as formatted multi-line
   * text.
   *
   * @param locale locale the locale for which the message is requested.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(java.util.Locale, ClassLoader)
   */
  public final String getLocalizedTextMessage(final Locale locale)
  {
    return getLocalizedTextMessage(locale, getClassLoader());
  }

  /**
   * Returns the localized message for the given locale as formatted multi-line
   * text.
   *
   * @param locale locale the locale for which the message is requested.
   * @param loader loader the loader to read the message bundle.
   * @return returns the localized message of this exception.
   * @see #getLocalizedMessage(String,java.util.Locale,de.smartics.exceptions.i18n.message.MessageType,java.lang.ClassLoader)
   */
  public final String getLocalizedTextMessage(final Locale locale,
      final ClassLoader loader)
  {
    final String message =
        localizedInfo.getLocalizedTextMessage(this, locale, loader);
    return message;
  }
File Line
de\smartics\exceptions\i18n\AbstractLocalizedException.java 386
de\smartics\exceptions\i18n\AbstractMessageException.java 321
de\smartics\exceptions\i18n\AbstractMessageRuntimeException.java 322
  }

  @Override
  public final String getMessages()
  {
    return getMessages(Locale.getDefault());
  }

  @Override
  public final String getMessages(final Locale locale)
  {
    final StringBuilder buffer = new StringBuilder();
    for (MessageType type : MessageType.values())
    {
      buffer.append(type.name()).append('=').append(getMessage(locale, type))
          .append('\n');
    }
    return StringUtils.chop(buffer.toString());
  }

  @Override
  public final Messages createMessages()
  {
    return createMessages(Locale.getDefault());
  }

  @Override
  public final Messages createMessages(final Locale locale)
  {
    final Messages.Builder builder = new Messages.Builder();
    final String keyPrefix = getCode().getCode();
    for (MessageType type : MessageType.values())
    {
      builder.put(type, localizedInfo.createLocalizedMessage(this, keyPrefix,
File Line
de\smartics\exceptions\i18n\message\DefaultMessageComposer.java 559
de\smartics\exceptions\i18n\message\IcuMessageComposer.java 409
      return value;
    }
    catch (final SecurityException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_SECURITY,
          calcPropertyName(method.getName()), bean.getClass(), method.getName());
    }
    catch (final IllegalArgumentException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_NOARG,
          calcPropertyName(method.getName()), bean.getClass(), method.getName());
    }
    catch (final IllegalAccessException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_MISSING_GETTER,
          calcPropertyName(method.getName()), bean.getClass(), method.getName());
    }
    catch (final InvocationTargetException e)
    {
      throw new MethodAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_RUNTIME_ACCESS,
          calcPropertyName(method.getName()), bean.getClass(), method.getName());
    }
  }

  /**
   * Returns the value of the given field.
   * <p>
   * The method assumes the the field is accessible. If not an configuration
   * exception is thrown.
   *
   * @param bean the instance whose field value is requested.
   * @param field the field whose value is requested.
   * @return the requested value fetched from the field.
   */
  private static Object getFieldValue(final Object bean, final Field field)
File Line
de\smartics\exceptions\i18n\message\DefaultMessageComposer.java 672
de\smartics\exceptions\i18n\message\IcuMessageComposer.java 241
    }
  }

  /**
   * Returns the property value. The getter method derived from the property
   * name is called to access the value.
   *
   * @param bean the instance whose property value is requested.
   * @param propertyName the name of the property.
   * @return the value of the property.
   * @throws PropertyAccessConfigurationException if there is a problem using
   *           the method to access the requested property.
   */
  private static Object getProperty(final Object bean, final String propertyName)
    throws PropertyAccessConfigurationException
  {
    try
    {
      // final Object value = PropertyUtils.getProperty(instance, propertyName);
      final String methodName = "get" + Helper.capitalize(propertyName);
      final Method method = bean.getClass().getMethod(methodName, new Class[0]);
      final Object value = method.invoke(bean, new Object[0]);
      return value;
    }
    catch (final IllegalAccessException e)
    {
      throw new PropertyAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_INACCESSIBLE_PROPERTY,
          propertyName, bean.getClass());
    }
    catch (final InvocationTargetException e)
    {
      throw new PropertyAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_PROPERTY_RUNTIME_ACCESS,
          propertyName, bean.getClass());
    }
    catch (final NoSuchMethodException e)
    {
      throw new PropertyAccessConfigurationException(e,
          ConfigurationExceptionCode.CONFIGURATION_NO_GETTER_FOR_PROPERTY,
          propertyName, bean.getClass());
    }
  }
File Line
de\smartics\exceptions\i18n\app\ConfigurationExceptionCode.java 132
de\smartics\exceptions\i18n\app\ParseExceptionCode.java 114
  private ConfigurationExceptionCode(final String componentId,
      final Integer majorNumber, final Integer minorNumber)
  {
    this.info = new NumberCodeInfo(componentId, majorNumber, minorNumber);
  }

  // ********************************* Methods ********************************

  // --- init -----------------------------------------------------------------

  /**
   * Used to access the identify for the exceptions raised by this component.
   *
   * @return the component identifier of this exception library.
   */
  private static String readComponentId()
  {
    return Constant.COMPONENT_ID;
  }

  // --- get&set --------------------------------------------------------------

  // --- business -------------------------------------------------------------

  @Override
  public String getCode()
  {
    return info.getCode();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String getComponentId()
  {
    return info.getComponentId();
  }

  @Override
  public Integer getMajorNumber()
  {
    return info.getMajorNumber();
  }

  @Override
  public Integer getMinorNumber()
  {
    return info.getMinorNumber();
  }

  @Override
  public String getDisplayId()
  {
    return info.getDisplayId();
  }

  // --- object basics --------------------------------------------------------

  /**
   * Returns the string representation of the object.
   *
   * @return the string representation of the object.
   */
  @Override
  public String toString()
  {
    return info.toString();
  }
}
File Line
de\smartics\exceptions\i18n\message\DefaultMessageComposer.java 585
de\smartics\exceptions\i18n\message\IcuMessageComposer.java 441
  }

  /**
   * Returns the value of the given field.
   * <p>
   * The method assumes the the field is accessible. If not an configuration
   * exception is thrown.
   *
   * @param bean the instance whose field value is requested.
   * @param field the field whose value is requested.
   * @return the requested value fetched from the field.
   */
  private static Object getFieldValue(final Object bean, final Field field)
  {
    try
    {
      final Object value = field.get(bean);
      return value;
    }
    catch (final IllegalArgumentException e)
    {
      assert false : "The field '" + field.getName()
                     + "' is not a member of the class '" + bean.getClass()
                     + "': " + e.getMessage();
    }
    catch (final IllegalAccessException e)
    {
      assert false : "The field '" + field.getName() + "' in class '"
                     + bean.getClass() + "' is not accessible: "
                     + e.getMessage();
    }
    // Unfortunately the compiler does not see that we will raise an assertion
    // exception if one of the caught exceptions is thrown.
    assert false : "The system should never reach this point.";
    return null;
  }