src/java.base/share/classes/java/lang/reflect/UndeclaredThrowableException.java
changeset 57956 e0b8b019d2f5
parent 52427 3c6aa484536c
equal deleted inserted replaced
57955:18863bf3501f 57956:e0b8b019d2f5
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    60  * @author      Peter Jones
    60  * @author      Peter Jones
    61  * @see         InvocationHandler
    61  * @see         InvocationHandler
    62  * @since       1.3
    62  * @since       1.3
    63  */
    63  */
    64 public class UndeclaredThrowableException extends RuntimeException {
    64 public class UndeclaredThrowableException extends RuntimeException {
       
    65     @java.io.Serial
    65     static final long serialVersionUID = 330127114055056639L;
    66     static final long serialVersionUID = 330127114055056639L;
    66 
    67 
    67     /**
    68     /**
    68      * Constructs an {@code UndeclaredThrowableException} with the
    69      * Constructs an {@code UndeclaredThrowableException} with the
    69      * specified {@code Throwable}.
    70      * specified {@code Throwable}.
   106     /**
   107     /**
   107      * Serializable fields for UndeclaredThrowableException.
   108      * Serializable fields for UndeclaredThrowableException.
   108      *
   109      *
   109      * @serialField undeclaredThrowable Throwable
   110      * @serialField undeclaredThrowable Throwable
   110      */
   111      */
       
   112     @java.io.Serial
   111     private static final ObjectStreamField[] serialPersistentFields = {
   113     private static final ObjectStreamField[] serialPersistentFields = {
   112         new ObjectStreamField("undeclaredThrowable", Throwable.class)
   114         new ObjectStreamField("undeclaredThrowable", Throwable.class)
   113     };
   115     };
   114 
   116 
   115     /*
   117     /*
   116      * Reconstitutes the UndeclaredThrowableException instance from a stream
   118      * Reconstitutes the UndeclaredThrowableException instance from a stream
   117      * and initialize the cause properly when deserializing from an older
   119      * and initialize the cause properly when deserializing from an older
   118      * version.
   120      * version.
   119      */
   121      */
       
   122     @java.io.Serial
   120     private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
   123     private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
   121         ObjectInputStream.GetField fields = s.readFields();
   124         ObjectInputStream.GetField fields = s.readFields();
   122         Throwable exception = (Throwable) fields.get("undeclaredThrowable", null);
   125         Throwable exception = (Throwable) fields.get("undeclaredThrowable", null);
   123         if (exception != null) {
   126         if (exception != null) {
   124             SharedSecrets.getJavaLangAccess().setCause(this, exception);
   127             SharedSecrets.getJavaLangAccess().setCause(this, exception);
   127 
   130 
   128     /*
   131     /*
   129      * To maintain compatibility with older implementation, write a serial
   132      * To maintain compatibility with older implementation, write a serial
   130      * "ex" field with the cause as the value.
   133      * "ex" field with the cause as the value.
   131      */
   134      */
       
   135     @java.io.Serial
   132     private void writeObject(ObjectOutputStream out) throws IOException {
   136     private void writeObject(ObjectOutputStream out) throws IOException {
   133         ObjectOutputStream.PutField fields = out.putFields();
   137         ObjectOutputStream.PutField fields = out.putFields();
   134         fields.put("undeclaredThrowable", super.getCause());
   138         fields.put("undeclaredThrowable", super.getCause());
   135         out.writeFields();
   139         out.writeFields();
   136     }
   140     }