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

ObjectInputStream.GetField.get returns null instead of handling ClassNotFoundException

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Won't Fix
    • 8, 11, 17
    • None
    • core-libs

    Description

      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
              shadowbug Shadow Bug
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: