src/java.xml/share/classes/org/xml/sax/SAXException.java
author aefimov
Fri, 09 Feb 2018 14:49:38 +0000
changeset 48837 a262b919311a
parent 47216 71c04702a3d5
child 58247 3aef3bccfae3
permissions -rw-r--r--
6857903: SAXException.initCause() does not correctly set Exception Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    10
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * accompanied this code).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
 * questions.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
// SAX exception class.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
// http://www.saxproject.org
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    28
// No warranty; no copyright -- use this as you will.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    29
// $Id: SAXException.java,v 1.3 2004/11/03 22:55:32 jsuttor Exp $
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    31
package org.xml.sax;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    32
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    33
import java.io.IOException;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    34
import java.io.InvalidClassException;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    35
import java.io.ObjectInputStream;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    36
import java.io.ObjectOutputStream;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    37
import java.io.ObjectStreamField;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    38
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    39
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    40
 * Encapsulate a general SAX error or warning.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    41
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    42
 * <blockquote>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    43
 * <em>This module, both source code and documentation, is in the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    45
 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
 * for further information.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
 * </blockquote>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    48
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 * <p>This class can contain basic error or warning information from
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 * either the XML parser or the application: a parser writer or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    51
 * application writer can subclass it to provide additional
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    52
 * functionality.  SAX handlers may throw this exception or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
 * any exception subclassed from it.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
 * <p>If the application needs to pass through other types of
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
 * exceptions, it must wrap those exceptions in a SAXException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
 * or an exception derived from a SAXException.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    58
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
 * <p>If the parser or application needs to include information about a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
 * specific location in an XML document, it should use the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
 * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
 *
25262
1fe892ba017a 8047723: @since tag cleanup in jaxp
henryjen
parents: 12457
diff changeset
    63
 * @since 1.4, SAX 1.0
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
 * @author David Megginson
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
 * @version 2.0.1 (sax2r2)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
 * @see org.xml.sax.SAXParseException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
public class SAXException extends Exception {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
     * Create a new SAXException.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
    public SAXException ()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
        super();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
     * Create a new SAXException.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
     * @param message The error or warning message.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
    public SAXException (String message) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
        super(message);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    90
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    91
     * Create a new SAXException wrapping an existing exception.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
     * <p>The existing exception will be embedded in the new
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
     * one, and its message will become the default message for
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
     * the SAXException.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    97
     * @param e The exception to be wrapped in a SAXException.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
    public SAXException (Exception e)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   101
        super(e);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   106
     * Create a new SAXException from an existing exception.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
     * <p>The existing exception will be embedded in the new
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   109
     * one, but the new exception will have its own message.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   110
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   111
     * @param message The detail message.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
     * @param e The exception to be wrapped in a SAXException.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   113
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   114
    public SAXException (String message, Exception e)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   116
        super(message, e);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   119
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   121
     * Return a detail message for this exception.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   123
     * <p>If there is an embedded exception, and if the SAXException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
     * has no detail message of its own, this method will return
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
     * the detail message from the embedded exception.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   126
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
     * @return The error or warning message.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   128
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   129
    public String getMessage ()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
        String message = super.getMessage();
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   132
        Throwable cause = super.getCause();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   134
        if (message == null && cause != null) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   135
            return cause.getMessage();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   136
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   137
            return message;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   142
     * Return the embedded exception, if any.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   143
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   144
     * @return The embedded exception, or null if there is none.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   145
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   146
    public Exception getException ()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   147
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   148
        return getExceptionInternal();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   151
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   152
     * Return the cause of the exception
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
     * @return Return the cause of the exception
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
    public Throwable getCause() {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   157
        return super.getCause();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   160
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   161
     * Override toString to pick up any embedded exception.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   162
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   163
     * @return A string representation of this exception.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   165
    public String toString ()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   166
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   167
        Throwable exception = super.getCause();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   168
        if (exception != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   169
            return super.toString() + "\n" + exception.toString();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   170
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   171
            return super.toString();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   172
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
    //////////////////////////////////////////////////////////////////////
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
    // Internal state.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   179
    //////////////////////////////////////////////////////////////////////
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   180
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   181
    private static final ObjectStreamField[] serialPersistentFields = {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   182
        new ObjectStreamField( "exception", Exception.class )
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   183
    };
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   184
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   185
    /**
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   186
     * Writes "exception" field to the stream.
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   187
     *
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   188
     * @param out stream used for serialization.
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   189
     * @throws IOException thrown by <code>ObjectOutputStream</code>
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   190
     */
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   191
    private void writeObject(ObjectOutputStream out)
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   192
            throws IOException {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   193
        ObjectOutputStream.PutField fields = out.putFields();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   194
        fields.put("exception", getExceptionInternal());
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   195
        out.writeFields();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   196
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   197
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
    /**
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   199
     * Reads the "exception" field from the stream.
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   200
     * And initializes the "exception" if it wasn't
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   201
     * done before.
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   202
     *
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   203
     * @param in stream used for deserialization
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   204
     * @throws IOException            thrown by <code>ObjectInputStream</code>
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   205
     * @throws ClassNotFoundException thrown by <code>ObjectInputStream</code>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
     */
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   207
    private void readObject(ObjectInputStream in)
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   208
            throws IOException, ClassNotFoundException {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   209
        ObjectInputStream.GetField fields = in.readFields();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   210
        Exception exception = (Exception) fields.get("exception", null);
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   211
        Throwable superCause = super.getCause();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   212
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   213
        // if super.getCause() and 'exception' fields present then always use
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   214
        // getCause() value. Otherwise, use 'exception' to initialize cause
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   215
        if (superCause == null && exception != null) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   216
            try {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   217
                super.initCause(exception);
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   218
            } catch (IllegalStateException e) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   219
                throw new InvalidClassException("Inconsistent state: two causes");
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   220
            }
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   221
        }
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   222
    }
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   223
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   224
    // Internal method to guard against overriding of public getException
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   225
    // method by SAXException subclasses
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   226
    private Exception getExceptionInternal() {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   227
        Throwable cause = super.getCause();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   228
        if (cause instanceof Exception) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   229
            return (Exception) cause;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   230
        } else {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   231
            return null;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   232
        }
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   233
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
    // Added serialVersionUID to preserve binary compatibility
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
    static final long serialVersionUID = 583241635256073760L;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
}
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   238
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   239
// end of SAXException.java