You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Andrew Zhang <zh...@gmail.com> on 2006/11/12 17:30:55 UTC

[classlib][sql] SerialJavaObject constructor throws SerialException when the object is unserializable?

Hi folks,

I'm confused by javax.sql.rowset.serial.SerialJavaObject spec. The spec of
SerialJavaObject constructor says "throws SerialException if the object is
found to be unserializable". It also mentions "Static or transient fields
cannot be serialized; an attempt to serialize them will result in a
SerialException object being thrown. ". Does it mean to throw
SerialException if the object doesn't implement Serializable or it contains
static/transient fields? I tried some tests[1], but SerialException is never
thrown. Am I missing something? Thank you in advance for your help!

[1] SerialJavaObject constructor test case:
 public void test_Constructor() throws Exception {
  Object obj = new NonSerializableClass();
  SerialJavaObject sjo = new SerialJavaObject(obj);
 }

 static class NonSerializableClass {
  public static int i;
  public static Thread t;
  public transient String s;
  NonSerializableClass() {

  }
 }

-- 
Best regards,
Andrew Zhang

Re: [classlib][sql] SerialJavaObject constructor throws SerialException when the object is unserializable?

Posted by Andrew Zhang <zh...@gmail.com>.
On 11/13/06, Mikhail Loenko <ml...@gmail.com> wrote:
>
> I guess that Sun has implemented some behavior and some exception
> could be thrown by that implementation. Then they wrapped that exception
> by SerialException and documented in the spec ;)
>
> You might want to implement it without exception throwing and if we find
> an
> inconsistency later -- fix it


The first version implementation is attached to JIRA Harmony-2277. Thanks!

Thanks,
> Mikhail
>
> 2006/11/12, Andrew Zhang <zh...@gmail.com>:
> > Hi folks,
> >
> > I'm confused by javax.sql.rowset.serial.SerialJavaObject spec. The spec
> of
> > SerialJavaObject constructor says "throws SerialException if the object
> is
> > found to be unserializable". It also mentions "Static or transient
> fields
> > cannot be serialized; an attempt to serialize them will result in a
> > SerialException object being thrown. ". Does it mean to throw
> > SerialException if the object doesn't implement Serializable or it
> contains
> > static/transient fields? I tried some tests[1], but SerialException is
> never
> > thrown. Am I missing something? Thank you in advance for your help!
> >
> > [1] SerialJavaObject constructor test case:
> >  public void test_Constructor() throws Exception {
> >  Object obj = new NonSerializableClass();
> >  SerialJavaObject sjo = new SerialJavaObject(obj);
> >  }
> >
> >  static class NonSerializableClass {
> >  public static int i;
> >  public static Thread t;
> >  public transient String s;
> >  NonSerializableClass() {
> >
> >  }
> >  }
> >
> > --
> > Best regards,
> > Andrew Zhang
> >
> >
>



-- 
Best regards,
Andrew Zhang

Re: [classlib][sql] SerialJavaObject constructor throws SerialException when the object is unserializable?

Posted by Andrew Zhang <zh...@gmail.com>.
On 11/17/06, Alexei Zakharov <al...@gmail.com> wrote:
>
> Hi,
>
> It is interesting question. What are advantages of such serialization
> model?


I dunno, but the spec maker knows. :)

IMHO majority of Java classes in the world have static fields.
> :-) What are usage patterns of this class?


