FAQ
Hi

I'm trying to serialize my Cayenne entities using JBoss Marshaller, but I
get the following errors (keeping them short as the details are not
important, see further explanation below):

Serverside: java.io.NotActiveException: Fields were never written
...

Clientside: EOFException: Read past end of file
[java] at
org.jboss.marshalling.SimpleDataInput.eofOnRead(SimpleDataInput.java:126)
[java] at
org.jboss.marshalling.SimpleDataInput.readUnsignedByteDirect(SimpleDataInput.java:263)
[java] at
org.jboss.marshalling.SimpleDataInput.readUnsignedByte(SimpleDataInput.java:224)
[java] at
org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
[java] at
org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1677)
[java] at
org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1593)
[java] at
org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1235)
....

While googling the problem I came across this issue:
https://issues.jboss.org/browse/JBMAR-67 indicating what the problem might
be.
I checked the Cayenne source and CayenneDataObject do indeed implement
private void writeObject(ObjectOutputStream stream), but does NOT call
defaultWriteObject or writeFields and I think this is the problem.
According to this<http://docs.oracle.com/javase/6/docs/platform/serialization/spec/output.html#861>writeObject
MUST call defaultWriteObject or writeFields once. Is this a bug
in Cayenne or is this actually intentional? Or am I misunderstanding what
is happening here?

I've searched in Jira, but can't find anything related to this. Has anyone
experienced this problem before, and is there a way around this?


-Erlend

