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 /** 27 * Thrown when an identity object is required but a value object is supplied. 28 * <p> 29 * Identity objects are required for synchronization and locking. 30 * <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">Value-based</a> 31 * objects do not have identity and cannot be used for synchronization or locking. 32 * 33 * @since Valhalla 34 */ 35 public class IdentityException extends RuntimeException { 36 @java.io.Serial 37 private static final long serialVersionUID = 1L; 38 39 /** 40 * Create an {@code IdentityException} with no message. 41 */ 42 public IdentityException() { 43 } 44 45 /** 46 * Create an {@code IdentityException} with the class name and default message. 47 * 48 * @param clazz the class of the object 49 */ 50 public IdentityException(Class<?> clazz) { 51 super(clazz.getName() + " is not an identity class"); 52 } 53 54 /** 55 * Create an {@code IdentityException} with a message. 56 * 57 * @param message the detail message; can be {@code null} 58 */ 59 public IdentityException(String message) { 60 super(message); 61 } 62 63 /** 64 * Create an {@code IdentityException} with a cause. 65 * 66 * @param cause the cause; {@code null} is permitted, and indicates 67 * that the cause is nonexistent or unknown. 68 */ 69 public IdentityException(Throwable cause) { 70 super(cause); 71 } 72 73 /** 74 * Create an {@code IdentityException} with a message and cause. 75 * 76 * @param message the detail message; can be {@code null} 77 * @param cause the cause; {@code null} is permitted, and indicates 78 * that the cause is nonexistent or unknown. 79 */ 80 public IdentityException(String message, Throwable cause) { 81 super(message, cause); 82 } 83 }