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

Fix incorrect usage of AtomicMapFieldUpdater.putAtomic()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.0.Alpha16
    • 3.0.0.Alpha15
    • Management
    • None

      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.

              kkhan1@redhat.com Kabir Khan
              kkhan1@redhat.com Kabir Khan
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: