• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • DSO:L1
  • teck
  • Reporter: rbodkin
  • March 28, 2007
  • 0
  • Watchers: 0
  • July 27, 2012
  • March 28, 2007

Description

When I execute the constructor for this class in a TerraCotta-enabled JVM, it fails to add elements. The same code works as expected on a normal JVM without TerraCotta instrumentation:

public class IntArrayMapImpl extends HashMap<Integer, Map<Integer,int[]» {

private int buckets = 100;

public IntArrayMapImpl() \{
	for (int i=0; i<buckets; i++) \{
		put(i, new HashMap<Integer,int[]>()); // data is not added here if TC is involved
	\}		
\} \}

Comments

Ron Bodkin 2007-03-28

A workaround here is to delegate to a synchronized private method in the constructor. This is a bit awkward (at least it breaks the expectations of the JMM where you don’t need to synchronize during initialization):

public class IntArrayMapImpl extends HashMap<Integer, Map<Integer,int[]» {

 private int buckets = 100; 

public IntArrayMapImpl() \{
	init();
\}

private synchronized void init() \{
	for (int i=0; i<buckets; i++) \{
		put(i, new HashMap<Integer,int[]>());
	\}				
\}

Steve Harris 2007-03-28

can you look at this

Tim Eck 2007-03-28

I think this is already fixed in 2.3 branch and trunk.

In 2.2.1 stable 2, I don’t think all of the put() calls ignored, I would think the there would be one mapping retained (99 –> HashMap())

I’ll look into what was fixed in the recent branch and potentially back port the fix

Tim Eck 2007-03-28

I mispoke, there are to be no more 2.2.1 releases. The upcoming 2.3 release will resolve this issue

Tim Eck 2007-03-28

this is already fixed (thanks to Antonio)

Ron Bodkin 2007-03-28

Yes, we see one mapping not 100. Thanks for the update. At least we have a workaround for 2.2