-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 17
ADDITIONAL SYSTEM INFORMATION :
All OS/JRE
A DESCRIPTION OF THE PROBLEM :
A test might describe the problem the best:
@Test
public void hashMapTest()
{
Map<UUID, UUID> map = new HashMap<>();
for (int i = 0; i < 10; i++)
{
UUID uuid = UUID.randomUUID();
map.computeIfAbsent(uuid, key ->
{
map.put(uuid,uuid);
return uuid;
});
}
assertThat(map.size(), is(10));
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
@Test
public void hashMapTest()
{
Map<UUID, UUID> map = new HashMap<>();
for (int i = 0; i < 10; i++)
{
UUID uuid = UUID.randomUUID();
map.computeIfAbsent(uuid, key ->
{
map.put(uuid,uuid);
return uuid;
});
}
assertThat(map.size(), is(10));
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
green test
ACTUAL -
red test, double enntries
---------- BEGIN SOURCE ----------
@Test
public void hashMapTest()
{
Map<UUID, UUID> map = new HashMap<>();
for (int i = 0; i < 10; i++)
{
UUID uuid = UUID.randomUUID();
map.computeIfAbsent(uuid, key ->
{
map.put(uuid,uuid);
return uuid;
});
}
assertThat(map.size(), is(10));
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
fix the code and do not add the value inside the computeIfAbsent method
All OS/JRE
A DESCRIPTION OF THE PROBLEM :
A test might describe the problem the best:
@Test
public void hashMapTest()
{
Map<UUID, UUID> map = new HashMap<>();
for (int i = 0; i < 10; i++)
{
UUID uuid = UUID.randomUUID();
map.computeIfAbsent(uuid, key ->
{
map.put(uuid,uuid);
return uuid;
});
}
assertThat(map.size(), is(10));
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
@Test
public void hashMapTest()
{
Map<UUID, UUID> map = new HashMap<>();
for (int i = 0; i < 10; i++)
{
UUID uuid = UUID.randomUUID();
map.computeIfAbsent(uuid, key ->
{
map.put(uuid,uuid);
return uuid;
});
}
assertThat(map.size(), is(10));
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
green test
ACTUAL -
red test, double enntries
---------- BEGIN SOURCE ----------
@Test
public void hashMapTest()
{
Map<UUID, UUID> map = new HashMap<>();
for (int i = 0; i < 10; i++)
{
UUID uuid = UUID.randomUUID();
map.computeIfAbsent(uuid, key ->
{
map.put(uuid,uuid);
return uuid;
});
}
assertThat(map.size(), is(10));
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
fix the code and do not add the value inside the computeIfAbsent method