@@ -137,20 +137,20 @@ public IFeatureFlagBuffer clone() {
137137 int isolationIndex = isolationSize - 1 ;
138138 int currentIndex = currentSize - 1 ;
139139
140+ @ Nullable
141+ FeatureFlagEntry globalEntry = globalFlags == null ? null : globalFlags .get (globalIndex );
142+ @ Nullable
143+ FeatureFlagEntry isolationEntry =
144+ isolationFlags == null ? null : isolationFlags .get (isolationIndex );
145+ @ Nullable
146+ FeatureFlagEntry currentEntry = currentFlags == null ? null : currentFlags .get (currentIndex );
147+
140148 final @ NotNull java .util .Map <String , FeatureFlagEntry > uniqueFlags =
141149 new java .util .LinkedHashMap <>(maxSize );
142150
143151 // check if there is still room and remaining items to check
144152 while (uniqueFlags .size () < maxSize
145- && (globalIndex >= 0 || isolationIndex >= 0 || currentIndex >= 0 )) {
146- final FeatureFlagEntry globalEntry =
147- (globalFlags != null && globalIndex >= 0 ) ? globalFlags .get (globalIndex ) : null ;
148- final FeatureFlagEntry isolationEntry =
149- (isolationFlags != null && isolationIndex >= 0 )
150- ? isolationFlags .get (isolationIndex )
151- : null ;
152- final FeatureFlagEntry currentEntry =
153- (currentFlags != null && currentIndex >= 0 ) ? currentFlags .get (currentIndex ) : null ;
153+ && (globalEntry != null || isolationEntry != null || currentEntry != null )) {
154154
155155 @ Nullable FeatureFlagEntry entryToAdd = null ;
156156 @ Nullable ScopeType selectedBuffer = null ;
@@ -179,10 +179,18 @@ public IFeatureFlagBuffer clone() {
179179 // decrement only index of buffer that was selected
180180 if (ScopeType .CURRENT .equals (selectedBuffer )) {
181181 currentIndex --;
182+ currentEntry =
183+ currentFlags != null && currentIndex >= 0 ? currentFlags .get (currentIndex ) : null ;
182184 } else if (ScopeType .ISOLATION .equals (selectedBuffer )) {
183185 isolationIndex --;
186+ isolationEntry =
187+ isolationFlags != null && isolationIndex >= 0
188+ ? isolationFlags .get (isolationIndex )
189+ : null ;
184190 } else if (ScopeType .GLOBAL .equals (selectedBuffer )) {
185191 globalIndex --;
192+ globalEntry =
193+ globalFlags != null && globalIndex >= 0 ? globalFlags .get (globalIndex ) : null ;
186194 }
187195 } else {
188196 // no need to look any further since lists are sorted and we could not find any newer
0 commit comments