1 /* |
1 /* |
2 * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1995, 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 |
32 |
32 |
33 /** |
33 /** |
34 * Thrown when an application tries to load in a class through its |
34 * Thrown when an application tries to load in a class through its |
35 * string name using: |
35 * string name using: |
36 * <ul> |
36 * <ul> |
37 * <li>The <code>forName</code> method in class <code>Class</code>. |
37 * <li>The {@code forName} method in class {@code Class}. |
38 * <li>The <code>findSystemClass</code> method in class |
38 * <li>The {@code findSystemClass} method in class |
39 * <code>ClassLoader</code> . |
39 * {@code ClassLoader} . |
40 * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>. |
40 * <li>The {@code loadClass} method in class {@code ClassLoader}. |
41 * </ul> |
41 * </ul> |
42 * <p> |
42 * <p> |
43 * but no definition for the class with the specified name could be found. |
43 * but no definition for the class with the specified name could be found. |
44 * |
44 * |
45 * <p>As of release 1.4, this exception has been retrofitted to conform to |
45 * <p>As of release 1.4, this exception has been retrofitted to conform to |
57 */ |
57 */ |
58 public class ClassNotFoundException extends ReflectiveOperationException { |
58 public class ClassNotFoundException extends ReflectiveOperationException { |
59 /** |
59 /** |
60 * use serialVersionUID from JDK 1.1.X for interoperability |
60 * use serialVersionUID from JDK 1.1.X for interoperability |
61 */ |
61 */ |
|
62 @java.io.Serial |
62 private static final long serialVersionUID = 9176873029745254542L; |
63 private static final long serialVersionUID = 9176873029745254542L; |
63 |
64 |
64 /** |
65 /** |
65 * Constructs a <code>ClassNotFoundException</code> with no detail message. |
66 * Constructs a {@code ClassNotFoundException} with no detail message. |
66 */ |
67 */ |
67 public ClassNotFoundException() { |
68 public ClassNotFoundException() { |
68 super((Throwable)null); // Disallow initCause |
69 super((Throwable)null); // Disallow initCause |
69 } |
70 } |
70 |
71 |
71 /** |
72 /** |
72 * Constructs a <code>ClassNotFoundException</code> with the |
73 * Constructs a {@code ClassNotFoundException} with the |
73 * specified detail message. |
74 * specified detail message. |
74 * |
75 * |
75 * @param s the detail message. |
76 * @param s the detail message. |
76 */ |
77 */ |
77 public ClassNotFoundException(String s) { |
78 public ClassNotFoundException(String s) { |
78 super(s, null); // Disallow initCause |
79 super(s, null); // Disallow initCause |
79 } |
80 } |
80 |
81 |
81 /** |
82 /** |
82 * Constructs a <code>ClassNotFoundException</code> with the |
83 * Constructs a {@code ClassNotFoundException} with the |
83 * specified detail message and optional exception that was |
84 * specified detail message and optional exception that was |
84 * raised while loading the class. |
85 * raised while loading the class. |
85 * |
86 * |
86 * @param s the detail message |
87 * @param s the detail message |
87 * @param ex the exception that was raised while loading the class |
88 * @param ex the exception that was raised while loading the class |
97 * |
98 * |
98 * <p>This method predates the general-purpose exception chaining facility. |
99 * <p>This method predates the general-purpose exception chaining facility. |
99 * The {@link Throwable#getCause()} method is now the preferred means of |
100 * The {@link Throwable#getCause()} method is now the preferred means of |
100 * obtaining this information. |
101 * obtaining this information. |
101 * |
102 * |
102 * @return the <code>Exception</code> that was raised while loading a class |
103 * @return the {@code Exception} that was raised while loading a class |
103 * @since 1.2 |
104 * @since 1.2 |
104 */ |
105 */ |
105 public Throwable getException() { |
106 public Throwable getException() { |
106 return super.getCause(); |
107 return super.getCause(); |
107 } |
108 } |
122 * |
124 * |
123 * The getException and getCause method returns the private "ex" field |
125 * The getException and getCause method returns the private "ex" field |
124 * in the older implementation and ClassNotFoundException::cause |
126 * in the older implementation and ClassNotFoundException::cause |
125 * was set to null. |
127 * was set to null. |
126 */ |
128 */ |
|
129 @java.io.Serial |
127 private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { |
130 private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { |
128 ObjectInputStream.GetField fields = s.readFields(); |
131 ObjectInputStream.GetField fields = s.readFields(); |
129 Throwable exception = (Throwable) fields.get("ex", null); |
132 Throwable exception = (Throwable) fields.get("ex", null); |
130 if (exception != null) { |
133 if (exception != null) { |
131 setCause(exception); |
134 setCause(exception); |
134 |
137 |
135 /* |
138 /* |
136 * To maintain compatibility with older implementation, write a serial |
139 * To maintain compatibility with older implementation, write a serial |
137 * "ex" field with the cause as the value. |
140 * "ex" field with the cause as the value. |
138 */ |
141 */ |
|
142 @java.io.Serial |
139 private void writeObject(ObjectOutputStream out) throws IOException { |
143 private void writeObject(ObjectOutputStream out) throws IOException { |
140 ObjectOutputStream.PutField fields = out.putFields(); |
144 ObjectOutputStream.PutField fields = out.putFields(); |
141 fields.put("ex", super.getCause()); |
145 fields.put("ex", super.getCause()); |
142 out.writeFields(); |
146 out.writeFields(); |
143 } |
147 } |