ExceptionUtils.java
11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
package org.apache.commons.lang3.exception;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
public class ExceptionUtils
{
private static final String[] a = { "getCause", "getNextException", "getTargetException", "getException", "getSourceException", "getRootCause", "getCausedByException", "getNested", "getLinkedException", "getNestedException", "getLinkedCause", "getThrowable" };
private static int a(Throwable paramThrowable, Class<?> paramClass, int paramInt, boolean paramBoolean)
{
if ((paramThrowable == null) || (paramClass == null))
{
paramInt = -1;
return paramInt;
}
int i = paramInt;
if (paramInt < 0) {
i = 0;
}
paramThrowable = getThrowables(paramThrowable);
if (i >= paramThrowable.length) {
return -1;
}
paramInt = i;
if (paramBoolean) {
for (;;)
{
if (i >= paramThrowable.length) {
break label101;
}
paramInt = i;
if (paramClass.isAssignableFrom(paramThrowable[i].getClass())) {
break;
}
i += 1;
}
}
do
{
paramInt += 1;
if (paramInt >= paramThrowable.length) {
break;
}
} while (!paramClass.equals(paramThrowable[paramInt].getClass()));
return paramInt;
label101:
return -1;
}
private static Throwable a(Throwable paramThrowable, String paramString)
{
try
{
paramString = paramThrowable.getClass().getMethod(paramString, new Class[0]);
if ((paramString == null) || (!Throwable.class.isAssignableFrom(paramString.getReturnType()))) {}
}
catch (NoSuchMethodException paramString)
{
for (;;)
{
try
{
paramThrowable = (Throwable)paramString.invoke(paramThrowable, new Object[0]);
return paramThrowable;
}
catch (InvocationTargetException paramThrowable)
{
return null;
}
catch (IllegalArgumentException paramThrowable)
{
continue;
}
catch (IllegalAccessException paramThrowable)
{
continue;
}
paramString = paramString;
paramString = null;
}
}
catch (SecurityException paramString)
{
for (;;)
{
paramString = null;
}
}
}
private static List<String> a(Throwable paramThrowable)
{
paramThrowable = new StringTokenizer(getStackTrace(paramThrowable), SystemUtils.LINE_SEPARATOR);
ArrayList localArrayList = new ArrayList();
int i = 0;
do
{
for (;;)
{
if (!paramThrowable.hasMoreTokens()) {
return localArrayList;
}
String str = paramThrowable.nextToken();
int j = str.indexOf("at");
if ((j == -1) || (!str.substring(0, j).trim().isEmpty())) {
break;
}
i = 1;
localArrayList.add(str);
}
} while (i == 0);
return localArrayList;
}
@Deprecated
public static Throwable getCause(Throwable paramThrowable)
{
return getCause(paramThrowable, null);
}
@Deprecated
public static Throwable getCause(Throwable paramThrowable, String[] paramArrayOfString)
{
if (paramThrowable == null) {}
for (;;)
{
return null;
String[] arrayOfString = paramArrayOfString;
if (paramArrayOfString == null)
{
paramArrayOfString = paramThrowable.getCause();
if (paramArrayOfString != null) {
return paramArrayOfString;
}
arrayOfString = a;
}
int j = arrayOfString.length;
int i = 0;
while (i < j)
{
paramArrayOfString = arrayOfString[i];
if (paramArrayOfString != null)
{
paramArrayOfString = a(paramThrowable, paramArrayOfString);
if (paramArrayOfString != null) {
return paramArrayOfString;
}
}
i += 1;
}
}
}
@Deprecated
public static String[] getDefaultCauseMethodNames()
{
return (String[])ArrayUtils.clone(a);
}
public static String getMessage(Throwable paramThrowable)
{
if (paramThrowable == null) {
return "";
}
String str = ClassUtils.getShortClassName(paramThrowable, null);
paramThrowable = paramThrowable.getMessage();
return str + ": " + StringUtils.defaultString(paramThrowable);
}
public static Throwable getRootCause(Throwable paramThrowable)
{
paramThrowable = getThrowableList(paramThrowable);
if (paramThrowable.size() < 2) {
return null;
}
return (Throwable)paramThrowable.get(paramThrowable.size() - 1);
}
public static String getRootCauseMessage(Throwable paramThrowable)
{
Throwable localThrowable = getRootCause(paramThrowable);
if (localThrowable == null) {}
for (;;)
{
return getMessage(paramThrowable);
paramThrowable = localThrowable;
}
}
public static String[] getRootCauseStackTrace(Throwable paramThrowable)
{
if (paramThrowable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
Throwable[] arrayOfThrowable = getThrowables(paramThrowable);
int j = arrayOfThrowable.length;
ArrayList localArrayList = new ArrayList();
paramThrowable = a(arrayOfThrowable[(j - 1)]);
int i = j;
int k = i - 1;
Object localObject;
if (k >= 0)
{
if (k == 0) {
break label186;
}
localObject = a(arrayOfThrowable[(k - 1)]);
removeCommonFrames(paramThrowable, (List)localObject);
}
for (;;)
{
if (k == j - 1) {
localArrayList.add(arrayOfThrowable[k].toString());
}
for (;;)
{
i = 0;
while (i < paramThrowable.size())
{
localArrayList.add(paramThrowable.get(i));
i += 1;
}
localArrayList.add(" [wrapped] " + arrayOfThrowable[k].toString());
}
i = k;
paramThrowable = (Throwable)localObject;
break;
return (String[])localArrayList.toArray(new String[localArrayList.size()]);
label186:
localObject = paramThrowable;
}
}
public static String[] getStackFrames(Throwable paramThrowable)
{
if (paramThrowable == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
paramThrowable = new StringTokenizer(getStackTrace(paramThrowable), SystemUtils.LINE_SEPARATOR);
ArrayList localArrayList = new ArrayList();
while (paramThrowable.hasMoreTokens()) {
localArrayList.add(paramThrowable.nextToken());
}
return (String[])localArrayList.toArray(new String[localArrayList.size()]);
}
public static String getStackTrace(Throwable paramThrowable)
{
StringWriter localStringWriter = new StringWriter();
paramThrowable.printStackTrace(new PrintWriter(localStringWriter, true));
return localStringWriter.getBuffer().toString();
}
public static int getThrowableCount(Throwable paramThrowable)
{
return getThrowableList(paramThrowable).size();
}
public static List<Throwable> getThrowableList(Throwable paramThrowable)
{
ArrayList localArrayList = new ArrayList();
while ((paramThrowable != null) && (!localArrayList.contains(paramThrowable)))
{
localArrayList.add(paramThrowable);
paramThrowable = getCause(paramThrowable);
}
return localArrayList;
}
public static Throwable[] getThrowables(Throwable paramThrowable)
{
paramThrowable = getThrowableList(paramThrowable);
return (Throwable[])paramThrowable.toArray(new Throwable[paramThrowable.size()]);
}
public static boolean hasCause(Throwable paramThrowable, Class<? extends Throwable> paramClass)
{
Throwable localThrowable = paramThrowable;
if ((paramThrowable instanceof UndeclaredThrowableException)) {
localThrowable = paramThrowable.getCause();
}
return paramClass.isInstance(localThrowable);
}
public static int indexOfThrowable(Throwable paramThrowable, Class<?> paramClass)
{
return a(paramThrowable, paramClass, 0, false);
}
public static int indexOfThrowable(Throwable paramThrowable, Class<?> paramClass, int paramInt)
{
return a(paramThrowable, paramClass, paramInt, false);
}
public static int indexOfType(Throwable paramThrowable, Class<?> paramClass)
{
return a(paramThrowable, paramClass, 0, true);
}
public static int indexOfType(Throwable paramThrowable, Class<?> paramClass, int paramInt)
{
return a(paramThrowable, paramClass, paramInt, true);
}
public static void printRootCauseStackTrace(Throwable paramThrowable)
{
printRootCauseStackTrace(paramThrowable, System.err);
}
public static void printRootCauseStackTrace(Throwable paramThrowable, PrintStream paramPrintStream)
{
if (paramThrowable == null) {
return;
}
if (paramPrintStream == null) {
throw new IllegalArgumentException("The PrintStream must not be null");
}
paramThrowable = getRootCauseStackTrace(paramThrowable);
int j = paramThrowable.length;
int i = 0;
while (i < j)
{
paramPrintStream.println(paramThrowable[i]);
i += 1;
}
paramPrintStream.flush();
}
public static void printRootCauseStackTrace(Throwable paramThrowable, PrintWriter paramPrintWriter)
{
if (paramThrowable == null) {
return;
}
if (paramPrintWriter == null) {
throw new IllegalArgumentException("The PrintWriter must not be null");
}
paramThrowable = getRootCauseStackTrace(paramThrowable);
int j = paramThrowable.length;
int i = 0;
while (i < j)
{
paramPrintWriter.println(paramThrowable[i]);
i += 1;
}
paramPrintWriter.flush();
}
public static void removeCommonFrames(List<String> paramList1, List<String> paramList2)
{
if ((paramList1 == null) || (paramList2 == null)) {
throw new IllegalArgumentException("The List must not be null");
}
int i = paramList1.size();
int j = paramList2.size() - 1;
i -= 1;
while ((i >= 0) && (j >= 0))
{
if (((String)paramList1.get(i)).equals((String)paramList2.get(j))) {
paramList1.remove(i);
}
j -= 1;
i -= 1;
}
}
public static <R> R rethrow(Throwable paramThrowable)
{
throw paramThrowable;
}
public static <R> R wrapAndThrow(Throwable paramThrowable)
{
if ((paramThrowable instanceof RuntimeException)) {
throw ((RuntimeException)paramThrowable);
}
if ((paramThrowable instanceof Error)) {
throw ((Error)paramThrowable);
}
throw new UndeclaredThrowableException(paramThrowable);
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/org/apache/commons/lang3/exception/ExceptionUtils.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/