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

java.io.ObjectInputStream.registerValidation() doesn't throw NotActiveException

    XMLWordPrintable

    Details

      Description



      Name: ooR10001 Date: 01/17/2001


      java.io.ObjectInputStream.registerValidation() doesn't throw NotActiveException when it is
      invoked for a stream which is not currently reading objects. Such behavior contradicts to current
      javadoc.

      The javadoc says:
      ------------------------
      registerValidation
      ............................

            Throws:
                  NotActiveException - The stream is not currently reading objects so it is invalid to
                  register a callback.
       ..................
      ------------------------

      This sample is showing a bug:
      ---------------------------------
      import java.io.*;

      class ValidObj implements Serializable, ObjectInputValidation {

          transient boolean validated = false;

          public ValidObj() {}
       
          public void validateObject() throws InvalidObjectException {
              validated = true;
          }

          public boolean isValidated() {
              return validated;
          }
      }

      public class test {

        public static void main(String[] args) {
          try {
              ByteArrayOutputStream b = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(b);
              oos.writeObject(new String("test"));
              oos.close();
              ByteArrayInputStream bais = new ByteArrayInputStream(b.toByteArray());
              ObjectInputStream ois = new ObjectInputStream(bais);
              ois.registerValidation(new ValidObj(), 0);
              System.out.println("NotActiveException is not thrown");
          } catch (NotActiveException e) {
              System.out.println("OKAY");
          } catch (Exception e) {
          }
        }

      }
      ---------------------------------

      Output:
      -----------------------------------
      NotActiveException is not thrown
      -----------------------------------

      It needs to be fixed.

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mwarressunw Michael Warres (Inactive)
              Reporter:
              oovsunw Oov Oov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: