--- old/src/java.base/share/classes/jdk/internal/org/xml/sax/SAXException.java 2018-02-05 16:48:21.938648789 +0000
+++ new/src/java.base/share/classes/jdk/internal/org/xml/sax/SAXException.java 2018-02-05 16:48:21.526648804 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,11 @@
package jdk.internal.org.xml.sax;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+
/**
* Encapsulate a general SAX error or warning.
*
@@ -68,7 +73,6 @@
public SAXException ()
{
super();
- this.exception = null;
}
@@ -79,7 +83,6 @@
*/
public SAXException (String message) {
super(message);
- this.exception = null;
}
@@ -94,8 +97,7 @@
*/
public SAXException (Exception e)
{
- super();
- this.exception = e;
+ super(e);
}
@@ -110,8 +112,7 @@
*/
public SAXException (String message, Exception e)
{
- super(message);
- this.exception = e;
+ super(message, e);
}
@@ -127,15 +128,15 @@
public String getMessage ()
{
String message = super.getMessage();
+ Throwable cause = super.getCause();
- if (message == null && exception != null) {
- return exception.getMessage();
+ if (message == null && cause != null) {
+ return cause.getMessage();
} else {
return message;
}
}
-
/**
* Return the embedded exception, if any.
*
@@ -143,7 +144,12 @@
*/
public Exception getException ()
{
- return exception;
+ Throwable cause = super.getCause();
+ if (Exception.class.isInstance(cause)) {
+ return (Exception) cause;
+ } else {
+ return null;
+ }
}
/**
@@ -152,7 +158,7 @@
* @return Return the cause of the exception
*/
public Throwable getCause() {
- return exception;
+ return super.getCause();
}
/**
@@ -162,6 +168,7 @@
*/
public String toString ()
{
+ Throwable exception = getCause();
if (exception != null) {
return super.toString() + "\n" + exception.toString();
} else {
@@ -175,11 +182,47 @@
// Internal state.
//////////////////////////////////////////////////////////////////////
+ private static final ObjectStreamField[] serialPersistentFields = {
+ new ObjectStreamField( "exception", Exception.class )
+ };
/**
- * @serial The embedded exception if tunnelling, or null.
+ * Writes "exception" field to the stream.
+ *
+ * @param out stream used for serialization.
+ * @throws IOException thrown by ObjectOutputStream
+ *
*/
- private Exception exception;
+ private void writeObject(ObjectOutputStream out)
+ throws IOException
+ {
+ ObjectOutputStream.PutField fields = out.putFields();
+ fields.put("exception", getException());
+ out.writeFields();
+ }
+
+ /**
+ * Reads the "exception" field from the stream.
+ * And initializes the "exception" if it wasn't
+ * done before.
+ *
+ * @param in stream used for deserialization
+ * @throws IOException thrown by ObjectInputStream
+ * @throws ClassNotFoundException thrown by ObjectInputStream
+ */
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException
+ {
+ ObjectInputStream.GetField fields = in.readFields();
+ Exception exception = (Exception) fields.get("exception", null);
+ Throwable superCause = super.getCause();
+
+ // if super.getCause() and 'exception' fields present then always use
+ // getCause() value. Otherwise, use 'exception' to initialize cause
+ if (superCause == null && exception != null) {
+ initCause(exception);
+ }
+ }
// Added serialVersionUID to preserve binary compatibility
static final long serialVersionUID = 583241635256073760L;