Buggy code:
private synchronized DiscoveryDriver getDriver ( String driverType ) { } private void init ( AbstractStorageDriver driver ) { } @ Override public void collectStatisticsInformation ( AccessProfile accessProfile ) throws BaseCollectionException { } @ Override public void scan ( AccessProfile accessProfile ) throws BaseCollectionException { } @ Override public void discover ( AccessProfile accessProfile ) throws BaseCollectionException { } private void discoverStorageSystem ( DiscoveryDriver driver , AccessProfile accessProfile ) throws BaseCollectionException { } private List < StoragePool > discoverStoragePools ( DiscoveryDriver driver , AccessProfile accessProfile ) throws BaseCollectionException { } private Map < String , List < StoragePort > > discoverStoragePorts ( DiscoveryDriver driver , Set < Network > networksToUpdate , AccessProfile accessProfile ) throws BaseCollectionException { URI storageSystemId = accessProfile . getSystemId ( ) ; StorageSystem storageSystem = _dbClient . queryObject ( com . emc . storageos . storagedriver . model . StorageSystem . class , storageSystemId ) ; Map < String , List < StoragePort > > storagePorts = new HashMap < > ( ) ; Map < com . emc . storageos . storagedriver . model . StoragePort , StoragePort > driverPortsToDBPorts = new HashMap < > ( ) ; List < StoragePort > newStoragePorts = new ArrayList < > ( ) ; List < StoragePort > existingStoragePorts = new ArrayList < > ( ) ; List < String > endpoints = new ArrayList < > ( ) ; com . emc . storageos . storagedriver . model . StorageSystem driverStorageSystem = initStorageSystem ( storageSystem ) ; try { _log . info ( "discoverPorts<seq2seq4repair_space>for<seq2seq4repair_space>storage<seq2seq4repair_space>system<seq2seq4repair_space>{}<seq2seq4repair_space>-<seq2seq4repair_space>start" , storageSystemId ) ; List < com . emc . storageos . storagedriver . model . StoragePort > driverStoragePorts = new ArrayList < > ( ) ; DriverTask task = driver . discoverStoragePorts ( driverStorageSystem , driverStoragePorts ) ; if ( ( task . getStatus ( ) ) == ( TaskStatus . READY ) ) { for ( com . emc . storageos . storagedriver . model . StoragePort driverPort : driverStoragePorts ) { StoragePort storagePort = null ; String portNativeGuid = NativeGUIDGenerator . generateNativeGuid ( storageSystem , driverPort . getNativeId ( ) , PORT ) ; @ SuppressWarnings ( "deprecation" ) List < URI > portURIs = _dbClient . queryByConstraint ( Factory . getStoragePortByNativeGuidConstraint ( portNativeGuid ) ) ; for ( URI portUri : portURIs ) { StoragePort port = _dbClient . queryObject ( com . emc . storageos . storagedriver . model . StoragePort . class , portUri ) ; if ( ( port . getStorageDevice ( ) . equals ( storageSystemId ) ) && ( ! ( port . getInactive ( ) ) ) ) { storagePort = port ; break ; } } if ( storagePort == null ) { storagePort = new StoragePort ( ) ; prepareNewPort ( storagePort , driverPort ) ; storagePort . setNativeGuid ( portNativeGuid ) ; storagePort . setStorageDevice ( storageSystemId ) ; if ( ( driverPort . getNetworkId ( ) ) != null ) { Network portNetwork = getNetworkForStoragePort ( driverPort ) ; storagePort . setNetwork ( portNetwork . getId ( ) ) ; portNetwork . addEndpoints ( new ArrayList ( Arrays . asList ( driverPort . getPortNetworkId ( ) ) ) , true ) ; networksToUpdate . add ( portNetwork ) ; } storagePort . setTcpPortNumber ( driverPort . getTcpPortNumber ( ) ) ; storagePort . setRegistrationStatus ( REGISTERED . toString ( ) ) ; _log . info ( "Creating<seq2seq4repair_space>new<seq2seq4repair_space>storage<seq2seq4repair_space>port<seq2seq4repair_space>using<seq2seq4repair_space>NativeGuid<seq2seq4repair_space>:<seq2seq4repair_space>{}" , portNativeGuid ) ; newStoragePorts . add ( storagePort ) ; } else { existingStoragePorts . add ( storagePort ) ; } storagePort . setPortNetworkId ( driverPort . getPortNetworkId ( ) ) ; storagePort . setDiscoveryStatus ( VISIBLE . name ( ) ) ; storagePort . setCompatibilityStatus ( COMPATIBLE . name ( ) ) ; storagePort . setOperationalStatus ( driverPort . getOperationalStatus ( ) ) ; storagePort . setAvgBandwidth ( driverPort . getAvgBandwidth ( ) ) ; storagePort . setPortSpeed ( driverPort . getPortSpeed ( ) ) ; if ( ( driverPort . getUtilizationMetric ( ) ) != null ) { StringMap usageMetrics = storagePort . getMetrics ( ) ; MetricsKeys . putDouble ( portMetric , driverPort . getUtilizationMetric ( ) , usageMetrics ) ; storagePort . setMetrics ( usageMetrics ) ; } driverPortsToDBPorts . put ( driverPort , storagePort ) ; } storagePorts . put ( ExternalDeviceCommunicationInterface . NEW , newStoragePorts ) ; storagePorts . put ( ExternalDeviceCommunicationInterface . EXISTING , existingStoragePorts ) ; <START_BUG> processStorageHADomains ( storageSystem , driverPortsToDBPorts ) ; <END_BUG> } else { String errorMsg = String . format ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>discover<seq2seq4repair_space>storage<seq2seq4repair_space>ports<seq2seq4repair_space>for<seq2seq4repair_space>system<seq2seq4repair_space>%s<seq2seq4repair_space>of<seq2seq4repair_space>type<seq2seq4repair_space>%s" , accessProfile . getSystemId ( ) , accessProfile . getSystemType ( ) ) ; throw new com . emc . storageos . volumecontroller . impl . externaldevice . ExternalDeviceCollectionException ( false , ServiceCode . DISCOVERY_ERROR , null , errorMsg , null , null ) ; } String message = String . format ( "Storage<seq2seq4repair_space>ports<seq2seq4repair_space>of<seq2seq4repair_space>storage<seq2seq4repair_space>array<seq2seq4repair_space>%s<seq2seq4repair_space>with<seq2seq4repair_space>native<seq2seq4repair_space>id<seq2seq4repair_space>%s<seq2seq4repair_space>were<seq2seq4repair_space>discovered<seq2seq4repair_space>successfully." , storageSystem . getId ( ) , storageSystem . getNativeGuid ( ) ) ; _log . info ( message ) ; return storagePorts ; } catch ( Exception e ) { String message = String . format ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>discover<seq2seq4repair_space>storage<seq2seq4repair_space>ports<seq2seq4repair_space>of<seq2seq4repair_space>storage<seq2seq4repair_space>array<seq2seq4repair_space>%s<seq2seq4repair_space>with<seq2seq4repair_space>native<seq2seq4repair_space>id<seq2seq4repair_space>%s<seq2seq4repair_space>:<seq2seq4repair_space>%s<seq2seq4repair_space>." , storageSystem . getId ( ) , storageSystem . getNativeGuid ( ) , e . getMessage ( ) ) ; _log . info ( message ) ; throw e ; } finally { _log . info ( "Discovery<seq2seq4repair_space>of<seq2seq4repair_space>storage<seq2seq4repair_space>ports<seq2seq4repair_space>of<seq2seq4repair_space>storage<seq2seq4repair_space>system<seq2seq4repair_space>{}<seq2seq4repair_space>of<seq2seq4repair_space>type<seq2seq4repair_space>{}<seq2seq4repair_space>-<seq2seq4repair_space>end" , accessProfile . getSystemId ( ) , accessProfile . getSystemType ( ) ) ; } } private void prepareNewPort ( StoragePort storagePort , com . emc . storageos . storagedriver . model . StoragePort driverPort ) { } private com . emc . storageos . storagedriver . model . StorageSystem initStorageSystem ( StorageSystem storageSystem ) { } private Network getNetworkForStoragePort ( com . emc . storageos . storagedriver . model . StoragePort driverPort ) { } private void processStorageHADomains ( StorageSystem storageSystem , Map < com . emc . storageos . storagedriver . model . StoragePort , StoragePort > driverPortsToDBPorts ) { } }

Fix:
processStorageHADomains ( storageSystem , Collections . unmodifiableMap ( driverPortsToDBPorts ) ) ;