Search Discussions

  • Andrus Adamchik at Mar 4, 2012 at 11:56 pm
    You might be right indeed. Cayenne serialization behavior was implemented based on the description from java.io.Serializable javadocs, which does not mention a call to 'defaultWriteObject' as required. So it is skipped... Sure enough that has never caused us any problems with the JDK (there's lots of serialization tests in our unit test suite).

    But of course alternative serialization solutions are free to complain about this behavior, and that seems to be the case with River marshaller.

    Appreciate if you can open a bug report in Cayenne Jira. I think we can fix it...

    Andrus


    On Feb 29, 2012, at 7:05 PM, Erlend Birkenes wrote:
    Hi

    I'm trying to serialize my Cayenne entities using JBoss Marshaller, but I
    get the following errors (keeping them short as the details are not
    important, see further explanation below):

    Serverside: java.io.NotActiveException: Fields were never written
    ...

    Clientside: EOFException: Read past end of file
    [java] at
    org.jboss.marshalling.SimpleDataInput.eofOnRead(SimpleDataInput.java:126)
    [java] at
    org.jboss.marshalling.SimpleDataInput.readUnsignedByteDirect(SimpleDataInput.java:263)
    [java] at
    org.jboss.marshalling.SimpleDataInput.readUnsignedByte(SimpleDataInput.java:224)
    [java] at
    org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
    [java] at
    org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1677)
    [java] at
    org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1593)
    [java] at
    org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1235)
    ....

    While googling the problem I came across this issue:
    https://issues.jboss.org/browse/JBMAR-67 indicating what the problem might
    be.
    I checked the Cayenne source and CayenneDataObject do indeed implement
    private void writeObject(ObjectOutputStream stream), but does NOT call
    defaultWriteObject or writeFields and I think this is the problem.
    According to this<http://docs.oracle.com/javase/6/docs/platform/serialization/spec/output.html#861>writeObject
    MUST call defaultWriteObject or writeFields once. Is this a bug
    in Cayenne or is this actually intentional? Or am I misunderstanding what
    is happening here?

    I've searched in Jira, but can't find anything related to this. Has anyone
    experienced this problem before, and is there a way around this?


    -Erlend
  • Erlend Birkenes at Mar 5, 2012 at 11:54 am
    Hi Andrus

    2012/3/5 Andrus Adamchik <andrus@objectstyle.org>
    You might be right indeed. Cayenne serialization behavior was implemented
    based on the description from java.io.Serializable javadocs, which does not
    mention a call to 'defaultWriteObject' as required. So it is skipped...
    Sure enough that has never caused us any problems with the JDK (there's
    lots of serialization tests in our unit test suite).
    Yeah, I ended up building my own version of River commenting out just the
    lines (in RiverObjectOutputStream and RiverObjectInputStream) where the
    exception is thrown and it works just fine.

    But of course alternative serialization solutions are free to complain
    about this behavior, and that seems to be the case with River marshaller.
    Yes, that is the case, and I'm not sure what is the correct way to do this.
    I'm leaning more and more towards that River is way too strict on this.
    There is probably a reason this is only in the spec and not strictly
    enforced anywhere else.
    The spec says: "the behavior of instance deserialization is undefined in
    cases where the ObjectInputStream cannot resolve the class which defined
    the writeObject method". I don't know which cases those are, but this is
    not one of them. It works fine in Cayenne when I disable the exceptions. As
    you said, the Serializable javadoc says that you CAN invoke
    defaultWriteObject, not that you must. This is all very vague and I'm not
    sure the interpretation used by River is correct.
    I've not been able to find any other libraries where this is a problem so
    I'm thinking that this is actually more of a River problem, even though it
    might be technically correct. One thing to consider is that River is doing
    marshalling, which apparently is slightly different from serialization, but
    the actual difference is not clear to me. I don't know if that is important.

    Appreciate if you can open a bug report in Cayenne Jira. I think we can
    fix it...
    I can do that, but I'm not yet sure that it is a Cayenne problem. Cayenne
    tries to serialize only the ObjectId if possible, and by calling
    defaultWriteObject wouldn't you lose that functionality? Wouldn't it then
    serialize all the fields every time? I don't think we want that. Or did you
    have another solution in mind?


    -Erlend
  • Durchholz, Joachim at Mar 5, 2012 at 12:27 pm

    One thing to consider is that River is doing marshalling,
    which apparently is slightly different from serialization,
    In my book, they are both the same: convert an object to an untyped data (byte/word/whatever) stream and back, restoring the original functionality of the serialized/marshalled object.
    but the actual difference is not clear to me. I don't know if that is important.
    That depends on what the definitions are in River's book.
    It looks like River isn't spelling these out clearly enough.
  • Erlend Birkenes at Mar 5, 2012 at 1:55 pm
    2012/3/5 Durchholz, Joachim <Joachim.Durchholz@hennig-fahrzeugteile.de>
    One thing to consider is that River is doing marshalling,
    which apparently is slightly different from serialization,
    In my book, they are both the same: convert an object to an untyped data
    (byte/word/whatever) stream and back, restoring the original functionality
    of the serialized/marshalled object.
    but the actual difference is not clear to me. I don't know if that is
    important.

    That depends on what the definitions are in River's book.
    It looks like River isn't spelling these out clearly enough.
    Yeah, I agree on that. I will take this up with the River people and see
    what they say about it.

    -Erlend
  • Andrus Adamchik at Mar 5, 2012 at 1:40 pm

    On Mar 5, 2012, at 6:53 AM, Erlend Birkenes wrote:



    Appreciate if you can open a bug report in Cayenne Jira. I think we can
    fix it...
    I can do that, but I'm not yet sure that it is a Cayenne problem. Cayenne
    tries to serialize only the ObjectId if possible, and by calling
    defaultWriteObject wouldn't you lose that functionality? Wouldn't it then
    serialize all the fields every time? I don't think we want that. Or did you
    have another solution in mind?
    I think I we can achieve compliant serialization behavior by using "transient" on fields that are serialized manually. But yeah, this is certainly low priority, especially since you've found a workaround.

    Andrus
  • Erlend Birkenes at Mar 5, 2012 at 2:02 pm
    2012/3/5 Andrus Adamchik <andrus@objectstyle.org>
    I think I we can achieve compliant serialization behavior by using
    "transient" on fields that are serialized manually.

    Yes, I think that is probably the "correct" way to do this. I think that is
    what the spec means by "optional fields".

    But yeah, this is certainly low priority, especially since you've found a
    workaround.
    Agreed, even though I don't feel having to build a custom jar is a good
    workaround, but it will do for right now.
    I'll take this up with the River developers and I can create a Jira issue
    after that if necessary.

    -Erlend

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedMar 1, '12 at 12:06a
activeMar 5, '12 at 2:02p
posts7
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase