NoSuchElementException in SequenceEncoder.Decoder.nextToken

We’ve had a lot of reports of NoSuchElementExceptions thrown by SequenceEncoder.Decoder.nextToken(). For example:

sourceforge.net/tracker/?func=d … tid=594231
sourceforge.net/tracker/?func=d … tid=594231
sourceforge.net/tracker/?func=d … tid=594231
sourceforge.net/tracker/?func=d … tid=594231
sourceforge.net/tracker/?func=d … tid=594231
sourceforge.net/tracker/?func=d … tid=594231
sourceforge.net/tracker/?func=d … tid=594231

I understand what’s happening in these at the “bottom” of the stack trace: Something is expecting there to be more decodable tokens then there actually are. What I don’t understand is why this is the case. I’m fairly certain that SequenceEncoder.Decoder is not at fault here. The problem is either that more tokens should have been written, or fewer tokens should have been been requested.

This might also not be a VASSAL bug, but rather a module bug. If this isn’t a VASSAL bug, then I’d like to suggest that there is a VASSAL bug here anyway, namely that the user should be told what’s wrong and we should not be seeing these as bug reports.

Does anyone have any insight into this problem? I’d like to get these resolved, as this is the most frequent kind of bug report I see which isn’t obviously attributable to a JRE bug.

I suspect a VASSAL bug, rather than a module bug, but there are particular circumstances in which it turns up, otherwise it would be happening to everyone all the time.

Reviewing those error logs shows a number of different scenarios where the bug is showing up.

The ones that point to a VASSAL bug are when a saved game is being loaded and the AddPiece command is executing, trying to recreate a piece that has been saved in the Save Game. This does not reference the existing piece definition, it is just trying to recreate the piece exactly as it is saved. While trying to this, Decorator is finding that not enough state has been saved to satisfy all of the decorators in the saved piece.

So the bug would appear to be in getState() when the piece is saved in the first place, failing to return the State for all Decorators in the Piece. The way getState() works is to recursively call down through the Decorator stack, it only takes one Decorator to be failing to do this properly to generate this error.

I suspect that the other scenarios are all related, caused by the same bug, but showing up in different sections of code.

To attack this bug, I need a module plus save game that is showing the AddPiece error reproducibly. The piece failing needs to be fairly simple (< 10 traits) or it becomes impossible to debug. From this I can manually decode the state recorded in the save file and compare it to what should have been generated and try to pin down the trait causing the problem.

Another approach would be to catch the NoSuchElementException in Decorator.getState() and include information about which Decorator is actually the one finding there is no more state. It is likely to be the one that failed to generate sufficient state in the first place. Hopefully we will see a pattern emerge.

Decorator does not have access to the trait description, but including the value of myGetType() in the error message would do the trick. We could include this in 3.1.12.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Something like this (committed to swampwallaby-3.1@6085) should do the trick:

public void setState(String newState) {
SequenceEncoder.Decoder st = new SequenceEncoder.Decoder(newState, ‘\t’);
mySetState(st.nextToken());
try {
piece.setState(st.nextToken());
}
catch (NoSuchElementException e) {
throw new IllegalStateException(“Please submit this bug: No state for Decorator=”+myGetType());
}
}

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

I think nobody had contacted most of the users who left email addresses yet,
so I emailed them all asking whether anyone can reproduce the problem
reliably. Let’s see if we get any bites that way.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

Merged to 3.1@6087.

BTW, did you ever get the information you needed from that other diagnostic
patch we put in?


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Brent, here’s a reproducible example for you:

sourceforge.net/tracker/?func=d … p_id=90612

I’m guessing that the VSQL counters are pretty complex, though.

There does not seem to have been a reoccurence since the diagnostics went in!

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

I will have a look at this at some stage, but it is actually generated by a piece of my custom code and I don’t think it is relevent to the main problem. I may be wrong.

What I would really like to see is the problem happening when a save game is opened.

I’m away from a PC for the 4 days or so.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

If there’s any evidence that this has something to do with imported ADC2 modules, let me know as this is certainly a candidate.

Sorry I haven’t been around much. The best I can promise is that I’ll have more time freed up in mid-November to have fun. I can assure you that I have not otherwise been having fun.

  • M.

2009/10/7 Brent Easton <b.easton@exemail.com.au (b.easton@exemail.com.au)>

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

You have one now:

sourceforge.net/tracker/index.p … tid=594231


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)