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/26 13:19:07 UTC

[classlib] how to verify private/package private field which is required by serialized form?

Hi folks,

I encountered a problem when writing serialization test for SerialJavaObject
class. There're two fields are required by serialized form: Object obj, and
Vector chain. But there's no public method is available to get chain
variable. The question comes:
How can I verify deserilized object, by reflection? How do we handle such
problem in other modules? Any suggestions?

Thanks in adavance!

-- 
Best regards,
Andrew Zhang

Re: [classlib] how to verify private/package private field which is required by serialized form?

Posted by Spark Shen <sm...@gmail.com>.
Then seems only reflection is possible

Best regards


2006/11/27, Andrew Zhang <zh...@gmail.com>:
>
> On 11/27/06, Spark Shen <sm...@gmail.com> wrote:
> >
> > Reflection may be feasible, but a downside hit on performance.
> >
> > I have a suggestion: writing a subclass, open that field using a getter,
>
>
> How can we get the field if it's private?
>
> and
> > then customize serialization process for this subclass to deliberate
> > invoke
> > this getter. Is this possible?
> >
> >
> > 2006/11/26, Andrew Zhang <zh...@gmail.com>:
> > >
> > > Hi folks,
> > >
> > > I encountered a problem when writing serialization test for
> > > SerialJavaObject
> > > class. There're two fields are required by serialized form: Object
> obj,
> > > and
> > > Vector chain. But there's no public method is available to get chain
> > > variable. The question comes:
> > > How can I verify deserilized object, by reflection? How do we handle
> > such
> > > problem in other modules? Any suggestions?
> > >
> > > Thanks in adavance!
> > >
> > > --
> > > Best regards,
> > > Andrew Zhang
> > >
> > >
> >
> >
> > --
> > Spark Shen
> > China Software Development Lab, IBM
> >
> >
>
>
> --
> Best regards,
> Andrew Zhang
>
>


-- 
Spark Shen
China Software Development Lab, IBM

Re: [classlib] how to verify private/package private field which is required by serialized form?

Posted by spark shen <sm...@gmail.com>.
Alexey Varlamov 写道:
> The real fun might begin when this "vector" is not a real field
> either: it can be just ObjectStreamField declaration de/serialized
> manually into any other private representation. So don't expect this
> test to be implementation-independent.
>
> BTW, what is the point to care about serialization test performance?
Ha ha, agree. But if there is better alternative which takes less time,
it would be better.

Best regards
>
> 2006/11/27, spark shen <sm...@gmail.com>:
>> Nathan Beyer 写道:
>> > On 11/26/06, Andrew Zhang <zh...@gmail.com> wrote:
>> >> On 11/27/06, Spark Shen <sm...@gmail.com> wrote:
>> >> >
>> >> > Reflection may be feasible, but a downside hit on performance.
>> >> >
>> >> > I have a suggestion: writing a subclass, open that field using a
>> >> getter,
>> >>
>> >>
>> >> How can we get the field if it's private?
>> >
>> > Write an accessor that looks up the declared field, set it as
>> > accessible and then read it. This requires that the security policy
>> > allows it.
>> Good idea. And IMHO, this may not over-perform reflection. :-)
>>
>> Best regards
>> >
>> > -Nathan
>> >
>> >>
>> >> and
>> >> > then customize serialization process for this subclass to
>> deliberate
>> >> > invoke
>> >> > this getter. Is this possible?
>> >> >
>> >> >
>> >> > 2006/11/26, Andrew Zhang <zh...@gmail.com>:
>> >> > >
>> >> > > Hi folks,
>> >> > >
>> >> > > I encountered a problem when writing serialization test for
>> >> > > SerialJavaObject
>> >> > > class. There're two fields are required by serialized form:
>> >> Object obj,
>> >> > > and
>> >> > > Vector chain. But there's no public method is available to get
>> chain
>> >> > > variable. The question comes:
>> >> > > How can I verify deserilized object, by reflection? How do we
>> handle
>> >> > such
>> >> > > problem in other modules? Any suggestions?
>> >> > >
>> >> > > Thanks in adavance!
>> >> > >
>> >> > > --
>> >> > > Best regards,
>> >> > > Andrew Zhang
>> >> > >
>> >> > >
>> >> >
>> >> >
>> >> > --
>> >> > Spark Shen
>> >> > China Software Development Lab, IBM
>> >> >
>> >> >
>> >>
>> >>
>> >> --
>> >> Best regards,
>> >> Andrew Zhang
>> >>
>> >>
>> >
>>
>>
>>
>



