1 /*
2 * Copyright (c) 2001-2017, Zoltan Farkas All Rights Reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Additionally licensed with:
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License");
21 * you may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */
32 package org.spf4j.base.avro;
33
34 import java.util.List;
35 import javax.annotation.ParametersAreNonnullByDefault;
36
37 /**
38 * @author Zoltan Farkas
39 */
40 @ParametersAreNonnullByDefault
41 public class RemoteException extends org.spf4j.base.RemoteException {
42
43 public RemoteException(final String source, final Throwable remote) {
44 super(remote.getMessage(),
45 source, remote.getClassName(),
46 remote, remote.getCause() == null ? null : new RemoteException(source, remote.getCause()));
47 for (Throwable suppressed : remote.getSuppressed()) {
48 addSuppressed(new RemoteException(source, suppressed));
49 }
50 List<StackTraceElement> stackTrace = remote.getStackTrace();
51 java.lang.StackTraceElement[] jste = new java.lang.StackTraceElement[stackTrace.size()];
52 int i = 0;
53 for (StackTraceElement ste : stackTrace) {
54 FileLocation location = ste.getLocation();
55 Method method = ste.getMethod();
56 String declaringClass = method.getDeclaringClass();
57 if (!declaringClass.startsWith("remote.")) { // add this to protect from reflectiion use.
58 declaringClass = "remote." + declaringClass;
59 }
60 if (location == null) {
61 jste[i] = new java.lang.StackTraceElement(declaringClass, method.getName(),
62 "N/A", -1);
63 } else {
64 jste[i] = new java.lang.StackTraceElement(declaringClass, method.getName(),
65 location.getFileName(), location.getLineNumber());
66 }
67 i++;
68 }
69 this.setStackTrace(jste);
70 }
71
72 public final Throwable getRemoteCause() {
73 return (Throwable) getRemoteDetail();
74 }
75
76 public final String getSource() {
77 return getOrigin();
78 }
79
80 /**
81 * Override to make up the remote stack trace.
82 * @return
83 */
84 @Override
85 public synchronized java.lang.Throwable fillInStackTrace() {
86 // no need to do anything we will overwrite this.
87 return this;
88 }
89
90 }