Skip to main content

InvalidClassException

java.io.InvalidClassException

InvalidClassException is described in the javadoc comments as:

Thrown when the Serialization runtime detects one of the following problems with a Class.
  • The serial version of the class does not match that of the class descriptor read from the stream
  • The class contains unknown datatypes
  • The class does not have an accessible no-arg constructor

author: unascribed version: 1.20, 12/19/03 since: JDK1.1

Where is this exception thrown?

Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown.

How is this exception thrown?

The following sub-sections identify where this exception is thrown, and how (or why) the code is throwing the exception.

Any source code quoted in this section is subject to the Java Research License unless stated otherwise.

com.sun.corba.se.impl.io.IIOPInputStream.inputCurrentClassFieldsForReadFields(java.util.Map)

/**
     * Called from InputStreamHook.
     * Reads the fields of the current class (could be the ones
     * queried from the remote FVD) and puts them in
     * the given Map, name to value.  Wraps primitives in the
     * corresponding java.lang Objects.
     */
private final void inputCurrentClassFieldsForReadFields(java.util.Map fieldToValueMap) throws InvalidClassException, StreamCorruptedException, ClassNotFoundException, IOException {
    ObjectStreamField[] fields = currentClassDesc.getFieldsNoCopy();
    int primFields = fields.length - currentClassDesc.objFields;
    for (int i = 0; i < primFields; ++i) {
        switch(fields[i].getTypeCode()) {
            case 'B':
                byte byteValue = orbStream.read_octet();
                fieldToValueMap.put(fields[i].getName(), new Byte(byteValue));
                break;
            case 'Z':
                boolean booleanValue = orbStream.read_boolean();
                fieldToValueMap.put(fields[i].getName(), new Boolean(booleanValue));
                break;
            case 'C':
                char charValue = orbStream.read_wchar();
                fieldToValueMap.put(fields[i].getName(), new Character(charValue));
                break;
            case 'S':
                short shortValue = orbStream.read_short();
                fieldToValueMap.put(fields[i].getName(), new Short(shortValue));
                break;
            case 'I':
                int intValue = orbStream.read_long();
                fieldToValueMap.put(fields[i].getName(), new Integer(intValue));
                break;
            case 'J':
                long longValue = orbStream.read_longlong();
                fieldToValueMap.put(fields[i].getName(), new Long(longValue));
                break;
            case 'F':
                float floatValue = orbStream.read_float();
                fieldToValueMap.put(fields[i].getName(), new Float(floatValue));
                break;
            case 'D':
                double doubleValue = orbStream.read_double();
                fieldToValueMap.put(fields[i].getName(), new Double(doubleValue));
                break;
            default:
                throw new InvalidClassException(currentClassDesc.getName());
        }
    }
    if (currentClassDesc.objFields > 0) {
        for (int i = primFields; i < fields.length; i++) {
            Object objectValue = null;
            try {
                objectValue = inputObjectField(fields[i]);
            } catch (IndirectionException cdrie) {
                objectValue = activeRecursionMgr.getObject(cdrie.offset);
            }
            fieldToValueMap.put(fields[i].getName(), objectValue);
        }
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.corba.se.impl.io.IIOPInputStream.inputPrimitiveField(Object, Class, ObjectStreamField)

/**
     * Factored out of inputClassFields  This reads a primitive value and sets it 
     * in the field of o described by the ObjectStreamField field.
     * Note that reflection cannot be used here, because reflection cannot be used
     * to set final fields. 
     */
private void inputPrimitiveField(Object o, Class cl, ObjectStreamField field) throws InvalidClassException, IOException {
    try {
        switch(field.getTypeCode()) {
            case 'B':
                byte byteValue = orbStream.read_octet();
                bridge.putByte(o, field.getFieldID(), byteValue);
                break;
            case 'Z':
                boolean booleanValue = orbStream.read_boolean();
                bridge.putBoolean(o, field.getFieldID(), booleanValue);
                break;
            case 'C':
                char charValue = orbStream.read_wchar();
                bridge.putChar(o, field.getFieldID(), charValue);
                break;
            case 'S':
                short shortValue = orbStream.read_short();
                bridge.putShort(o, field.getFieldID(), shortValue);
                break;
            case 'I':
                int intValue = orbStream.read_long();
                bridge.putInt(o, field.getFieldID(), intValue);
                break;
            case 'J':
                long longValue = orbStream.read_longlong();
                bridge.putLong(o, field.getFieldID(), longValue);
                break;
            case 'F':
                float floatValue = orbStream.read_float();
                bridge.putFloat(o, field.getFieldID(), floatValue);
                break;
            case 'D':
                double doubleValue = orbStream.read_double();
                bridge.putDouble(o, field.getFieldID(), doubleValue);
                break;
            default:
                throw new InvalidClassException(cl.getName());
        }
    } catch (IllegalArgumentException e) {
        ClassCastException cce = new ClassCastException('Assigning instance of class ' + field.getType().getName() + ' to field ' + currentClassDesc.getName() + '#' + field.getField().getName());
        cce.initCause(e);
        throw cce;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.corba.se.impl.io.IIOPOutputStream.outputClassFields(Object, Class, ObjectStreamField[])

private void outputClassFields(Object o, Class cl, ObjectStreamField[] fields) throws IOException, InvalidClassException {
    for (int i = 0; i < fields.length; i++) {
        if (fields[i].getField() == null) throw new InvalidClassException(cl.getName(), 'Nonexistent field ' + fields[i].getName());
        try {
            switch(fields[i].getTypeCode()) {
                case 'B':
                    byte byteValue = fields[i].getField().getByte(o);
                    orbStream.write_octet(byteValue);
                    break;
                case 'C':
                    char charValue = fields[i].getField().getChar(o);
                    orbStream.write_wchar(charValue);
                    break;
                case 'F':
                    float floatValue = fields[i].getField().getFloat(o);
                    orbStream.write_float(floatValue);
                    break;
                case 'D':
                    double doubleValue = fields[i].getField().getDouble(o);
                    orbStream.write_double(doubleValue);
                    break;
                case 'I':
                    int intValue = fields[i].getField().getInt(o);
                    orbStream.write_long(intValue);
                    break;
                case 'J':
                    long longValue = fields[i].getField().getLong(o);
                    orbStream.write_longlong(longValue);
                    break;
                case 'S':
                    short shortValue = fields[i].getField().getShort(o);
                    orbStream.write_short(shortValue);
                    break;
                case 'Z':
                    boolean booleanValue = fields[i].getField().getBoolean(o);
                    orbStream.write_boolean(booleanValue);
                    break;
                case '[':
                case 'L':
                    Object objectValue = fields[i].getField().get(o);
                    writeObjectField(fields[i], objectValue);
                    break;
                default:
                    throw new InvalidClassException(cl.getName());
            }
        } catch (IllegalAccessException exc) {
            throw wrapper.illegalFieldAccess(exc, fields[i].getName());
        }
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.corba.se.impl.io.IIOPOutputStream.writeField(ObjectStreamField, Object)

void writeField(ObjectStreamField field, Object value) throws IOException {
    switch(field.getTypeCode()) {
        case 'B':
            if (value == null) orbStream.write_octet((byte) 0); else orbStream.write_octet(((Byte) value).byteValue());
            break;
        case 'C':
            if (value == null) orbStream.write_wchar((char) 0); else orbStream.write_wchar(((Character) value).charValue());
            break;
        case 'F':
            if (value == null) orbStream.write_float((float) 0); else orbStream.write_float(((Float) value).floatValue());
            break;
        case 'D':
            if (value == null) orbStream.write_double((double) 0); else orbStream.write_double(((Double) value).doubleValue());
            break;
        case 'I':
            if (value == null) orbStream.write_long((int) 0); else orbStream.write_long(((Integer) value).intValue());
            break;
        case 'J':
            if (value == null) orbStream.write_longlong((long) 0); else orbStream.write_longlong(((Long) value).longValue());
            break;
        case 'S':
            if (value == null) orbStream.write_short((short) 0); else orbStream.write_short(((Short) value).shortValue());
            break;
        case 'Z':
            if (value == null) orbStream.write_boolean(false); else orbStream.write_boolean(((Boolean) value).booleanValue());
            break;
        case '[':
        case 'L':
            writeObjectField(field, value);
            break;
        default:
            throw new InvalidClassException(currentClassDesc.getName());
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.corba.se.impl.io.ObjectStreamClass.setClass(Class)

final void setClass(Class cl) throws InvalidClassException {
    if (cl == null) {
        localClassDesc = null;
        ofClass = null;
        computeFieldInfo();
        return;
    }
    localClassDesc = lookupInternal(cl);
    if (localClassDesc == null) throw new InvalidClassException(cl.getName(), 'Local class not compatible');
    if (suid != localClassDesc.suid) {
        boolean addedSerialOrExtern = isNonSerializable() || localClassDesc.isNonSerializable();
        boolean arraySUID = (cl.isArray() && !cl.getName().equals(name));
        if (!arraySUID && !addedSerialOrExtern) {
            throw new InvalidClassException(cl.getName(), 'Local class not compatible:' + ' stream classdesc serialVersionUID=' + suid + ' local class serialVersionUID=' + localClassDesc.suid);
        }
    }
    if (!compareClassNames(name, cl.getName(), '.')) throw new InvalidClassException(cl.getName(), 'Incompatible local class name. ' + 'Expected class name compatible with ' + name);
    if ((serializable != localClassDesc.serializable) || (externalizable != localClassDesc.externalizable) || (!serializable && !externalizable)) throw new InvalidClassException(cl.getName(), 'Serialization incompatible with Externalization');
    ObjectStreamField[] destfield = (ObjectStreamField[]) localClassDesc.fields;
    ObjectStreamField[] srcfield = (ObjectStreamField[]) fields;
    int j = 0;
    nextsrc: for (int i = 0; i < srcfield.length; i++) {
        for (int k = j; k < destfield.length; k++) {
            if (srcfield[i].getName().equals(destfield[k].getName())) {
                if (srcfield[i].isPrimitive() && !srcfield[i].typeEquals(destfield[k])) {
                    throw new InvalidClassException(cl.getName(), 'The type of field ' + srcfield[i].getName() + ' of class ' + name + ' is incompatible.');
                }
                j = k;
                srcfield[i].setField(destfield[j].getField());
                continue nextsrc;
            }
        }
    }
    computeFieldInfo();
    ofClass = cl;
    readObjectMethod = localClassDesc.readObjectMethod;
    readResolveObjectMethod = localClassDesc.readResolveObjectMethod;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass, Class, ClassNotFoundException, ObjectStreamClass)

/**
     * Initializes class descriptor representing a non-proxy class.
     */
void initNonProxy(ObjectStreamClass model, Class cl, ClassNotFoundException resolveEx, ObjectStreamClass superDesc) throws InvalidClassException {
    this.cl = cl;
    this.resolveEx = resolveEx;
    this.superDesc = superDesc;
    name = model.name;
    suid = new Long(model.getSerialVersionUID());
    isProxy = false;
    isEnum = model.isEnum;
    serializable = model.serializable;
    externalizable = model.externalizable;
    hasBlockExternalData = model.hasBlockExternalData;
    hasWriteObjectData = model.hasWriteObjectData;
    fields = model.fields;
    primDataSize = model.primDataSize;
    numObjFields = model.numObjFields;
    if (cl != null) {
        localDesc = lookup(cl, true);
        if (localDesc.isProxy) {
            throw new InvalidClassException('cannot bind non-proxy descriptor to a proxy class');
        }
        if (isEnum != localDesc.isEnum) {
            throw new InvalidClassException(isEnum ? 'cannot bind enum descriptor to a non-enum class' : 'cannot bind non-enum descriptor to an enum class');
        }
        if (serializable == localDesc.serializable && !cl.isArray() && suid.longValue() != localDesc.getSerialVersionUID()) {
            throw new InvalidClassException(localDesc.name, 'local class incompatible: ' + 'stream classdesc serialVersionUID = ' + suid + ', local class serialVersionUID = ' + localDesc.getSerialVersionUID());
        }
        if (!classNamesEqual(name, localDesc.name)) {
            throw new InvalidClassException(localDesc.name, 'local class name incompatible with stream class ' + 'name \'' + name + '\'');
        }
        if (!isEnum) {
            if ((serializable == localDesc.serializable) && (externalizable != localDesc.externalizable)) {
                throw new InvalidClassException(localDesc.name, 'Serializable incompatible with Externalizable');
            }
            if ((serializable != localDesc.serializable) || (externalizable != localDesc.externalizable) || !(serializable || externalizable)) {
                deserializeEx = new InvalidClassException(localDesc.name, 'class invalid for deserialization');
            }
        }
        cons = localDesc.cons;
        writeObjectMethod = localDesc.writeObjectMethod;
        readObjectMethod = localDesc.readObjectMethod;
        readObjectNoDataMethod = localDesc.readObjectNoDataMethod;
        writeReplaceMethod = localDesc.writeReplaceMethod;
        readResolveMethod = localDesc.readResolveMethod;
        if (deserializeEx == null) {
            deserializeEx = localDesc.deserializeEx;
        }
    }
    fieldRefl = getReflector(fields, localDesc);
    fields = fieldRefl.getFields();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectStreamClass.readNonProxy(ObjectInputStream)

/**
     * Reads non-proxy class descriptor information from given input stream.
     * The resulting class descriptor is not fully functional; it can only be
     * used as input to the ObjectInputStream.resolveClass() and
     * ObjectStreamClass.initNonProxy() methods.
     */
void readNonProxy(ObjectInputStream in) throws IOException, ClassNotFoundException {
    name = in.readUTF();
    suid = new Long(in.readLong());
    isProxy = false;
    byte flags = in.readByte();
    hasWriteObjectData = ((flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0);
    hasBlockExternalData = ((flags & ObjectStreamConstants.SC_BLOCK_DATA) != 0);
    externalizable = ((flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0);
    boolean sflag = ((flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0);
    if (externalizable && sflag) {
        throw new InvalidClassException(name, 'serializable and externalizable flags conflict');
    }
    serializable = externalizable || sflag;
    isEnum = ((flags & ObjectStreamConstants.SC_ENUM) != 0);
    if (isEnum && suid.longValue() != 0L) {
        throw new InvalidClassException(name, 'enum descriptor has non-zero serialVersionUID: ' + suid);
    }
    int numFields = in.readShort();
    if (isEnum && numFields != 0) {
        throw new InvalidClassException(name, 'enum descriptor has non-zero field count: ' + numFields);
    }
    fields = (numFields > 0) ? new ObjectStreamField[numFields] : NO_FIELDS;
    for (int i = 0; i < numFields; i++) {
        char tcode = (char) in.readByte();
        String fname = in.readUTF();
        String signature = ((tcode == 'L') || (tcode == '[')) ? in.readTypeString() : new String(new char[] { tcode });
        try {
            fields[i] = new ObjectStreamField(fname, signature, false);
        } catch (RuntimeException e) {
            throw (IOException) new InvalidClassException(name, 'invalid descriptor for field ' + fname).initCause(e);
        }
    }
    computeFieldOffsets();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectStreamClass.computeFieldOffsets()

/**
     * Calculates and sets serializable field offsets, as well as primitive
     * data size and object field count totals.  Throws InvalidClassException
     * if fields are illegally ordered.
     */
private void computeFieldOffsets() throws InvalidClassException {
    primDataSize = 0;
    numObjFields = 0;
    int firstObjIndex = -1;
    for (int i = 0; i < fields.length; i++) {
        ObjectStreamField f = fields[i];
        switch(f.getTypeCode()) {
            case 'Z':
            case 'B':
                f.setOffset(primDataSize++);
                break;
            case 'C':
            case 'S':
                f.setOffset(primDataSize);
                primDataSize += 2;
                break;
            case 'I':
            case 'F':
                f.setOffset(primDataSize);
                primDataSize += 4;
                break;
            case 'J':
            case 'D':
                f.setOffset(primDataSize);
                primDataSize += 8;
                break;
            case '[':
            case 'L':
                f.setOffset(numObjFields++);
                if (firstObjIndex == -1) {
                    firstObjIndex = i;
                }
                break;
            default:
                throw new InternalError();
        }
    }
    if (firstObjIndex != -1 && firstObjIndex + numObjFields != fields.length) {
        throw new InvalidClassException(name, 'illegal field order');
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectStreamClass.matchFields(ObjectStreamField[], ObjectStreamClass)

/**
     * Matches given set of serializable fields with serializable fields
     * obtained from the given local class descriptor (which contain bindings
     * to reflective Field objects).  Returns list of ObjectStreamFields in
     * which each ObjectStreamField whose signature matches that of a local
     * field contains a Field object for that field; unmatched
     * ObjectStreamFields contain null Field objects.  Shared/unshared settings
     * of the returned ObjectStreamFields also reflect those of matched local
     * ObjectStreamFields.  Throws InvalidClassException if unresolvable type
     * conflicts exist between the two sets of fields.
     */
private static ObjectStreamField[] matchFields(ObjectStreamField[] fields, ObjectStreamClass localDesc) throws InvalidClassException {
    ObjectStreamField[] localFields = (localDesc != null) ? localDesc.fields : NO_FIELDS;
    ObjectStreamField[] matches = new ObjectStreamField[fields.length];
    for (int i = 0; i < fields.length; i++) {
        ObjectStreamField f = fields[i], m = null;
        for (int j = 0; j < localFields.length; j++) {
            ObjectStreamField lf = localFields[j];
            if (f.getName().equals(lf.getName())) {
                if ((f.isPrimitive() || lf.isPrimitive()) && f.getTypeCode() != lf.getTypeCode()) {
                    throw new InvalidClassException(localDesc.name, 'incompatible types for field ' + f.getName());
                }
                if (lf.getField() != null) {
                    m = new ObjectStreamField(lf.getField(), lf.isUnshared(), false);
                } else {
                    m = new ObjectStreamField(lf.getName(), lf.getSignature(), lf.isUnshared());
                }
            }
        }
        if (m == null) {
            m = new ObjectStreamField(f.getName(), f.getSignature(), false);
        }
        m.setOffset(f.getOffset());
        matches[i] = m;
    }
    return matches;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectInputStream.readOrdinaryObject(boolean)

/**
     * Reads and returns 'ordinary' (i.e., not a String, Class,
     * ObjectStreamClass, array, or enum constant) object, or null if object's
     * class is unresolvable (in which case a ClassNotFoundException will be
     * associated with object's handle).  Sets passHandle to object's assigned
     * handle.
     */
private Object readOrdinaryObject(boolean unshared) throws IOException {
    if (bin.readByte() != TC_OBJECT) {
        throw new StreamCorruptedException();
    }
    ObjectStreamClass desc = readClassDesc(false);
    desc.checkDeserialize();
    Object obj;
    try {
        obj = desc.isInstantiable() ? desc.newInstance() : null;
    } catch (Exception ex) {
        throw new InvalidClassException(desc.forClass().getName(), 'unable to create instance');
    }
    passHandle = handles.assign(unshared ? unsharedMarker : obj);
    ClassNotFoundException resolveEx = desc.getResolveException();
    if (resolveEx != null) {
        handles.markException(passHandle, resolveEx);
    }
    if (desc.isExternalizable()) {
        readExternalData((Externalizable) obj, desc);
    } else {
        readSerialData(obj, desc);
    }
    handles.finish(passHandle);
    if (obj != null && handles.lookupException(passHandle) == null && desc.hasReadResolveMethod()) {
        Object rep = desc.invokeReadResolve(obj);
        if (rep != obj) {
            handles.setObject(passHandle, obj = rep);
        }
    }
    return obj;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectStreamClass.initProxy(Class, ClassNotFoundException, ObjectStreamClass)

/**
     * Initializes class descriptor representing a proxy class.
     */
void initProxy(Class cl, ClassNotFoundException resolveEx, ObjectStreamClass superDesc) throws InvalidClassException {
    this.cl = cl;
    this.resolveEx = resolveEx;
    this.superDesc = superDesc;
    isProxy = true;
    serializable = true;
    suid = new Long(0);
    fields = NO_FIELDS;
    if (cl != null) {
        localDesc = lookup(cl, true);
        if (!localDesc.isProxy) {
            throw new InvalidClassException('cannot bind proxy descriptor to a non-proxy class');
        }
        name = localDesc.name;
        externalizable = localDesc.externalizable;
        cons = localDesc.cons;
        writeReplaceMethod = localDesc.writeReplaceMethod;
        readResolveMethod = localDesc.readResolveMethod;
        deserializeEx = localDesc.deserializeEx;
    }
    fieldRefl = getReflector(fields, localDesc);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectStreamClass.getDeclaredSerialFields(Class)

/**
     * Returns serializable fields of given class as defined explicitly by a
     * 'serialPersistentFields' field, or null if no appropriate
     * 'serialPersistentFields' field is defined.  Serializable fields backed
     * by an actual field of the class are represented by ObjectStreamFields
     * with corresponding non-null Field objects.  For compatibility with past
     * releases, a 'serialPersistentFields' field with a null value is
     * considered equivalent to not declaring 'serialPersistentFields'.  Throws
     * InvalidClassException if the declared serializable fields are
     * invalid--e.g., if multiple fields share the same name.
     */
private static ObjectStreamField[] getDeclaredSerialFields(Class cl) throws InvalidClassException {
    ObjectStreamField[] serialPersistentFields = null;
    try {
        Field f = cl.getDeclaredField('serialPersistentFields');
        int mask = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL;
        if ((f.getModifiers() & mask) == mask) {
            f.setAccessible(true);
            serialPersistentFields = (ObjectStreamField[]) f.get(null);
        }
    } catch (Exception ex) {
    }
    if (serialPersistentFields == null) {
        return null;
    } else if (serialPersistentFields.length == 0) {
        return NO_FIELDS;
    }
    ObjectStreamField[] boundFields = new ObjectStreamField[serialPersistentFields.length];
    Set fieldNames = new HashSet(serialPersistentFields.length);
    for (int i = 0; i < serialPersistentFields.length; i++) {
        ObjectStreamField spf = serialPersistentFields[i];
        String fname = spf.getName();
        if (fieldNames.contains(fname)) {
            throw new InvalidClassException('multiple serializable fields named ' + fname);
        }
        fieldNames.add(fname);
        try {
            Field f = cl.getDeclaredField(fname);
            if ((f.getType() == spf.getType()) && ((f.getModifiers() & Modifier.STATIC) == 0)) {
                boundFields[i] = new ObjectStreamField(f, spf.isUnshared(), true);
            }
        } catch (NoSuchFieldException ex) {
        }
        if (boundFields[i] == null) {
            boundFields[i] = new ObjectStreamField(fname, spf.getType(), spf.isUnshared());
        }
    }
    return boundFields;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.io.ObjectInputStream.readEnum(boolean)

/**
     * Reads in and returns enum constant, or null if enum type is
     * unresolvable.  Sets passHandle to enum constant's assigned handle.
     */
private Enum readEnum(boolean unshared) throws IOException {
    if (bin.readByte() != TC_ENUM) {
        throw new StreamCorruptedException();
    }
    ObjectStreamClass desc = readClassDesc(false);
    if (!desc.isEnum()) {
        throw new InvalidClassException('non-enum class: ' + desc);
    }
    int enumHandle = handles.assign(unshared ? unsharedMarker : null);
    ClassNotFoundException resolveEx = desc.getResolveException();
    if (resolveEx != null) {
        handles.markException(enumHandle, resolveEx);
    }
    String name = readString(false);
    Enum en = null;
    Class cl = desc.forClass();
    if (cl != null) {
        try {
            en = Enum.valueOf(cl, name);
        } catch (IllegalArgumentException ex) {
            throw (IOException) new InvalidObjectException('enum constant ' + name + ' does not exist in ' + cl).initCause(ex);
        }
        if (!unshared) {
            handles.setObject(enumHandle, en);
        }
    }
    handles.finish(enumHandle);
    passHandle = enumHandle;
    return en;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Comments

Popular posts from this blog

NullPointerException

java.lang.NullPointerException NullPointerException is described in the javadoc comments as: Thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of a null object. Accessing or modifying the field of a null object. Taking the length of null as if it were an array. Accessing or modifying the slots of null as if it were an array. Throwing null as if it were a Throwable value. Applications should throw instances of this class to indicate other illegal uses of the null object. author: unascribed version: 1.19, 12/19/03 since: JDK1.0 Where is this exception thrown? Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown. The message ' java.lang.NullPointerException: ' is thrown within the method: com.sun.corba.se.impl.interceptors.ClientRequestInfoImpl.get_r

Connection refused: No available router to destination

This is a simple symptom-cause-solution blog entry only. I hope these blogs will help fellow administrators. Symptom The following exception occurs in WebLogic server logs. Most likely to occur during WebLogic server start-up, but similar exceptions may occur at other times. java.net.ConnectException: t3://myserver:8000: Destination unreachable; nested exception is: java.net.ConnectException: Connection refused: connect; No available router to destination] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:49) at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:773) at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:363) at weblogic.jndi.Environment.getContext(Environment.java:307) at weblogic.jndi.Environment.getContext(Environment.java:277) Cause This message (Connection refused: connect; No available

SocketException

java.net.SocketException SocketException is described in the javadoc comments as: Thrown to indicate that there is an error in the underlying protocol, such as a TCP error. author: Jonathan Payne version: 1.17, 12/19/03 since: JDK1.0 Where is this exception thrown? Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown. The message ' java.net.SocketException: ... ' is thrown within the method: java.net.ServerSocket.createImpl() The message ' java.net.SocketException: ... ' is thrown within the method: java.net.Socket.createImpl(boolean) The message ' java.net.SocketException: ... ' is thrown within the method: java.net.SocksSocketImpl.connect(SocketAddress, int) The message ' java.net.SocketException: ... ' is thrown within the method: java.net.SocksSocketImpl.socksBind(InetSocketAddress) The message