Path: blob/master/src/java.base/share/classes/java/io/InvalidClassException.java
41152 views
/*1* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.io;2627/**28* Thrown when the Serialization runtime detects one of the following29* problems with a Class.30* <UL>31* <LI> The serial version of the class does not match that of the class32* descriptor read from the stream33* <LI> The class contains unknown datatypes34* <LI> The class does not have an accessible no-arg constructor35* <LI> The ObjectStreamClass of an enum constant does not represent36* an enum type37* <LI> Other conditions given in the <cite>Java Object Serialization38* Specification</cite>39* </UL>40*41* @since 1.142*/43public class InvalidClassException extends ObjectStreamException {4445@java.io.Serial46private static final long serialVersionUID = -4333316296251054416L;4748/**49* Name of the invalid class.50*51* @serial Name of the invalid class.52*/53public String classname;5455/**56* Report an InvalidClassException for the reason specified.57*58* @param reason String describing the reason for the exception.59*/60public InvalidClassException(String reason) {61super(reason);62}6364/**65* Constructs an InvalidClassException object.66*67* @param cname a String naming the invalid class.68* @param reason a String describing the reason for the exception.69*/70public InvalidClassException(String cname, String reason) {71super(reason);72classname = cname;73}7475/**76* Produce the message and include the classname, if present.77*/78public String getMessage() {79if (classname == null)80return super.getMessage();81else82return classname + "; " + super.getMessage();83}84}858687