Source:
<code>private boolean createOffheapResource(OffHeapResourceIdentifier identifier, long size) { if (resources.containsKey(identifier)) { return false; } OffHeapResourceImpl offHeapResource = new OffHeapResourceImpl( identifier.getName(), size, (res, update) -> { for (EntityManagementRegistry registry : registries) { Map<String, String> attrs = new HashMap<>(); attrs.put("oldThreshold", String.valueOf(update.old)); attrs.put("threshold", String.valueOf(update.now)); attrs.put("capacity", String.valueOf(res.capacity())); attrs.put("available", String.valueOf(res.available())); registry.pushServerEntityNotification(res.getManagementBinding(), "OFFHEAP_RESOURCE_THRESHOLD_REACHED", attrs); } }, (res, oldCapacity, newCapacity) -> { updateCurrentUsage(newCapacity - oldCapacity); for (EntityManagementRegistry registry : registries) { Map<String, String> attrs = new HashMap<>(); attrs.put("oldCapacity", Long.toString(oldCapacity)); attrs.put("newCapacity", Long.toString(newCapacity)); registry.pushServerEntityNotification(res.getManagementBinding(), "OFFHEAP_RESOURCE_CAPACITY_CHANGED", attrs); } }); <START> resources.put(identifier, offHeapResource); <END> Map<String, Object> properties = new HashMap<>(); properties.put("discriminator", "OffHeapResource"); properties.put("offHeapResourceIdentifier", identifier.getName()); StatisticsManager.createPassThroughStatistic( offHeapResource, "allocatedMemory", new HashSet<>(Arrays.asList("OffHeapResource", "tier")), properties, StatisticType.GAUGE, () -> offHeapResource.capacity() - offHeapResource.available() ); return true; }</code><technical_language>subtle race here. putIfAbsent. If putIfAbsent return null, return false</technical_language>

Target:
private boolean createOffheapResource(OffHeapResourceIdentifier identifier, long size) { if (resources.containsKey(identifier)) { return false; } OffHeapResourceImpl offHeapResource = new OffHeapResourceImpl( identifier.getName(), size, (res, update) -> { for (EntityManagementRegistry registry : registries) { Map<String, String> attrs = new HashMap<>(); attrs.put("oldThreshold", String.valueOf(update.old)); attrs.put("threshold", String.valueOf(update.now)); attrs.put("capacity", String.valueOf(res.capacity())); attrs.put("available", String.valueOf(res.available())); registry.pushServerEntityNotification(res.getManagementBinding(), "OFFHEAP_RESOURCE_THRESHOLD_REACHED", attrs); } }, (res, oldCapacity, newCapacity) -> { updateCurrentUsage(newCapacity - oldCapacity); for (EntityManagementRegistry registry : registries) { Map<String, String> attrs = new HashMap<>(); attrs.put("oldCapacity", Long.toString(oldCapacity)); attrs.put("newCapacity", Long.toString(newCapacity)); registry.pushServerEntityNotification(res.getManagementBinding(), "OFFHEAP_RESOURCE_CAPACITY_CHANGED", attrs); } }); if (resources.putIfAbsent(identifier, offHeapResource) != null) { return false; } Map<String, Object> properties = new HashMap<>(); properties.put("discriminator", "OffHeapResource"); properties.put("offHeapResourceIdentifier", identifier.getName()); StatisticsManager.createPassThroughStatistic( offHeapResource, "allocatedMemory", new HashSet<>(Arrays.asList("OffHeapResource", "tier")), properties, StatisticType.GAUGE, () -> offHeapResource.capacity() - offHeapResource.available() ); return true; }