On 09/10/2010 04:46 PM, Adrian Crum wrote:
--- On Fri, 9/10/10, Adam Heath<[email protected]>  wrote:
On 09/10/2010 04:22 PM, Adrian Crum
wrote:
--- On Fri, 9/10/10, Adam Heath<[email protected]>
wrote:
On 09/10/2010 01:03 PM, Adrian Crum
wrote:
--- On Fri, 9/10/10, Adam Heath<[email protected]>
wrote:
I haven't had this be a problem for
me in production anywhere, but I noticed
that
when
remove(Object) is called, it'll remove the
value
from the
top-most map in the stack.  This then
means
any queries
for the key will fall-thru to lower maps,
which
is
definately *not* what should occur.

That would depend on your point of view. From
a
variable scoping viewpoint, that would be the
correct
behavior.

Let's say I have two variables, both with the
same
name. One is declared early on and could be
considered
"global." The other is declared inside a method
and is
considered "local." If I remove the local
variable, I would
expect the global variable to still be there.

java.util.Map.remove(Object) says that it removes
the
object from the
map, such that Map.containsKey(Object) will return
false
afterwards.
That is what the contract states, and that's what
MapStack/MapContext
should follow.

If you want another method to do what you say,
then I can
go ahead and
implement that.

As it is, if an instance of MapStack/MapContext is
passed
to legacy
code that only deals with maps, then it'll break.

Like I said, it's a matter of perspective. What is
MapStack's purpose - to implement a Map, or to implement
variable scoping? Based on the MapStack code and how it is
used in the framework, I think it is the latter.

If it is supposed to implement variable scoping, then it doesn't, as remove doesn't insert a sentinal.

And, to be safe, MapContext can't actually insert a sentinal into the map at the top level. It can't insert null, as that is a valid value. It can't insert an object of a different type, as that would break the generics. The only way to solve it is to have each level of the stack have an out-of-band store for removed items(basically, a set of keys).


It would be helpful to hear from others.

MapStack implements Map.  It must follow the Map
contract.  If you
remove the Map from the implements, then it can do whatever
we want.

I can correct these problems, it's busy work for me.

I have a feeling that will break a lot of screen widget/mini-language code.

Removing implements Map, or fixing the implementation?

I've seen code scattered around that checks if the Map is an instance of MapStack, and then does a push, falling back on wrapping the map in a new MapStack. Such code shouldn't break

Reply via email to