Re: [classlib] how to verify private/package private field which is required by serialized form?

Posted by Alexey Varlamov <al...@gmail.com>.
The real fun might begin when this "vector" is not a real field
either: it can be just ObjectStreamField declaration de/serialized
manually into any other private representation. So don't expect this
test to be implementation-independent.

BTW, what is the point to care about serialization test performance?

2006/11/27, spark shen <sm...@gmail.com>:
> Nathan Beyer 写道:
> > On 11/26/06, Andrew Zhang <zh...@gmail.com> wrote:
> >> On 11/27/06, Spark Shen <sm...@gmail.com> wrote:
> >> >
> >> > Reflection may be feasible, but a downside hit on performance.
> >> >
> >> > I have a suggestion: writing a subclass, open that field using a
> >> getter,
> >>
> >>
> >> How can we get the field if it's private?
> >
> > Write an accessor that looks up the declared field, set it as
> > accessible and then read it. This requires that the security policy
> > allows it.
> Good idea. And IMHO, this may not over-perform reflection. :-)
>
> Best regards
> >
> > -Nathan
> >
> >>
> >> and
> >> > then customize serialization process for this subclass to deliberate
> >> > invoke
> >> > this getter. Is this possible?
> >> >
> >> >
> >> > 2006/11/26, Andrew Zhang <zh...@gmail.com>:
> >> > >
> >> > > Hi folks,
> >> > >
> >> > > I encountered a problem when writing serialization test for
> >> > > SerialJavaObject
> >> > > class. There're two fields are required by serialized form:
> >> Object obj,
> >> > > and
> >> > > Vector chain. But there's no public method is available to get chain
> >> > > variable. The question comes:
> >> > > How can I verify deserilized object, by reflection? How do we handle
> >> > such
> >> > > problem in other modules? Any suggestions?
> >> > >
> >> > > Thanks in adavance!
> >> > >
> >> > > --
> >> > > Best regards,
> >> > > Andrew Zhang
> >> > >
> >> > >
> >> >
> >> >
> >> > --
> >> > Spark Shen
> >> > China Software Development Lab, IBM
> >> >
> >> >
> >>
> >>
> >> --
> >> Best regards,
> >> Andrew Zhang
> >>
> >>
> >
>
>
>

Re: [classlib] how to verify private/package private field which is required by serialized form?

Posted by spark shen <sm...@gmail.com>.
Nathan Beyer 写道:
> On 11/26/06, Andrew Zhang <zh...@gmail.com> wrote:
>> On 11/27/06, Spark Shen <sm...@gmail.com> wrote:
>> >
>> > Reflection may be feasible, but a downside hit on performance.
>> >
>> > I have a suggestion: writing a subclass, open that field using a 
>> getter,
>>
>>
>> How can we get the field if it's private?
>
> Write an accessor that looks up the declared field, set it as
> accessible and then read it. This requires that the security policy
> allows it.
Good idea. And IMHO, this may not over-perform reflection. :-)

Best regards
>
> -Nathan
>
>>
>> and
>> > then customize serialization process for this subclass to deliberate
>> > invoke
>> > this getter. Is this possible?
>> >
>> >
>> > 2006/11/26, Andrew Zhang <zh...@gmail.com>:
>> > >
>> > > Hi folks,
>> > >
>> > > I encountered a problem when writing serialization test for
>> > > SerialJavaObject
>> > > class. There're two fields are required by serialized form: 
>> Object obj,
>> > > and
>> > > Vector chain. But there's no public method is available to get chain
>> > > variable. The question comes:
>> > > How can I verify deserilized object, by reflection? How do we handle
>> > such
>> > > problem in other modules? Any suggestions?
>> > >
>> > > Thanks in adavance!
>> > >
>> > > --
>> > > Best regards,
>> > > Andrew Zhang
>> > >
>> > >
>> >
>> >
>> > --
>> > Spark Shen
>> > China Software Development Lab, IBM
>> >
>> >
>>
>>
>> -- 
>> Best regards,
>> Andrew Zhang
>>
>>
>



