|
@@ -25,31 +25,46 @@ import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcResponseHeaderProto.Rpc
|
|
|
import org.xml.sax.Attributes;
|
|
|
|
|
|
public class RemoteException extends IOException {
|
|
|
+ /** this value should not be defined in RpcHeader.proto so that protobuf will return a null */
|
|
|
+ private static final int UNSPECIFIED_ERROR = -1;
|
|
|
/** For java.io.Serializable */
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
private final int errorCode;
|
|
|
|
|
|
- private String className;
|
|
|
+ private final String className;
|
|
|
|
|
|
+ /**
|
|
|
+ * @param className wrapped exception, may be null
|
|
|
+ * @param msg may be null
|
|
|
+ */
|
|
|
public RemoteException(String className, String msg) {
|
|
|
- super(msg);
|
|
|
- this.className = className;
|
|
|
- errorCode = -1;
|
|
|
+ this(className, msg, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param className wrapped exception, may be null
|
|
|
+ * @param msg may be null
|
|
|
+ * @param erCode may be null
|
|
|
+ */
|
|
|
public RemoteException(String className, String msg, RpcErrorCodeProto erCode) {
|
|
|
super(msg);
|
|
|
this.className = className;
|
|
|
if (erCode != null)
|
|
|
errorCode = erCode.getNumber();
|
|
|
else
|
|
|
- errorCode = -1;
|
|
|
+ errorCode = UNSPECIFIED_ERROR;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return the class name for the wrapped exception; may be null if none was given.
|
|
|
+ */
|
|
|
public String getClassName() {
|
|
|
return className;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return may be null if the code was newer than our protobuf definitions or none was given.
|
|
|
+ */
|
|
|
public RpcErrorCodeProto getErrorCode() {
|
|
|
return RpcErrorCodeProto.valueOf(errorCode);
|
|
|
}
|
|
@@ -60,7 +75,7 @@ public class RemoteException extends IOException {
|
|
|
* <p>
|
|
|
* Unwraps any IOException.
|
|
|
*
|
|
|
- * @param lookupTypes the desired exception class.
|
|
|
+ * @param lookupTypes the desired exception class. may be null.
|
|
|
* @return IOException, which is either the lookupClass exception or this.
|
|
|
*/
|
|
|
public IOException unwrapRemoteException(Class<?>... lookupTypes) {
|
|
@@ -108,7 +123,10 @@ public class RemoteException extends IOException {
|
|
|
return ex;
|
|
|
}
|
|
|
|
|
|
- /** Create RemoteException from attributes */
|
|
|
+ /**
|
|
|
+ * Create RemoteException from attributes
|
|
|
+ * @param attrs may not be null
|
|
|
+ */
|
|
|
public static RemoteException valueOf(Attributes attrs) {
|
|
|
return new RemoteException(attrs.getValue("class"),
|
|
|
attrs.getValue("message"));
|