test/java/io/Serializable/NPEProvoker/NPEProvoker.java

Print this page
rev 3186 : 6880112: Project Coin: Port JDK core library code to use diamond operator


  39 import java.io.ObjectOutput;
  40 import java.io.ObjectOutputStream;
  41 import java.util.ArrayList;
  42 
  43 public class NPEProvoker implements java.io.Externalizable {
  44     private String test = "test";
  45 
  46     public void readExternal(ObjectInput in) throws IOException,
  47         ClassNotFoundException
  48     {
  49         throw new IOException(); //io exception for whatever reason
  50     }
  51 
  52     public void writeExternal(ObjectOutput out) throws IOException {
  53         out.writeObject(test);
  54     }
  55 
  56     public static void main(String[] args) {
  57         System.err.println("\n Regression test for bug 6541870\n");
  58         try {
  59             ArrayList<NPEProvoker> list = new ArrayList<NPEProvoker>();
  60             list.add(new NPEProvoker());
  61             ByteArrayOutputStream baos = new ByteArrayOutputStream();
  62             ObjectOutputStream oos = new ObjectOutputStream(baos);
  63             oos.writeObject(list);
  64 
  65             ObjectInputStream ois =
  66                 new ObjectInputStream(new ByteArrayInputStream(
  67                 baos.toByteArray()));
  68             ois.readObject();
  69             throw new Error();
  70         } catch (IOException e) {
  71             System.err.println("\nTEST PASSED");
  72         } catch (ClassNotFoundException e) {
  73             throw new Error();
  74         } catch (NullPointerException e) {
  75             throw new Error();
  76         }
  77     }
  78 }


  39 import java.io.ObjectOutput;
  40 import java.io.ObjectOutputStream;
  41 import java.util.ArrayList;
  42 
  43 public class NPEProvoker implements java.io.Externalizable {
  44     private String test = "test";
  45 
  46     public void readExternal(ObjectInput in) throws IOException,
  47         ClassNotFoundException
  48     {
  49         throw new IOException(); //io exception for whatever reason
  50     }
  51 
  52     public void writeExternal(ObjectOutput out) throws IOException {
  53         out.writeObject(test);
  54     }
  55 
  56     public static void main(String[] args) {
  57         System.err.println("\n Regression test for bug 6541870\n");
  58         try {
  59             ArrayList<NPEProvoker> list = new ArrayList<>();
  60             list.add(new NPEProvoker());
  61             ByteArrayOutputStream baos = new ByteArrayOutputStream();
  62             ObjectOutputStream oos = new ObjectOutputStream(baos);
  63             oos.writeObject(list);
  64 
  65             ObjectInputStream ois =
  66                 new ObjectInputStream(new ByteArrayInputStream(
  67                 baos.toByteArray()));
  68             ois.readObject();
  69             throw new Error();
  70         } catch (IOException e) {
  71             System.err.println("\nTEST PASSED");
  72         } catch (ClassNotFoundException e) {
  73             throw new Error();
  74         } catch (NullPointerException e) {
  75             throw new Error();
  76         }
  77     }
  78 }