Thanks,
>
> 2006/11/16, Andrew Zhang <zh...@gmail.com>:
> > On 11/13/06, Mikhail Loenko <ml...@gmail.com> wrote:
> > >
> > > I guess that Sun has implemented some behavior and some exception
> > > could be thrown by that implementation.
> >
> >
> > Sorry for my late reply... Just back from travelling. :)
> >
> > I don't quite get the point. What does "that implementation" mean? Is it
> > invoked in SerialJavaObject constructor?
> >
> > Then they wrapped that exception
> > > by SerialException and documented in the spec ;)
> > >
> > > You might want to implement it without exception throwing and if we
> find
> > > an
> > > inconsistency later -- fix it
> >
> >
> > ya, I'd like to follow this way. If we find any problem, fix it then.
> :-)
> >
> > If no one objects, I'll ignore static/transient check in the
> constructor.
> > Thanks!
> >
> > Thanks,
> > > Mikhail
> > >
> > > 2006/11/12, Andrew Zhang <zh...@gmail.com>:
> > > > Hi folks,
> > > >
> > > > I'm confused by javax.sql.rowset.serial.SerialJavaObject spec. The
> spec
> > > of
> > > > SerialJavaObject constructor says "throws SerialException if the
> object
> > > is
> > > > found to be unserializable". It also mentions "Static or transient
> > > fields
> > > > cannot be serialized; an attempt to serialize them will result in a
> > > > SerialException object being thrown. ". Does it mean to throw
> > > > SerialException if the object doesn't implement Serializable or it
> > > contains
> > > > static/transient fields? I tried some tests[1], but SerialException
> is
> > > never
> > > > thrown. Am I missing something? Thank you in advance for your help!
> > > >
> > > > [1] SerialJavaObject constructor test case:
> > > >  public void test_Constructor() throws Exception {
> > > >  Object obj = new NonSerializableClass();
> > > >  SerialJavaObject sjo = new SerialJavaObject(obj);
> > > >  }
> > > >
> > > >  static class NonSerializableClass {
> > > >  public static int i;
> > > >  public static Thread t;
> > > >  public transient String s;
> > > >  NonSerializableClass() {
> > > >
> > > >  }
> > > >  }
>
>
> --
> Alexei Zakharov,
> Intel Enterprise Solutions Software Division
>



-- 
Best regards,
Andrew Zhang

Re: [classlib][sql] SerialJavaObject constructor throws SerialException when the object is unserializable?

Posted by Alexei Zakharov <al...@gmail.com>.
Hi,

It is interesting question. What are advantages of such serialization
model? IMHO majority of Java classes in the world have static fields.
:-) What are usage patterns of this class?

Thanks,

2006/11/16, Andrew Zhang <zh...@gmail.com>:
> On 11/13/06, Mikhail Loenko <ml...@gmail.com> wrote:
> >
> > I guess that Sun has implemented some behavior and some exception
> > could be thrown by that implementation.
>
>
> Sorry for my late reply... Just back from travelling. :)
>
> I don't quite get the point. What does "that implementation" mean? Is it
> invoked in SerialJavaObject constructor?
>
> Then they wrapped that exception
> > by SerialException and documented in the spec ;)
> >
> > You might want to implement it without exception throwing and if we find
> > an
> > inconsistency later -- fix it
>
>
> ya, I'd like to follow this way. If we find any problem, fix it then. :-)
>
> If no one objects, I'll ignore static/transient check in the constructor.
> Thanks!
>
> Thanks,
> > Mikhail
> >
> > 2006/11/12, Andrew Zhang <zh...@gmail.com>:
> > > Hi folks,
> > >
> > > I'm confused by javax.sql.rowset.serial.SerialJavaObject spec. The spec
> > of
> > > SerialJavaObject constructor says "throws SerialException if the object
> > is
> > > found to be unserializable". It also mentions "Static or transient
> > fields
> > > cannot be serialized; an attempt to serialize them will result in a
> > > SerialException object being thrown. ". Does it mean to throw
> > > SerialException if the object doesn't implement Serializable or it
> > contains
> > > static/transient fields? I tried some tests[1], but SerialException is
> > never
> > > thrown. Am I missing something? Thank you in advance for your help!
> > >
> > > [1] SerialJavaObject constructor test case:
> > >  public void test_Constructor() throws Exception {
> > >  Object obj = new NonSerializableClass();
> > >  SerialJavaObject sjo = new SerialJavaObject(obj);
> > >  }
> > >
> > >  static class NonSerializableClass {
> > >  public static int i;
> > >  public static Thread t;
> > >  public transient String s;
> > >  NonSerializableClass() {
> > >
> > >  }
> > >  }


