# Bug 2816988: IllegalArgumentException in StackMetrics

**URL:** <https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233>\
**Category:** Development\
**Created:** [July 24, 2009, 8:13pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233 "2009-07-24T20:13:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [July 24, 2009, 8:13pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/1 "2009-07-24T20:13:58Z")

</div>

I’ve been looking at this bug and found that the exception is thrown whenever  
StackMetrics.relativePosition() is called on a peice which is not in the  
Stack.

My question is: Does calling StackMetrics.relativePosition() on a piece not  
in the Stack really indicate a bug, or should relativePosition() act more  
like a “find” method, where it returns a designated value (like null) when  
the piece doesn’t exist?

---

<div class="post-metadata">

**Author:** ![rk1](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@rk1](https://forum.vassalengine.org/u/rk1)\
**Post date:** [July 24, 2009, 9:46pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/2 "2009-07-24T21:46:12Z")

</div>

The relativePosition() method is used to decide where to draw a piece within a stack or to decide which piece within a stack the user has clicked on. If the code is trying to do this for a piece not in the stack, it definitely sounds like a bug. There shouldn’t be any places where the code calls this method to decide whether a piece belongs to a stack. That should be done by looking for the piece’s parent or enumerating the stack’s contents.

rk

Post generated using Mail2Forum ([mail2forum.com](http://www.mail2forum.com))

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [July 24, 2009, 9:58pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/3 "2009-07-24T21:58:28Z")

</div>

Thus spake Rodney Kinney:

> [@](#):
>
> The relativePosition() method is used to decide where to draw a piece within  
> a stack or to decide which piece within a stack the user has clicked on. If  
> the code is trying to do this for a piece not in the stack, it definitely  
> sounds like a bug. There shouldn’t be any places where the code calls this  
> method to decide whether a piece belongs to a stack. That should be done by  
> looking for the piece’s parent or enumerating the stack’s contents.
> 
> rk

Do you want to work on this one? I’ve looked at it but can’t see why the  
piece isn’t in the stack.

–  
J.

* * *

Messages mailing list  
[Messages@forums.vassalengine.org](mailto:Messages@forums.vassalengine.org)  
[forums.vassalengine.org/mailman/ … engine.org](http://forums.vassalengine.org/mailman/listinfo/messages_forums.vassalengine.org)

Post generated using Mail2Forum ([mail2forum.com](http://www.mail2forum.com))

---

<div class="post-metadata">

**Author:** ![Brent\_Easton](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/brent_easton/32/10_2.png) [@Brent\_Easton](https://forum.vassalengine.org/u/Brent_Easton)\
**Post date:** [July 25, 2009, 2:37pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/4 "2009-07-25T14:37:28Z")

</div>

> [@](#):
>
> Thus spake Rodney Kinney:
> 
> > [@](#):
> >
> > The relativePosition() method is used to decide where to draw a piece
> 
> within
> 
> > [@](#):
> >
> > a stack or to decide which piece within a stack the user has clicked on.
> 
> If
> 
> > [@](#):
> >
> > the code is trying to do this for a piece not in the stack, it definitely  
> > sounds like a bug. There shouldn’t be any places where the code calls
> 
> this
> 
> > [@](#):
> >
> > method to decide whether a piece belongs to a stack. That should be
> 
> done by
> 
> > [@](#):
> >
> > looking for the piece’s parent or enumerating the stack’s contents.
> > 
> > rk
> 
> Do you want to work on this one? I’ve looked at it but can’t see why the  
> piece isn’t in the stack.

Some more clues…

There is a check at Map:1601 that specifically tests that the piece in question has a non null parent and then calls StackMetrics.relativePosition() to find the position of that piece in the parent.

The Error message tells us that the piece is a counter called Delhi and it’s parent is Deck containing the single piece called Baghdad. Either the piece has been removed from the Deck by a different thread since Map:1601 (unlikely), or the piece has been removed from the Deck, but still thinks it belongs to it (more likely)

Another clue is that the command that is trying to update the piece has come from a different client accross the network. Bug 2763811 is the identical problem in a completely different module - Deck with one piece, networked ChangePiece command.

PS. An unrelated way to generate the same Exception is to set the ‘Maximum Cards to Display’ field in a Deck to 0.

PSS. A bandaid fix would be for relativePosition() to return 0 instead of throwing an exception.

B.

* * *

Messages mailing list  
[Messages@forums.vassalengine.org](mailto:Messages@forums.vassalengine.org)  
[forums.vassalengine.org/mailman/ … engine.org](http://forums.vassalengine.org/mailman/listinfo/messages_forums.vassalengine.org)

Post generated using Mail2Forum ([mail2forum.com](http://www.mail2forum.com))

---

<div class="post-metadata">

**Author:** ![Brent\_Easton](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/brent_easton/32/10_2.png) [@Brent\_Easton](https://forum.vassalengine.org/u/Brent_Easton)\
**Post date:** [July 25, 2009, 11:39pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/5 "2009-07-25T23:39:40Z")

</div>

> [@](#):
>
> Do you want to work on this one? I’ve looked at it but can’t see why the  
> piece isn’t in the stack.

I have a concern about the way we use SwingUtilities.invokeLater() to fire off additional threads all over the place with no sort of explicit synchonization whatsoever. Maybe I don’t know enought about SwingUtilites.invokeLater(), but my reading does not indicate the the threads you start via invokeLater() are guaranteed to run Atomically, only that they will be executed asynchronously after all pending AWT events have been processed.

Is it possible for a thread initiated by invokeLater() to suspend before it has completed and another to run, then the initial thread resumes?

B.

* * *

Messages mailing list  
[Messages@forums.vassalengine.org](mailto:Messages@forums.vassalengine.org)  
[forums.vassalengine.org/mailman/ … engine.org](http://forums.vassalengine.org/mailman/listinfo/messages_forums.vassalengine.org)

Post generated using Mail2Forum ([mail2forum.com](http://www.mail2forum.com))

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [July 26, 2009, 1:03pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/6 "2009-07-26T13:03:58Z")

</div>

Thus spake “Brent Easton”:

> [@](#):
>
> > [@](#):
> >
> > Do you want to work on this one? I’ve looked at it but can’t see why the  
> > piece isn’t in the stack.
> 
> I have a concern about the way we use SwingUtilities.invokeLater() to fire of  
> f additional threads all over the place with no sort of explicit synchonizati  
> on whatsoever.

I’m more than just concerned about it. I’m certain it’s wrong. This is one  
of the things I’m planning to clean up in doing the model-view separation  
in September.

> [@](#):
>
> Maybe I don’t know enought about SwingUtilites.invokeLater(),  
> but my reading does not indicate the the threads you start via invokeLater()  
> are guaranteed to run Atomically, only that they will be executed asynchronou  
> sly after all pending AWT events have been processed.

Yes, that’s correct.

> [@](#):
>
> Is it possible for a thread initiated by invokeLater() to suspend before it h  
> as completed and another to run, then the initial thread resumes?

If invokeLater() is called on a Runnable from the EDT, then the already-  
running code will complete before the Runnable starts. If invokeLater() is  
called off the EDT, then you have no guarantees at all about when the  
Runnable will run.

–  
J.

* * *

Messages mailing list  
[Messages@forums.vassalengine.org](mailto:Messages@forums.vassalengine.org)  
[forums.vassalengine.org/mailman/ … engine.org](http://forums.vassalengine.org/mailman/listinfo/messages_forums.vassalengine.org)

Post generated using Mail2Forum ([mail2forum.com](http://www.mail2forum.com))

---

<div class="post-metadata">

**Author:** ![rk1](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@rk1](https://forum.vassalengine.org/u/rk1)\
**Post date:** [July 28, 2009, 9:55pm UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/7 "2009-07-28T21:55:01Z")

</div>

> [@](#):
>
> I have a concern about the way we use SwingUtilities.invokeLater() to fire off additional threads all over the place with no sort of explicit synchonization whatsoever.

Calling invokeLater() doesn’t start a new thread. It places work on the GUI thread, so it’s effectively a way of synchronizing events. You don’t have control over the exact order in which the events will be executed, but you guarantee that they won’t be interleaved.

> [@](#):
>
> Is it possible for a thread initiated by invokeLater() to suspend before it has completed and another to run, then the initial thread resumes?

This is not possible. All code in one invokeLater() call will complete before the code in the next invokeLater() is executed.

rk

Post generated using Mail2Forum ([mail2forum.com](http://www.mail2forum.com))

---

<div class="post-metadata">

**Author:** ![Brent\_Easton](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/brent_easton/32/10_2.png) [@Brent\_Easton](https://forum.vassalengine.org/u/Brent_Easton)\
**Post date:** [July 29, 2009, 12:22am UTC](https://forum.vassalengine.org/t/bug-2816988-illegalargumentexception-in-stackmetrics/2233/8 "2009-07-29T00:22:39Z")

</div>

> [@](#):
>
> I have a concern about the way we use SwingUtilities.invokeLater() to  
> fire off additional threads all over the place with no sort of explicit  
> synchonization whatsoever.
> 
> Calling invokeLater() doesn’t start a new thread. It places work on the  
> GUI thread, so it’s effectively a way of synchronizing events. You don’t  
> have control over the exact order in which the events will be executed,  
> but you guarantee that they won’t be interleaved.
> 
> Is it possible for a thread initiated by invokeLater() to suspend before  
> it has completed and another to run, then the initial thread resumes?
> 
> This is not possible. All code in one invokeLater() call will complete  
> before the code in the next invokeLater() is executed.\

That is reassuring.

B.

* * *

Messages mailing list  
[Messages@forums.vassalengine.org](mailto:Messages@forums.vassalengine.org)  
[forums.vassalengine.org/mailman/ … engine.org](http://forums.vassalengine.org/mailman/listinfo/messages_forums.vassalengine.org)

Post generated using Mail2Forum ([mail2forum.com](http://www.mail2forum.com))
