8006409: ThreadLocalRandom should dropping padding fields from its serialized form

Chris Hegarty chris.hegarty at oracle.com
Mon Feb 25 23:25:19 UTC 2013


Thanks Martin, good suggestion.

-Chris

On 25 Feb 2013, at 22:25, Martin Buchholz <martinrb at google.com> wrote:

> Perhaps slightly better is this variant, which adds doc for the @serialField's.
> 
>     /**
>      * @serialField rnd long
>      *              seed for random computations
>      * @serialField initialized boolean
>      *              always true
>      */
>     private static final ObjectStreamField[] serialPersistentFields = {
>             new ObjectStreamField("rnd", long.class),
>             new ObjectStreamField("initialized", boolean.class),
>     };
> 
>     /**
>      * Saves the {@code ThreadLocalRandom} to a stream (that is, serializes it).
>      */
>     private void writeObject(java.io.ObjectOutputStream out)
>         throws java.io.IOException {
> 
>         java.io.ObjectOutputStream.PutField fields = out.putFields();
>         fields.put("rnd", UNSAFE.getLong(Thread.currentThread(), SEED));
>         fields.put("initialized", true);
>         out.writeFields();
>     }
> 
> 
> On Mon, Feb 25, 2013 at 2:13 PM, Martin Buchholz <martinrb at google.com> wrote:
>> Me too!
> 



More information about the core-libs-dev mailing list