All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.internal.ch.qos.logback.classic.spi.ThrowableProxy Maven / Gradle / Ivy

The newest version!
/**
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */
package com.greenpepper.internal.com.greenpepper.internal.ch.qos.logback.classic.spi;

import com.greenpepper.internal.com.greenpepper.internal.ch.qos.logback.core.CoreConstants;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ThrowableProxy implements IThrowableProxy {

  private Throwable throwable;
  private String className;
  private String message;
  // package-private because of ThrowableProxyUtil
  StackTraceElementProxy[] stackTraceElementProxyArray;
  // package-private because of ThrowableProxyUtil
  int commonFrames;
  private ThrowableProxy cause;
  private ThrowableProxy[] suppressed=NO_SUPPRESSED;

  private transient PackagingDataCalculator packagingDataCalculator;
  private boolean calculatedPackageData = false;

  private static final Method GET_SUPPRESSED_METHOD;

  static {
    Method method = null;
    try {
      method = Throwable.class.getMethod("getSuppressed");
    } catch (NoSuchMethodException e) {
      // ignore, will get thrown in Java < 7
    }
    GET_SUPPRESSED_METHOD = method;
  }

  private static final ThrowableProxy[] NO_SUPPRESSED=new ThrowableProxy[0];

  public ThrowableProxy(Throwable throwable) {
   
    this.throwable = throwable;
    this.className = throwable.getClass().getName();
    this.message = throwable.getMessage();
    this.stackTraceElementProxyArray = ThrowableProxyUtil.steArrayToStepArray(throwable
        .getStackTrace());
    
    Throwable nested = throwable.getCause();
    
    if (nested != null) {
      this.cause = new ThrowableProxy(nested);
      this.cause.commonFrames = ThrowableProxyUtil
          .findNumberOfCommonFrames(nested.getStackTrace(),
              stackTraceElementProxyArray);
    }
    if(GET_SUPPRESSED_METHOD != null) {
      // this will only execute on Java 7
      try {
        Object obj = GET_SUPPRESSED_METHOD.invoke(throwable);
        if(obj instanceof Throwable[]) {
          Throwable[] throwableSuppressed = (Throwable[]) obj;
          if(throwableSuppressed.length > 0) {
            suppressed = new ThrowableProxy[throwableSuppressed.length];
            for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy