src/java.xml/share/classes/org/xml/sax/SAXException.java
author joehw
Fri, 20 Sep 2019 22:11:45 +0000
changeset 58247 3aef3bccfae3
parent 48837 a262b919311a
permissions -rw-r--r--
8231083: Clarify SAX documentation Reviewed-by: lancea, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
58247
3aef3bccfae3 8231083: Clarify SAX documentation
joehw
parents: 48837
diff changeset
     2
 * Copyright (c) 2000, 2019, 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
package org.xml.sax;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    28
import java.io.IOException;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    29
import java.io.InvalidClassException;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    30
import java.io.ObjectInputStream;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    31
import java.io.ObjectOutputStream;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    32
import java.io.ObjectStreamField;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    33
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    35
 * Encapsulate a general SAX error or warning.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    36
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    37
 * <p>This class can contain basic error or warning information from
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    38
 * either the XML parser or the application: a parser writer or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    39
 * application writer can subclass it to provide additional
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    40
 * functionality.  SAX handlers may throw this exception or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    41
 * any exception subclassed from it.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    42
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    43
 * <p>If the application needs to pass through other types of
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
 * exceptions, it must wrap those exceptions in a SAXException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    45
 * or an exception derived from a SAXException.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
 * <p>If the parser or application needs to include information about a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    48
 * specific location in an XML document, it should use the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 *
25262
1fe892ba017a 8047723: @since tag cleanup in jaxp
henryjen
parents: 12457
diff changeset
    51
 * @since 1.4, SAX 1.0
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    52
 * @author David Megginson
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
 * @version 2.0.1 (sax2r2)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
 * @see org.xml.sax.SAXParseException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
public class SAXException extends Exception {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
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
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
     * Create a new SAXException.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
    public SAXException ()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
        super();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
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
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
     * Create a new SAXException.
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
     * @param message The error or warning message.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
    public SAXException (String message) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
        super(message);
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
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
     * Create a new SAXException wrapping an existing exception.
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
     * <p>The existing exception will be embedded in the new
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
     * one, and its message will become the default message for
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
     * the SAXException.</p>
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
     * @param e The exception to be wrapped in a SAXException.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
    public SAXException (Exception e)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
    89
        super(e);
12005
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
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
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
     * Create a new SAXException from an existing exception.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
     * <p>The existing exception will be embedded in the new
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    97
     * one, but the new exception will have its own message.</p>
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
     * @param message The detail message.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
     * @param e The exception to be wrapped in a SAXException.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
    public SAXException (String message, Exception e)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   104
        super(message, e);
12005
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
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
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   109
     * Return a detail message for this exception.
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
     * <p>If there is an embedded exception, and if the SAXException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
     * has no detail message of its own, this method will return
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   113
     * the detail message from the embedded exception.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   114
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
     * @return The error or warning message.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
    public String getMessage ()
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
        String message = super.getMessage();
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   120
        Throwable cause = super.getCause();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   121
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   122
        if (message == null && cause != null) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   123
            return cause.getMessage();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
            return message;
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
    }
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
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
     * Return the embedded exception, if any.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
     * @return The embedded exception, or null if there is none.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   134
    public Exception getException ()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   135
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   136
        return getExceptionInternal();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   137
    }
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
     * Return the cause of the exception
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 Return the cause of the exception
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
    public Throwable getCause() {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   145
        return super.getCause();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   146
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   147
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   148
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
     * Override toString to pick up any embedded exception.
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
     * @return A string representation of this exception.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   152
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
    public String toString ()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
    {
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   155
        Throwable exception = super.getCause();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
        if (exception != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   157
            return super.toString() + "\n" + exception.toString();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
            return super.toString();
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
    }
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
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
    //////////////////////////////////////////////////////////////////////
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   166
    // Internal state.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   167
    //////////////////////////////////////////////////////////////////////
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   168
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   169
    private static final ObjectStreamField[] serialPersistentFields = {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   170
        new ObjectStreamField( "exception", Exception.class )
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   171
    };
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   172
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   173
    /**
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   174
     * Writes "exception" field to the stream.
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   175
     *
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   176
     * @param out stream used for serialization.
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   177
     * @throws IOException thrown by <code>ObjectOutputStream</code>
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   178
     */
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   179
    private void writeObject(ObjectOutputStream out)
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   180
            throws IOException {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   181
        ObjectOutputStream.PutField fields = out.putFields();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   182
        fields.put("exception", getExceptionInternal());
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   183
        out.writeFields();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   184
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   186
    /**
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   187
     * Reads the "exception" field from the stream.
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   188
     * And initializes the "exception" if it wasn't
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   189
     * done before.
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
     * @param in stream used for deserialization
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   192
     * @throws IOException            thrown by <code>ObjectInputStream</code>
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   193
     * @throws ClassNotFoundException thrown by <code>ObjectInputStream</code>
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
     */
48837
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   195
    private void readObject(ObjectInputStream in)
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   196
            throws IOException, ClassNotFoundException {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   197
        ObjectInputStream.GetField fields = in.readFields();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   198
        Exception exception = (Exception) fields.get("exception", null);
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   199
        Throwable superCause = super.getCause();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   200
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   201
        // if super.getCause() and 'exception' fields present then always use
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   202
        // getCause() value. Otherwise, use 'exception' to initialize cause
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   203
        if (superCause == null && exception != null) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   204
            try {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   205
                super.initCause(exception);
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   206
            } catch (IllegalStateException e) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   207
                throw new InvalidClassException("Inconsistent state: two causes");
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   208
            }
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   209
        }
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   210
    }
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   211
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   212
    // Internal method to guard against overriding of public getException
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   213
    // method by SAXException subclasses
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   214
    private Exception getExceptionInternal() {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   215
        Throwable cause = super.getCause();
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   216
        if (cause instanceof Exception) {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   217
            return (Exception) cause;
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   218
        } else {
a262b919311a 6857903: SAXException.initCause() does not correctly set Exception
aefimov
parents: 47216
diff changeset
   219
            return null;
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
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   222
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   223
    // Added serialVersionUID to preserve binary compatibility
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
    static final long serialVersionUID = 583241635256073760L;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
}
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   226
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   227
// end of SAXException.java