jdk/test/java/net/Inet6Address/serialize/Serialize.java
changeset 902 bbfb1e2369b2
parent 2 90ce3da70b43
child 1247 b4c26443dee5
equal deleted inserted replaced
901:7c3638e8ff31 902:bbfb1e2369b2
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 4921029
    26  * @bug 4921029
       
    27  * @bug 6656849
    27  * @summary  java.net.Inet6Address fails to be serialized with IPv6 support
    28  * @summary  java.net.Inet6Address fails to be serialized with IPv6 support
       
    29  * @summary  NullPointerException thrown while de-serializing IPV6 Address.
    28  */
    30  */
    29 
    31 
    30 import java.net.*;
    32 import java.net.*;
    31 import java.io.*;
    33 import java.io.*;
    32 import java.util.*;
    34 import java.util.*;
    74             throw new RuntimeException ("old ::1 not deserialized right");
    76             throw new RuntimeException ("old ::1 not deserialized right");
    75          }
    77          }
    76 
    78 
    77          System.out.println(nobj);
    79          System.out.println(nobj);
    78 
    80 
    79         // create an address with an unlikely numeric scope_id
    81          // create an address with an unlikely numeric scope_id
    80         if (!test ((Inet6Address)InetAddress.getByName ("fe80::1%99"))) {
    82          if (!test ((Inet6Address)InetAddress.getByName ("fe80::1%99"))) {
    81             throw new RuntimeException ("test failed on fe80::1%99");
    83              throw new RuntimeException ("test failed on fe80::1%99");
    82         }
    84          }
    83 
    85 
       
    86          // Deserialize an Inet6 address with a named interface
       
    87          file = new File (System.getProperty("test.src"), "serial-bge0.ser");
       
    88          ois = new ObjectInputStream(new FileInputStream(file));
       
    89          try {
       
    90              nobj = (Inet6Address) ois.readObject();
       
    91          } catch (NullPointerException e) {
       
    92              throw new RuntimeException("6656849 Not fixed: NullPointer when deserializing");
       
    93          }
       
    94          System.out.println(nobj);
    84          System.out.println("All tests passed");
    95          System.out.println("All tests passed");
    85      }
    96      }
    86 
    97 
    87      static boolean test (Inet6Address obj) throws Exception {
    98      static boolean test (Inet6Address obj) throws Exception {
    88          ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("i6a1.ser"));
    99          ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("i6a1.ser"));
    95          if (nobj.equals(obj)) {
   106          if (nobj.equals(obj)) {
    96              return true;
   107              return true;
    97          } else {
   108          } else {
    98              return false;
   109              return false;
    99          }
   110          }
   100 
       
   101 
       
   102      }
   111      }
   103 
       
   104  }
   112  }