0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 6323008
0N/A * @summary this test verifies that exception from GetField.get method
0N/A * will be a more comprehensible
0N/A *
0N/A * @author Andrey Ozerov
0N/A *
0N/A */
0N/A
0N/A import java.io.*;
0N/A
0N/A class TwoDPoint implements Serializable {
0N/A
0N/A private double radius;
0N/A private double angle;
0N/A
0N/A private static final ObjectStreamField[] serialPersistentFields = {
0N/A new ObjectStreamField("x", double.class),
0N/A new ObjectStreamField("y", double.class),
0N/A };
0N/A
0N/A public TwoDPoint(double x, double y) {
0N/A this.radius = Math.sqrt(x*x+y*y);
0N/A this.angle = Math.atan2(y, x);
0N/A }
0N/A
0N/A public double getX() {
0N/A return radius * Math.cos(angle);
0N/A }
0N/A
0N/A public double getY() {
0N/A return radius * Math.sin(angle);
0N/A }
0N/A
0N/A public String toString() {
0N/A return "[TwoDPoint:x=" + this.getX() + ", y=" + this.getY() +"]";
0N/A }
0N/A
0N/A private void writeObject(ObjectOutputStream out) throws IOException {
0N/A ObjectOutputStream.PutField fields = out.putFields();
0N/A fields.put("x", radius * Math.cos(angle));
0N/A fields.put("y", radius * Math.sin(angle));
0N/A out.writeFields();
0N/A }
0N/A
0N/A private void readObject(ObjectInputStream in)
0N/A throws ClassNotFoundException, IOException
0N/A {
0N/A ObjectInputStream.GetField fields = in.readFields();
0N/A double x = fields.get("x", 0);
0N/A double y = fields.get("y", 0.0);
0N/A
0N/A radius = Math.sqrt(x*x + y*y);
0N/A angle = Math.atan2(y, x);
0N/A }
0N/A
0N/A }
0N/A
0N/A public class NoSuchFieldClarification {
0N/A private static final String SUBSTRING1 = "x";
0N/A private static final String SUBSTRING2 = int.class.toString();
0N/A
0N/A public static void main(String[] args) throws IOException,
0N/A ClassNotFoundException
0N/A {
0N/A TwoDPoint point = new TwoDPoint(7, 67);
0N/A ByteArrayOutputStream bout = new ByteArrayOutputStream();
0N/A ObjectOutputStream oout = new ObjectOutputStream(bout);
0N/A oout.writeObject(point);
0N/A oout.close();
0N/A byte[] ser = bout.toByteArray();
0N/A ByteArrayInputStream bin = new ByteArrayInputStream(ser);
0N/A ObjectInputStream oin = new ObjectInputStream(bin);
0N/A try {
0N/A point = (TwoDPoint) oin.readObject();
0N/A throw new Error();
0N/A } catch(IllegalArgumentException exc) {
0N/A String msg = exc.getMessage();
0N/A System.err.println("\nOriginal message : " + msg);
0N/A if (msg.trim().toLowerCase().lastIndexOf(SUBSTRING1) > 0 &&
0N/A msg.trim().toLowerCase().lastIndexOf(SUBSTRING2) > 0)
0N/A {
0N/A System.err.println("\nTEST PASSED");
0N/A } else {
0N/A throw new Error();
0N/A }
0N/A }
0N/A }
0N/A }