public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
From: "bonniot at users dot sf dot net" <gcc-bugzilla@gcc.gnu.org>
To: java-prs@gcc.gnu.org
Subject: [Bug java/20169] New: Serialization: readResolve does not work
Date: Wed, 23 Feb 2005 16:06:00 -0000	[thread overview]
Message-ID: <20050223152937.20169.bonniot@users.sf.net> (raw)

I attach a simple Java class, which exercises the readResolve method. An object
is serialzed and deserialized from a byte array. Because of the readResolve
method, the object read back should be the exact same instance. This works with
JDK, but fails with both gij and gcj, as of today. It also fails with other free
runtimes: kaffe (1.1.4.PRECVS8) and jamvm (1.2.3), so it could be a GNU
classpath issue.

Here is the testcase:
///////////////////////////////////

import java.io.*;

public abstract class Enum implements Serializable
{
  static Enum instance;

  Object readResolve() {
    return instance;
  }

  static class Color extends Enum
  {
    static final Color red = new Color();

    static { instance = red; }
  }

  public static void main(String[] args)
  {
    try {
      ByteArrayOutputStream outb = new ByteArrayOutputStream();
      ObjectOutputStream outs = new ObjectOutputStream(outb);
      outs.writeObject(Color.red);
      byte[] store = outb.toByteArray();

      ByteArrayInputStream inb = new ByteArrayInputStream(store);
      ObjectInputStream ins = new ObjectInputStream(inb);

      Color color = (Color) ins.readObject();
      System.out.println(color);
      System.out.println(Color.red);
      System.out.println(color == Color.red);
    }
    catch (Throwable e) {
      throw new Error(e);
    }
  }
}
//////////////////////////////////////

Here is what happens:

/tmp/gcc/bin/gcj -C Enum.java

#### JDK: java Enum
Enum$Color@1cfb549
Enum$Color@1cfb549
true

#### GIJ: LD_LIBRARY_PATH=/tmp/gcc/lib /tmp/gcc/bin/gij Enum
Enum$Color@58c78
Enum$Color@58eb8
false

#### GCJ: /tmp/gcc/bin/gcj --main=Enum *.class
LD_LIBRARY_PATH=/tmp/gcc/lib ./a.out
Enum$Color@58cd0
Enum$Color@58f20
false
/tmp/gcc/bin/gcj --version
gcj (GCC) 4.0.0 20050223 (experimental)

-- 
           Summary: Serialization: readResolve does not work
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bonniot at users dot sf dot net
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org
  GCC host triplet: i386-debian-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20169


             reply	other threads:[~2005-02-23 15:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-23 16:06 bonniot at users dot sf dot net [this message]
2005-02-23 16:38 ` [Bug libgcj/20169] " pinskia at gcc dot gnu dot org
2005-02-28 13:08 ` bonniot at users dot sf dot net
2005-03-03  2:51 ` bonniot at users dot sf dot net
2005-05-27  1:04 ` pinskia at gcc dot gnu dot org
2005-05-27  9:47 ` bonniot at users dot sf dot net
2005-05-27 15:05 ` bonniot at users dot sf dot net
2005-06-01 20:01 ` tromey at gcc dot gnu dot org
2005-07-24 19:36 ` tromey at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050223152937.20169.bonniot@users.sf.net \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=java-prs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).