View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.spi;
15  
16  import java.io.Serializable;
17  import java.util.Arrays;
18  
19  public class ThrowableProxyVO implements IThrowableProxy, Serializable {
20  
21      private static final long serialVersionUID = -773438177285807139L;
22  
23      private String className;
24      private String overridingMessage;
25      private String message;
26      private int commonFramesCount;
27      private StackTraceElementProxy[] stackTraceElementProxyArray;
28      private IThrowableProxy cause;
29      private IThrowableProxy[] suppressed;
30      private boolean cyclic;
31  
32      public String getMessage() {
33          return message;
34      }
35      /**
36       * Return the overriding message if any. This method returns null
37       * if there is no overriding message.
38       *
39       * <p>Overriding message exists only if the original throwable implementation overrides the toString() method.</p>
40       *
41       * @return the overriding message or null
42       * @since 1.5.22
43       */
44      @Override
45      public String getOverridingMessage() { return overridingMessage;}
46  
47      public String getClassName() {
48          return className;
49      }
50  
51      public int getCommonFrames() {
52          return commonFramesCount;
53      }
54  
55      public IThrowableProxy getCause() {
56          return cause;
57      }
58  
59      public StackTraceElementProxy[] getStackTraceElementProxyArray() {
60          return stackTraceElementProxyArray;
61      }
62  
63      public IThrowableProxy[] getSuppressed() {
64          return suppressed;
65      }
66  
67      public boolean isCyclic() {
68          return cyclic;
69      }
70  
71      /**
72       * Returns a new {@link ThrowableProxyVOBuilder} for constructing a
73       * {@link ThrowableProxyVO} field by field.
74       *
75       * <p>This is a supplement to {@link #build(IThrowableProxy)}, which copies
76       * an existing {@link IThrowableProxy} in one step.</p>
77       *
78       * @return a new builder instance
79       * @since 1.6.2
80       */
81      public static ThrowableProxyVOBuilder builder() {
82          return new ThrowableProxyVOBuilder();
83      }
84  
85      // package-private setters used by ThrowableProxyVOBuilder
86  
87      void setClassName(String className) {
88          this.className = className;
89      }
90  
91      void setMessage(String message) {
92          this.message = message;
93      }
94  
95      void setOverridingMessage(String overridingMessage) {
96          this.overridingMessage = overridingMessage;
97      }
98  
99      void setCommonFramesCount(int commonFramesCount) {
100         this.commonFramesCount = commonFramesCount;
101     }
102 
103     void setStackTraceElementProxyArray(StackTraceElementProxy[] stackTraceElementProxyArray) {
104         this.stackTraceElementProxyArray = stackTraceElementProxyArray;
105     }
106 
107     void setCause(IThrowableProxy cause) {
108         this.cause = cause;
109     }
110 
111     void setSuppressed(IThrowableProxy[] suppressed) {
112         this.suppressed = suppressed;
113     }
114 
115     void setCyclic(boolean cyclic) {
116         this.cyclic = cyclic;
117     }
118 
119     @Override
120     public int hashCode() {
121         final int prime = 31;
122         int result = 1;
123         result = prime * result + ((className == null) ? 0 : className.hashCode());
124         return result;
125     }
126 
127     @Override
128     public boolean equals(Object obj) {
129         if (this == obj)
130             return true;
131         if (obj == null)
132             return false;
133         if (getClass() != obj.getClass())
134             return false;
135         final ThrowableProxyVO other = (ThrowableProxyVO) obj;
136 
137         if (className == null) {
138             if (other.className != null)
139                 return false;
140         } else if (!className.equals(other.className))
141             return false;
142 
143         if (!Arrays.equals(stackTraceElementProxyArray, other.stackTraceElementProxyArray))
144             return false;
145 
146         if (!Arrays.equals(suppressed, other.suppressed))
147             return false;
148 
149         if (cause == null) {
150             if (other.cause != null)
151                 return false;
152         } else if (!cause.equals(other.cause))
153             return false;
154 
155         return true;
156     }
157 
158     public static ThrowableProxyVO build(IThrowableProxy throwableProxy) {
159         if (throwableProxy == null) {
160             return null;
161         }
162         ThrowableProxyVO tpvo = new ThrowableProxyVO();
163         tpvo.className = throwableProxy.getClassName();
164         tpvo.message = throwableProxy.getMessage();
165         tpvo.overridingMessage = throwableProxy.getOverridingMessage();
166         tpvo.commonFramesCount = throwableProxy.getCommonFrames();
167         tpvo.stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray();
168         tpvo.cyclic = throwableProxy.isCyclic();
169 
170         IThrowableProxy cause = throwableProxy.getCause();
171         if (cause != null) {
172             tpvo.cause = ThrowableProxyVO.build(cause);
173         }
174         IThrowableProxy[] suppressed = throwableProxy.getSuppressed();
175         if (suppressed != null) {
176             tpvo.suppressed = new IThrowableProxy[suppressed.length];
177             for (int i = 0; i < suppressed.length; i++) {
178                 tpvo.suppressed[i] = ThrowableProxyVO.build(suppressed[i]);
179             }
180         }
181 
182         return tpvo;
183     }
184 }