Problem with SequenceEncoder

Hi folks,

I created a DynamicProperty with an empty initial value and this causes an IllegalStateException in Decorator.setState when you try to reload the module.

I have logged this as bug 3465 with an explanation of how it happens before searching for similar bugs (sorry) and discovered that there are quite a few.

This bug is simple to fix, setting the initial value to “” rather than null will mean that SequenceEncoder will handle it properly.

But there is an underlying problem, Decorator.getState() uses SequenceEncoder to serializes the state in a maner such that if myGetState() returns null only one token is created. Decorator.setState() on the other hand always requires two tokens.

The general problem seems to be that if a SequenceEncoder is created with an initial value and that value is null then the first token will not be created

i.e. (new SequenceEncoder(nullString, delim)).append(valueString); // creates one token
(new SequenceEncoder(delim)).append(nullString).append(valueString); // creates two tokens

I think that the first behaviour is wrong.

Bob

Search for the discussion where setting values to null or “” was discussed.
There is a reason and method to the madness, beyond me but deeper than what
you think I suspect.

Also it was never intended for you to leave the initial value of a DP empty
even though it lets you do this. The easy fix of course would be to put a
value in there and you’d get no bug :slight_smile:

-----Original Message-----
From: messages-bounces@vassalengine.org
[mailto:messages-bounces@vassalengine.org] On Behalf Of bobd
Sent: Tuesday, March 08, 2011 3:52 PM
To: messages@vassalengine.org
Subject: [messages] [Developers] Problem with SequenceEncoder

Hi folks,

I created a DynamicProperty with an empty initial value and this causes
an IllegalStateException in Decorator.setState when you try to reload
the module.

I have logged this as bug 3465 with an explanation of how it happens
before searching for similar bugs (sorry) and discovered that there are
quite a few.

This bug is simple to fix, setting the initial value to “” rather than
null will mean that SequenceEncoder will handle it properly.

But there is an underlying problem, Decorator.getState() uses
SequenceEncoder to serializes the state in a maner such that if
myGetState() returns null only one token is created.
Decorator.setState() on the other hand always requires two tokens.

The general problem seems to be that if a SequenceEncoder is created
with an initial value and that value is null then the first token will
not be created

i.e. (new SequenceEncoder(nullString, delim)).append(valueString);
// creates one token
(new
SequenceEncoder(delim)).append(nullString).append(valueString); //
creates two tokens

I think that the first behaviour is wrong.

Bob


Read this topic online here:
https://forum.vassalengine.org/t/problem-with-sequenceencoder/3733/1

I had a search but couldn’t find it.

I hadn’t intended to, but when it refused to reload the module I thought that I would try and understand the problem.

Now why didn’t I think of that :wink:

What did you think about the SequenceEncoder issue though? That is the cause of the bug, and may be the cause of some of the similar bugs in the tracker.

My thoughts would be to contact Joel and have him add you to the developers in sourceforge so you can create your own branch (from the 3.1.15 tag) in the repository to commit changes there, test etc… and post here for Joel the info “fix for foo @commit####” so he can go over it before merging it to the trunk when he gets to it.

He is always looking for help and sounds like you know what you are doing :slight_smile: