Buggy code:
public final class ActivityManager implements IActivityManager { static boolean isActivityDefinitionChildOf ( String ancestor , String id , Map activityDefinitionsById ) { } private Set activeActivityIds = new HashSet ( ) ; private Map activitiesById = new HashMap ( ) ; private Map activityDefinitionsById = new HashMap ( ) ; private IActivityManagerEvent activityManagerEvent ; private List activityManagerListeners ; private Set definedActivityIds = new HashSet ( ) ; private Set enabledActivityIds = new HashSet ( ) ; private ExtensionActivityRegistry extensionActivityRegistry ; private Map patternBindingsByActivityId = new HashMap ( ) ; public ActivityManager ( ) { } public void addActivityManagerListener ( IActivityManagerListener activityManagerListener ) { } public Set getActiveActivityIds ( ) { } public IActivity getActivity ( String activityId ) { } public Set getDefinedActivityIds ( ) { } public Set getEnabledActivityIds ( ) { } public boolean match ( String string , Set activityIds ) { } public void removeActivityManagerListener ( IActivityManagerListener activityManagerListener ) { } public void setActiveActivityIds ( Set activeActivityIds ) { } public void setEnabledActivityIds ( Set enabledActivityIds ) { } private void fireActivityManagerChanged ( ) { } private void notifyActivities ( Collection activityIds ) { } private void readRegistry ( ) { Collection activityDefinitions = new ArrayList ( ) ; activityDefinitions . addAll ( extensionActivityRegistry . getActivityDefinitions ( ) ) ; Map activityDefinitionsById = new HashMap ( ActivityDefinition . activityDefinitionsById ( activityDefinitions , false ) ) ; for ( Iterator iterator = activityDefinitionsById . values ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { IActivityDefinition activityDefinition = ( ( IActivityDefinition ) ( iterator . next ( ) ) ) ; String name = activityDefinition . getName ( ) ; if ( ( name == null ) || ( ( name . length ( ) ) == 0 ) ) iterator . remove ( ) ; } for ( Iterator iterator = activityDefinitionsById . keySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) if ( ! ( ActivityManager . isActivityDefinitionChildOf ( null , ( ( String ) ( iterator . next ( ) ) ) , activityDefinitionsById ) ) ) iterator . remove ( ) ; Map activityPatternBindingDefinitionsByActivityId = ActivityPatternBindingDefinition . activityPatternBindingDefinitionsByActivityId ( extensionActivityRegistry . getActivityPatternBindingDefinitions ( ) ) ; Map patternBindingsByActivityId = new HashMap ( ) ; for ( Iterator iterator = activityPatternBindingDefinitionsByActivityId . entrySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { Map . Entry entry = ( ( Map . Entry ) ( iterator . next ( ) ) ) ; String activityId = ( ( String ) ( entry . getKey ( ) ) ) ; if ( activityDefinitionsById . containsKey ( activityId ) ) { Collection activityPatternBindingDefinitions = ( ( Collection ) ( entry . getValue ( ) ) ) ; if ( activityPatternBindingDefinitions != null ) for ( Iterator iterator2 = activityPatternBindingDefinitions . iterator ( ) ; iterator2 . hasNext ( ) ; ) { IActivityPatternBindingDefinition activityPatternBindingDefinition = ( ( IActivityPatternBindingDefinition ) ( iterator2 . next ( ) ) ) ; String pattern = activityPatternBindingDefinition . getPattern ( ) ; if ( ( pattern != null ) && ( ( pattern . length ( ) ) != 0 ) ) { IPatternBinding patternBinding = new PatternBinding ( activityPatternBindingDefinition . isInclusive ( ) , pattern ) ; List patternBindings = ( ( List ) ( patternBindingsByActivityId . get ( activityId ) ) ) ; if ( patternBindings == null ) { patternBindings = new ArrayList ( ) ; patternBindingsByActivityId . put ( activityId , patternBindings ) ; } patternBindings . add ( patternBinding ) ; } } } } this . activityDefinitionsById = activityDefinitionsById ; this . patternBindingsByActivityId = patternBindingsByActivityId ; boolean activityManagerChanged = false ; <START_BUG> Set definedActivityIds = new TreeSet ( activityDefinitionsById . keySet ( ) ) ; <END_BUG> if ( ! ( definedActivityIds . equals ( this . definedActivityIds ) ) ) { this . definedActivityIds = definedActivityIds ; activityManagerChanged = true ; } Collection updatedActivityIds = updateActivities ( activitiesById . keySet ( ) ) ; if ( activityManagerChanged ) fireActivityManagerChanged ( ) ; if ( updatedActivityIds != null ) notifyActivities ( updatedActivityIds ) ; } private boolean updateActivity ( Activity activity ) { } private Collection updateActivities ( Collection activityIds ) { } }

Fix:
Set definedActivityIds = new HashSet ( activityDefinitionsById . keySet ( ) ) ;