Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/868#discussion_r146684621
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
 ---
    @@ -368,12 +370,51 @@ public void 
addToLocalUnpersistedTypeRegistry(RegisteredType type, boolean canFo
             if 
(!type.getId().equals(type.getSymbolicName()+":"+type.getVersion()))
                 Asserts.fail("Registered type "+type+" has ID / symname 
mismatch");
             
    -        RegisteredType oldType = mgmt.getTypeRegistry().get(type.getId());
    -        if (oldType==null || canForce || 
BrooklynVersionSyntax.isSnapshot(oldType.getVersion())) {
    -            log.debug("Inserting "+type+" into "+this);
    -            localRegisteredTypes.put(type.getId(), type);
    -        } else {
    -            assertSameEnoughToAllowReplacing(oldType, type);
    +        Map<String, RegisteredType> knownMatchingTypesByBundles = 
localRegisteredTypesAndContainingBundles.get(type.getId());
    +        if (knownMatchingTypesByBundles!=null && 
!knownMatchingTypesByBundles.isEmpty()) {
    +            for (RegisteredType existingT: 
knownMatchingTypesByBundles.values()) {
    --- End diff --
    
    Risks `ConcurrentModificationException`. Elsewhere it synchronizes on the 
(non-concurrent) `Map<String, RegisteredType` to do `put`, but here we iterate 
over it without synchronizing. Perhaps take a copy while synchronized on it, 
and then iterate over that copy? Or probably safer to just synchronize on the 
map for all of this block.


---

Reply via email to