1 /*
 2  * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 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
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package java.lang;
24 
25 
26 import jdk.internal.javac.PreviewFeature;
27 
28 /**
29  * Thrown when an identity object is required but a value object is supplied.
30  * <p>
31  * Identity objects are required for synchronization and locking.
32  * <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">Value-based</a>
33  * objects do not have identity and cannot be used for synchronization or locking.
34  *
35  * @since Valhalla
36  */
37 @PreviewFeature(feature = PreviewFeature.Feature.VALUE_OBJECTS)
38 public class IdentityException extends RuntimeException {
39     @java.io.Serial
40     private static final long serialVersionUID = 1L;
41 
42     /**
43      * Create an {@code IdentityException} with no message.
44      */
45     public IdentityException() {
46     }
47 
48     /**
49      * Create an {@code IdentityException} with the class name and default message.
50      *
51      * @param clazz the class of the object
52      */
53     public IdentityException(Class<?> clazz) {
54         super(clazz.getName() + " is not an identity class");
55     }
56 
57     /**
58      * Create an {@code IdentityException} with a message.
59      *
60      * @param  message the detail message; can be {@code null}
61      */
62     public IdentityException(String message) {
63         super(message);
64     }
65 
66     /**
67      * Create an {@code IdentityException} with a cause.
68      *
69      * @param  cause the cause; {@code null} is permitted, and indicates
70      *               that the cause is nonexistent or unknown.
71      */
72     public IdentityException(Throwable cause) {
73         super(cause);
74     }
75 
76     /**
77      * Create an {@code IdentityException} with a message and cause.
78      *
79      * @param  message the detail message; can be {@code null}
80      * @param  cause the cause; {@code null} is permitted, and indicates
81      *               that the cause is nonexistent or unknown.
82      */
83     public IdentityException(String message, Throwable cause) {
84         super(message, cause);
85     }
86 }