Buggy code:
private final Object policyUnitsLock = new Object ( ) ; private final ConcurrentHashMap < Guid , Semaphore > clusterLockMap = new ConcurrentHashMap < > ( ) ; private final VdsFreeMemoryChecker noWaitingMemoryChecker = new VdsFreeMemoryChecker ( new NonWaitingDelayer ( ) ) ; private final Map < Guid , Boolean > clusterId2isHaReservationSafe = new HashMap < > ( ) ; private PendingResourceManager getPendingResourceManager ( ) { } @ Inject private SchedulingManager ( ) { } @ PostConstruct public void init ( ) { } private void loadExternalScheduler ( ) { } private void reloadPolicyUnits ( ) { } public List < ClusterPolicy > getClusterPolicies ( ) { } public ClusterPolicy getClusterPolicy ( Guid clusterPolicyId ) { } public ClusterPolicy getClusterPolicy ( String name ) { } private ClusterPolicy getDefaultClusterPolicy ( ) { } public Map < Guid , PolicyUnitImpl > getPolicyUnitsMap ( ) { } private void loadClusterPolicies ( ) { } private void loadPolicyUnits ( ) { } private static class SchedulingResult { Map < Guid , Pair < EngineMessage , String > > filteredOutReasons ; Map < Guid , String > hostNames ; PerHostMessages details ; String message ; Guid vdsSelected = null ; public SchedulingResult ( ) { } public Guid getVdsSelected ( ) { } public void setVdsSelected ( Guid vdsSelected ) { } public void addReason ( Guid id , String hostName , EngineMessage filterType , String filterName ) { } public Set < Map . Entry < Guid , Pair < EngineMessage , String > > > getReasons ( ) { } public Collection < String > getReasonMessages ( ) { } private PerHostMessages getDetails ( ) { } public String getMessage ( ) { } public void setMessage ( String message ) { } } public Guid schedule ( VDSGroup cluster , VM vm , List < Guid > hostBlackList , List < Guid > hostWhiteList , List < Guid > destHostIdList , List < String > messages , VdsFreeMemoryChecker memoryChecker , String correlationId ) { } private void releaseCluster ( Guid cluster ) { } private void lockCluster ( Guid cluster ) throws InterruptedException { } private void prepareClusterLock ( Guid cluster ) { } private void markVfsAsUsedByVm ( Guid hostId , Guid vmId , Map < Guid , String > passthroughVnicToVfMap ) { } private void refreshCachedPendingValues ( List < VDS > vdsList ) { } private Guid selectBestHost ( VDSGroup cluster , VM vm , List < Guid > destHostIdList , List < VDS > availableVdsList , ClusterPolicy policy , Map < String , String > parameters ) { } private void checkAllowOverbooking ( VDSGroup cluster ) { } private boolean shouldWeighClusterHosts ( VDSGroup cluster , List < VDS > vdsList ) { } public boolean canSchedule ( VDSGroup cluster , VM vm , List < Guid > vdsBlackList , List < Guid > vdsWhiteList , List < Guid > destVdsIdList , List < String > messages ) { } static List < Guid > getEntityIds ( List < ? extends BusinessEntity < Guid > > entities ) { } private Map < String , String > createClusterPolicyParameters ( VDSGroup cluster ) { } private void updateInitialHostList ( List < VDS > vdsList , List < Guid > list , boolean contains ) { } private List < VDS > runFilters ( ArrayList < Guid > filters , List < VDS > hostList , VM vm , Map < String , String > parameters , Map < Guid , Integer > filterPositionMap , List < String > messages , VdsFreeMemoryChecker memoryChecker , boolean shouldRunExternalFilters , String correlationId ) { SchedulingManager . SchedulingResult result = new SchedulingManager . SchedulingResult ( ) ; ArrayList < PolicyUnitImpl > internalFilters = new ArrayList < > ( ) ; ArrayList < PolicyUnitImpl > externalFilters = new ArrayList < > ( ) ; <START_BUG> filters = new ArrayList ( filters ) ; <END_BUG> sortFilters ( filters , filterPositionMap ) ; for ( Guid filter : filters ) { PolicyUnitImpl filterPolicyUnit = policyUnits . get ( filter ) ; if ( filterPolicyUnit . getPolicyUnit ( ) . isInternal ( ) ) { internalFilters . add ( filterPolicyUnit ) ; } else { if ( filterPolicyUnit . getPolicyUnit ( ) . isEnabled ( ) ) { externalFilters . add ( filterPolicyUnit ) ; } } } if ( ( hostList == null ) || ( hostList . isEmpty ( ) ) ) { messages . add ( SCHEDULING_NO_HOSTS . name ( ) ) ; messages . addAll ( result . getReasonMessages ( ) ) ; return hostList ; } hostList = runInternalFilters ( internalFilters , hostList , vm , parameters , filterPositionMap , memoryChecker , correlationId , result ) ; if ( ( ( ( shouldRunExternalFilters && ( Config . < Boolean > getValue ( ExternalSchedulerEnabled ) ) ) && ( ! ( externalFilters . isEmpty ( ) ) ) ) && ( hostList != null ) ) && ( ! ( hostList . isEmpty ( ) ) ) ) { hostList = runExternalFilters ( externalFilters , hostList , vm , parameters , messages , correlationId , result ) ; } if ( ( hostList == null ) || ( hostList . isEmpty ( ) ) ) { messages . add ( SCHEDULING_ALL_HOSTS_FILTERED_OUT . name ( ) ) ; messages . addAll ( result . getReasonMessages ( ) ) ; } return hostList ; } private List < VDS > runInternalFilters ( ArrayList < PolicyUnitImpl > filters , List < VDS > hostList , VM vm , Map < String , String > parameters , Map < Guid , Integer > filterPositionMap , VdsFreeMemoryChecker memoryChecker , String correlationId , SchedulingManager . SchedulingResult result ) { } private Set < Guid > toIdSet ( List < VDS > hostList ) { } private void logFilterActions ( List < VDS > oldList , Set < Guid > newSet , EngineMessage actionName , String filterName , SchedulingManager . SchedulingResult result , String correlationId ) { }

Fix:
filters = ( filters != null ) ? new ArrayList ( filters ) : new ArrayList < Guid > ( ) ;