Re: [classlib] how to verify private/package private field which is required by serialized form?

Posted by Nathan Beyer <nb...@gmail.com>.
On 11/26/06, Andrew Zhang <zh...@gmail.com> wrote:
> On 11/27/06, Spark Shen <sm...@gmail.com> wrote:
> >
> > Reflection may be feasible, but a downside hit on performance.
> >
> > I have a suggestion: writing a subclass, open that field using a getter,
>
>
> How can we get the field if it's private?

Write an accessor that looks up the declared field, set it as
accessible and then read it. This requires that the security policy
allows it.

-Nathan

>
> and
> > then customize serialization process for this subclass to deliberate
> > invoke
> > this getter. Is this possible?
> >
> >
> > 2006/11/26, Andrew Zhang <zh...@gmail.com>:
> > >
> > > Hi folks,
> > >
> > > I encountered a problem when writing serialization test for
> > > SerialJavaObject
> > > class. There're two fields are required by serialized form: Object obj,
> > > and
> > > Vector chain. But there's no public method is available to get chain
> > > variable. The question comes:
> > > How can I verify deserilized object, by reflection? How do we handle
> > such
> > > problem in other modules? Any suggestions?
> > >
> > > Thanks in adavance!
> > >
> > > --
> > > Best regards,
> > > Andrew Zhang
> > >
> > >
> >
> >
> > --
> > Spark Shen
> > China Software Development Lab, IBM
> >
> >
>
>
> --
> Best regards,
> Andrew Zhang
>
>

Re: [classlib] how to verify private/package private field which is required by serialized form?

Posted by Andrew Zhang <zh...@gmail.com>.
On 11/27/06, Spark Shen <sm...@gmail.com> wrote:
>
> Reflection may be feasible, but a downside hit on performance.
>
> I have a suggestion: writing a subclass, open that field using a getter,


How can we get the field if it's private?

and
> then customize serialization process for this subclass to deliberate
> invoke
> this getter. Is this possible?
>
>
> 2006/11/26, Andrew Zhang <zh...@gmail.com>:
> >
> > Hi folks,
> >
> > I encountered a problem when writing serialization test for
> > SerialJavaObject
> > class. There're two fields are required by serialized form: Object obj,
> > and
> > Vector chain. But there's no public method is available to get chain
> > variable. The question comes:
> > How can I verify deserilized object, by reflection? How do we handle
> such
> > problem in other modules? Any suggestions?
> >
> > Thanks in adavance!
> >
> > --
> > Best regards,
> > Andrew Zhang
> >
> >
>
>
> --
> Spark Shen
> China Software Development Lab, IBM
>
>


-- 
Best regards,
Andrew Zhang

Re: [classlib] how to verify private/package private field which is required by serialized form?

Posted by Spark Shen <sm...@gmail.com>.
Reflection may be feasible, but a downside hit on performance.

I have a suggestion: writing a subclass, open that field using a getter, and
then customize serialization process for this subclass to deliberate invoke
this getter. Is this possible?


2006/11/26, Andrew Zhang <zh...@gmail.com>:
>
> Hi folks,
>
> I encountered a problem when writing serialization test for
> SerialJavaObject
> class. There're two fields are required by serialized form: Object obj,
> and
> Vector chain. But there's no public method is available to get chain
> variable. The question comes:
> How can I verify deserilized object, by reflection? How do we handle such
> problem in other modules? Any suggestions?
>
> Thanks in adavance!
>
> --
> Best regards,
> Andrew Zhang
>
>


-- 
Spark Shen
China Software Development Lab, IBM