Loading ...
Sorry, an error occurred while loading the content.

Re: [JSX-ideas] enums

Expand Messages
  • Brendan Macmillan
    Hi Steve, Thanks for the bug report on enums. I bet that if you serialize two instances in the same XML, then the == comparison will work correctly. ... The
    Message 1 of 10 , Aug 1, 2001
    • 0 Attachment
      Hi Steve,

      Thanks for the bug report on enums. I bet that if you serialize two
      instances in the same XML, then the == comparison will work correctly.

      > XML is <Suit
      > name="clubs"
      > ordinal="0"/>
      >
      > # Incidently, Suits is a supposedly type-safe "enumeration" type, taken
      > # the new book "Effective Java" by Joshua Bloch. One of the claims
      > # is that comparisons of type-safe enums can be done with == (efficient)
      > # instead of .equals (slow). However this doesn't work when an
      > # Object of type Suit is converted to/from XML using JSX. [I'd love
      > # a fix, if you're interested in looking at this (will send code if
      > # you are...)!]

      The difficulty is when you compare a deserialized one with another one. It
      is caused by JSX creating a new object for those that are deserialized, while
      the enum idea relies on them being the same object.

      The standard solution to this is to include some serialization code in the
      enum class, using the readResolve() method, so that instead of creating a
      new one, it always returns a particular instance. In this way, the ==
      comparison will work.

      There are two issues:
      (1). without readResolve, Java's own serialization will have the same problem
      you outline. You could check this.
      (2). Unfortunately, JSX does not presently implement readResolve(), so it
      wouldn't work anyway. It doesn't look hard to do, but there are several
      other priorities at the moment. It will happen. ;-)

      I would like to have a look at the code - but it will still take quite a while
      before I can actually do anything about it, unfortunately.

      See next reply for the 1.4 issue.


      Cheers,
      Brendan
      --
      e: bren@... v: +61 (3) 9905 1502
      Email is checked daily Phone is rarely attended
    • Brendan Macmillan
      ... I already have some working test code, that makes allocateNewObject work in 1.4. Again, it is just a delay problem. Sorry. Maybe in a week or two? I
      Message 2 of 10 , Aug 1, 2001
      • 0 Attachment
        > java.lang.NoSuchMethodException: allocateNewObject

        > Do you expect to support 1.4 soon? (I need 1.4 for other reasons...)
        I already have some working test code, that makes allocateNewObject work in
        1.4. Again, it is just a delay problem. Sorry. Maybe in a week or two?

        I think if I just keep my head down, it won't take too long.

        How necessary is it to use 1.4? I've been thinking that because it is still
        beta, I was safe in leaving it for a while?


        Cheers,
        Brendan
        --
        e: bren@... v: +61 (3) 9905 1502
        Email is checked daily Phone is rarely attended
      • kaadouh@hotmail.com
        Hello, It is the first time I participate in a group discussion. I am in Paris France. And our application is going to support jdk1.4, so I am having major
        Message 3 of 10 , Nov 14, 2001
        • 0 Attachment
          Hello,

          It is the first time I participate in a group discussion. I am in
          Paris France. And our application is going to support jdk1.4, so I am
          having major problems especially with allocateNewObject.

          This is the only way of initializing some types of serializable
          object for deserialization, any classes without no-args constructors
          cannot be initialized but for this function.

          Please, can you help me and tell me if you have found the equivalent
          JDK1.4 methods

          Thank You

          Anie
        • bren@mail.csse.monash.edu.au
          Hi Anie, ... Welcome! ... Yes, I have. They are pretty much identical - I have some prototype code somewhere that demonstrates it. I haven t yet looked for
          Message 4 of 10 , Nov 14, 2001
          • 0 Attachment
            Hi Anie,

            > It is the first time I participate in a group discussion. I am in
            > Paris France.
            Welcome!

            > ...major problems especially with allocateNewObject.

            > Please, can you help me and tell me if you have found the
            > equivalent JDK1.4 methods
            Yes, I have. They are pretty much identical - I have some prototype
            code somewhere that demonstrates it.

            I haven't yet looked for the code to support setting final fields
            (primitive and object) - this should be harder, but I think will be
            OK.

            The only reason I haven't done it yet is the lack of demand... and
            also the (reasonable) fear that Sun might some of it, since it is
            still in Beta... ;-) I have a lot of other stuff to work on, that
            I think is more important at the moment.

            BTW: is your product for distribution?


            Cheers,
            Brendan
          • kaadouh@hotmail.com
            Thank you Brendan for answering me! Here is my code and I need to substitute the call to allocateNewObject private static Method _newMethod; static { Class[]
            Message 5 of 10 , Nov 14, 2001
            • 0 Attachment
              Thank you Brendan for answering me!

              Here is my code and I need to substitute the call
              to "allocateNewObject"

              private static Method _newMethod;

              static {
              Class[] parameterTypes = new Class[2];

              try {
              parameterTypes[0] = Class.class;
              parameterTypes[1] = Class.class;
              _newMethod = ObjectInputStream.class.
              getDeclaredMethod("allocateNewObject",
              parameterTypes);
              _newMethod.setAccessible(true);

              }
              catch (Exception ex) {
              ex.printStackTrace();
              }
              }

              Can you send me please the prototye code where you replace the call
              to allocateNewObject


              A+
              Anie
            • kaadouh@hotmail.com
              Our product is already distributed (I mean it is with the clients). But a client has asked to have a version with jdk1.4 (we cannot go against progress) Hope I
              Message 6 of 10 , Nov 14, 2001
              • 0 Attachment
                Our product is already distributed (I mean it is with the clients).
                But a client has asked to have a version with jdk1.4 (we cannot go
                against progress)

                Hope I am clear (because of my french)

                Best regards,
                Anie
              • bren@mail.csse.monash.edu.au
                Thanks Anie, ... Are you using JSX in your product? Or is it just that you want to use the allocate magic? ... Yes, no problem Cheers, Brendan
                Message 7 of 10 , Nov 14, 2001
                • 0 Attachment
                  Thanks Anie,

                  > Our product is already distributed (I mean it is with the clients).
                  > But a client has asked to have a version with jdk1.4 (we cannot go
                  > against progress)

                  Are you using JSX in your product? Or is it just that you want to
                  use the allocate magic?

                  > Hope I am clear (because of my french)
                  Yes, no problem

                  Cheers,
                  Brendan
                • kaadouh@hotmail.com
                  Hi Brendan, No we aren t using JSX in our product. I just need to use the allocate magic. Good day Anie ... clients). ... go
                  Message 8 of 10 , Nov 15, 2001
                  • 0 Attachment
                    Hi Brendan,

                    No we aren't using JSX in our product. I just need to use the
                    allocate magic.

                    Good day

                    Anie

                    --- In JSX-ideas@y..., bren@m... wrote:
                    > Thanks Anie,
                    >
                    > > Our product is already distributed (I mean it is with the
                    clients).
                    > > But a client has asked to have a version with jdk1.4 (we cannot
                    go
                    > > against progress)
                    >
                    > Are you using JSX in your product? Or is it just that you want to
                    > use the allocate magic?
                    >
                    > > Hope I am clear (because of my french)
                    > Yes, no problem
                    >
                    > Cheers,
                    > Brendan
                  • bren@mail.csse.monash.edu.au
                    Hi Anie, ... This mailing list is for JSX, and as you can see from the other posts, I pretty much have my hands full with JSX at the moment. I don t want to
                    Message 9 of 10 , Nov 15, 2001
                    • 0 Attachment
                      Hi Anie,

                      > No we aren't using JSX in our product. I just need to use the
                      > allocate magic.

                      This mailing list is for JSX, and as you can see from the other
                      posts, I pretty much have my hands full with JSX at the moment. I
                      don't want to take time away from that to help you with unrelated
                      issues. Please try one of the general Java lists.

                      Right now, JSX is in critical period of development - check the
                      other posts if you're not sure what I mean.


                      Cheers,
                      Brendan
                    Your message has been successfully submitted and would be delivered to recipients shortly.