Uploaded image for project: 'WildFly Core'
  1. WildFly Core
  2. WFCORE-2111

Fix incorrect usage of AtomicMapFieldUpdater.putAtomic()



      The javadoc for the copy of AtomicMapFieldUpdater used in core specifies that if putAtomic() returns a value, that the put did not succeed. The transformer and notification registries are full of code checking the return value like https://github.com/kabir/wildfly-core/blob/3396609db1eebf7af382133b7d22fa1828643895/controller/src/main/java/org/jboss/as/controller/registry/GlobalTransformerRegistry.java#L270 :

          SubRegistry getOrCreate(final String key) {
              for (;;) {
                  final Map<String, SubRegistry> subRegistries = subRegistriesUpdater.get(this);
                  SubRegistry registry = subRegistries.get(key);
                  if(registry == null) {
                      registry = new SubRegistry();
                      SubRegistry existing = subRegistriesUpdater.putAtomic(this, key, registry, subRegistries);
                      if(existing == null) {
                          return registry;
                      } else if (existing != registry) {
                          return existing; // Problematic
                  return registry;

      This calling code assumes that if 'existing' is returned and is not the same as the created 'registry' that the put succeeded, and it was added to 'existing'. However, this is not what happens, when 'existing' is returned, its value is actually the same as the 'subRegistries' snapshot, and no insertion has happened.

      To clear up the confusion, make AtomicMapFieldUpdater return a boolean where 'true' is returned if the put succeeded, and 'false' when it did not. If 'false' is returned the caller needs to retry the put as implied today.

        Gliffy Diagrams


            Issue Links



                • Assignee:
                  kabirkhan Kabir Khan
                  kabirkhan Kabir Khan
                • Votes:
                  0 Vote for this issue
                  1 Start watching this issue


                  • Created: