<commit_before>/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.commons.schedule.executor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Invoke given method of given object.
 *
 * @author <NAME>
 */
public class LoggedRunnable implements Runnable {
  private static final Logger LOG = LoggerFactory.getLogger(LoggedRunnable.class);

  private final Object object;
  private final Method method;

  public LoggedRunnable(Object object, Method method) {
    this.object = object;
    this.method = method;
  }

  @Override
  public void run() {
    long startTime = System.currentTimeMillis();
    try {
      if (object instanceof Runnable
          && method.getName().equals("run")
          && method.getParameterTypes().length == 0) {
        LOG.debug(
            "Invoking method run of class {} instance {}", object.getClass().getName(), object);

        ((Runnable) object).run();

        LOG.debug(
            "Method of class {} instance {} complete  at {}  sec",
            object.getClass().getName(),
            object,
            TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
      } else {
        try {
          LOG.debug(
              "Invoking run method of class {} instance {}", object.getClass().getName(), object);

          method.invoke(object);

          LOG.debug(
              "Method of class {} instance {} complete  at {}  sec",
              object.getClass().getName(),
              object,
              TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
        } catch (InvocationTargetException | IllegalAccessException e) {
          LOG.error(e.getLocalizedMessage());
        }
      }
    } catch (Exception e) {
      LOG.error(e.getLocalizedMessage(), e);
      throw e;
    }
  }
}
<commit_msg>Add cause information in case of InvocationTargetException | IllegalAccessException happened in LoggedRunnable (#11602)<commit_after>/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.commons.schedule.executor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Invoke given method of given object.
 *
 * @author <NAME>
 */
public class LoggedRunnable implements Runnable {
  private static final Logger LOG = LoggerFactory.getLogger(LoggedRunnable.class);

  private final Object object;
  private final Method method;

  public LoggedRunnable(Object object, Method method) {
    this.object = object;
    this.method = method;
  }

  @Override
  public void run() {
    long startTime = System.currentTimeMillis();
    try {
      if (object instanceof Runnable
          && method.getName().equals("run")
          && method.getParameterTypes().length == 0) {
        LOG.debug(
            "Invoking method run of class {} instance {}", object.getClass().getName(), object);

        ((Runnable) object).run();

        LOG.debug(
            "Method of class {} instance {} complete  at {}  sec",
            object.getClass().getName(),
            object,
            TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
      } else {
        try {
          LOG.debug(
              "Invoking run method of class {} instance {}", object.getClass().getName(), object);

          method.invoke(object);

          LOG.debug(
              "Method of class {} instance {} complete  at {}  sec",
              object.getClass().getName(),
              object,
              TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
        } catch (InvocationTargetException | IllegalAccessException e) {
          LOG.error(e.getMessage(), e);
        }
      }
    } catch (Exception e) {
      LOG.error(e.getMessage(), e);
      throw e;
    }
  }
}

{'fraction_non_alphanumeric': 0.11689438299718065, 'fraction_numerical': 0.008458035133376708, 'mean_word_length': 2.6257861635220126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4363272', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1270, 'n_words': 336}