-- 
Alexei Zakharov,
Intel Enterprise Solutions Software Division

Re: [classlib][sql] SerialJavaObject constructor throws SerialException when the object is unserializable?

Posted by Andrew Zhang <zh...@gmail.com>.
On 11/13/06, Mikhail Loenko <ml...@gmail.com> wrote:
>
> I guess that Sun has implemented some behavior and some exception
> could be thrown by that implementation.


Sorry for my late reply... Just back from travelling. :)

I don't quite get the point. What does "that implementation" mean? Is it
invoked in SerialJavaObject constructor?

Then they wrapped that exception
> by SerialException and documented in the spec ;)
>
> You might want to implement it without exception throwing and if we find
> an
> inconsistency later -- fix it


ya, I'd like to follow this way. If we find any problem, fix it then. :-)

If no one objects, I'll ignore static/transient check in the constructor.
Thanks!

Thanks,
> Mikhail
>
> 2006/11/12, Andrew Zhang <zh...@gmail.com>:
> > Hi folks,
> >
> > I'm confused by javax.sql.rowset.serial.SerialJavaObject spec. The spec
> of
> > SerialJavaObject constructor says "throws SerialException if the object
> is
> > found to be unserializable". It also mentions "Static or transient
> fields
> > cannot be serialized; an attempt to serialize them will result in a
> > SerialException object being thrown. ". Does it mean to throw
> > SerialException if the object doesn't implement Serializable or it
> contains
> > static/transient fields? I tried some tests[1], but SerialException is
> never
> > thrown. Am I missing something? Thank you in advance for your help!
> >
> > [1] SerialJavaObject constructor test case:
> >  public void test_Constructor() throws Exception {
> >  Object obj = new NonSerializableClass();
> >  SerialJavaObject sjo = new SerialJavaObject(obj);
> >  }
> >
> >  static class NonSerializableClass {
> >  public static int i;
> >  public static Thread t;
> >  public transient String s;
> >  NonSerializableClass() {
> >
> >  }
> >  }
> >
> > --
> > Best regards,
> > Andrew Zhang
> >
> >
>



-- 
Best regards,
Andrew Zhang

Re: [classlib][sql] SerialJavaObject constructor throws SerialException when the object is unserializable?

Posted by Mikhail Loenko <ml...@gmail.com>.
I guess that Sun has implemented some behavior and some exception
could be thrown by that implementation. Then they wrapped that exception
by SerialException and documented in the spec ;)

You might want to implement it without exception throwing and if we find an
inconsistency later -- fix it

Thanks,
Mikhail

2006/11/12, Andrew Zhang <zh...@gmail.com>:
> Hi folks,
>
> I'm confused by javax.sql.rowset.serial.SerialJavaObject spec. The spec of
> SerialJavaObject constructor says "throws SerialException if the object is
> found to be unserializable". It also mentions "Static or transient fields
> cannot be serialized; an attempt to serialize them will result in a
> SerialException object being thrown. ". Does it mean to throw
> SerialException if the object doesn't implement Serializable or it contains
> static/transient fields? I tried some tests[1], but SerialException is never
> thrown. Am I missing something? Thank you in advance for your help!
>
> [1] SerialJavaObject constructor test case:
>  public void test_Constructor() throws Exception {
>  Object obj = new NonSerializableClass();
>  SerialJavaObject sjo = new SerialJavaObject(obj);
>  }
>
>  static class NonSerializableClass {
>  public static int i;
>  public static Thread t;
>  public transient String s;
>  NonSerializableClass() {
>
>  }
>  }
>
> --
> Best regards,
> Andrew Zhang
>
>