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

java.io.StreamCorruptedException thrown due to java.lang.ClassNotFoundException

XMLWordPrintable

    • 07
    • generic
    • generic
    • Verified

        Many of us have came across lot of crs that has StreamCorruptedExceptions from the following code in java.io.ObjectInputStream:

                 private ObjectStreamClass readNonProxyDesc(boolean unshared)
                 throws IOException
                 {
                 if (bin.readByte() != TC_CLASSDESC) {
                     throw new StreamCorruptedException();
                 }

                 ObjectStreamClass desc = new ObjectStreamClass();
                 int descHandle = handles.assign(unshared ? unsharedMarker : desc);
                 passHandle = NULL_HANDLE;

                 ObjectStreamClass readDesc = null;
                 try {
                     readDesc = readClassDescriptor();
                 } catch (ClassNotFoundException ex) {
                     // REMIND: do something less drastic here?
                     throw new StreamCorruptedException();
                 }

                 Class cl = null;
                 ClassNotFoundException resolveEx = null;
                 bin.setBlockDataMode(true);
                 try {
                     if ((cl = resolveClass(readDesc)) == null) {
                     throw new ClassNotFoundException("null class");
                     }
                 } catch (ClassNotFoundException ex) {
                     resolveEx = ex;
                 }
                 skipCustomData();

                 desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false));

                 handles.finish(descHandle);
                 passHandle = descHandle;
                 return desc;
                 }

        I highligted the place where it is throwing StreamCorruptedException. It is throwing StreamCorruptedException when it gets ClassNotFoundException while reading ClassDescriptor. Many of us actually gone through crs that has StreamCorruptedExceptions from this code and we were little confused intially that why we would experience this exception. Later on after looking at the code we realized that it is result of ClassCastException.

        There is also a reminder that says 'do something less drastic here'. This wasn't like this in 1.3.1_x. In 1.3.1_x, it is using inputClassDescriptor() method and that method throws ClassNotFoundException. From 1.4.1 onwards they changed the code and calling this readNonProxyDesc() method and it doesn't have ClassNotFoundException in the throws class and hence they are throwing StreamCorruptedExceptions.

        crs -> customer complaints received by BEA

              mwarressunw Michael Warres (Inactive)
              gnagasunsunw Gopinath Nagasundara (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: