Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8277093

Vector should throw ClassNotFoundException for a missing class of an element

    XMLWordPrintable

Details

    Backports

      Description

        Java.util.Vector reports a StreamCorruptedException instead of ClassNotFoundException due to the incorrect handling of a missing class by ObjectInputStream.GetField.get(name, val).
        Vector checks the deserialized 'data' field for null and throws StreamCorruptedException.
        The null can be a reflection of more than one condition, including the field is null, the field is not present in the stream, and the field is null because one of the array elements could not be deserialized due to a missing class.
        The first two cases reflect a corrupted stream but the third should be treated as ClassNotFoundException.

        Currently, there is a bug in ObjectInputStream.FieldValues.get(name, val).

                public Object get(String name, Object val) {
                    int off = getFieldOffset(name, Object.class);
                    if (off >= 0) {
                        int objHandle = objHandles[off];
                        handles.markDependency(passHandle, objHandle);
                        return (handles.lookupException(objHandle) == null) ?
                            objValues[off] : null;
                    } else {
                        return val;
                    }

        Here, a call to handles.lookupException is made, however rather than throwing the associated exception, the method simply returns null.

        This is causing ClassNotFoundExceptions to be buried by the stack and the exception being thrown further up the stack by the caller of the method.

        The method signature for FieldValues.get cannot be changed. However, given that FieldValues implements the GetField interface, the GetField.get(name, value) method throws an IOException.

        The CNFE exception could be wrapped in an IOException and get thrown here, rather than incorrectly further up the stack.

        Attachments

          Issue Links

            Activity

              People

                rriggs Roger Riggs
                rriggs Roger Riggs
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: