@@ -33,9 +33,9 @@ final class ConfiguratorRegistry {
3333 @ GuardedBy ("this" )
3434 private boolean wasConfiguratorsSet ;
3535 @ GuardedBy ("this" )
36- private boolean configFrozen ;
37- @ GuardedBy ("this" )
3836 private List <Configurator > configurators = Collections .emptyList ();
37+ @ GuardedBy ("this" )
38+ private int getConfiguratorsCallCountBeforeSet = 0 ;
3939
4040 ConfiguratorRegistry () {}
4141
@@ -56,22 +56,31 @@ public static synchronized ConfiguratorRegistry getDefaultRegistry() {
5656 * @throws IllegalStateException if this method is called more than once
5757 */
5858 public synchronized void setConfigurators (List <? extends Configurator > configurators ) {
59- if (configFrozen ) {
59+ if (wasConfiguratorsSet ) {
6060 throw new IllegalStateException ("Configurators are already set" );
6161 }
6262 this .configurators = Collections .unmodifiableList (new ArrayList <>(configurators ));
63- configFrozen = true ;
6463 wasConfiguratorsSet = true ;
6564 }
6665
6766 /**
6867 * Returns a list of the configurators in this registry.
6968 */
7069 public synchronized List <Configurator > getConfigurators () {
71- configFrozen = true ;
70+ if (!wasConfiguratorsSet ) {
71+ getConfiguratorsCallCountBeforeSet ++;
72+ }
7273 return configurators ;
7374 }
7475
76+ /**
77+ * Returns the number of times getConfigurators() was called before
78+ * setConfigurators() was successfully invoked.
79+ */
80+ public synchronized int getGetConfiguratorsCallCountBeforeSet () {
81+ return getConfiguratorsCallCountBeforeSet ;
82+ }
83+
7584 public synchronized boolean wasSetConfiguratorsCalled () {
7685 return wasConfiguratorsSet ;
7786 }
0 commit comments