Buggy code:
public class DataSourceStatisticsListener extends AbstractServiceListener < Object > { private final ManagementResourceRegistration registration ; private final String dsName ; public DataSourceStatisticsListener ( final ManagementResourceRegistration registration , final String dsName ) { } public void transition ( final ServiceController < ? extends Object > controller , final ServiceController . Transition transition ) { switch ( transition ) { case STARTING_to_UP : { CommonDeployment deploymentMD = ( ( AbstractDataSourceService ) ( controller . getService ( ) ) ) . getDeploymentMD ( ) ; StatisticsPlugin jdbcStats = deploymentMD . getDataSources ( ) [ 0 ] . getStatistics ( ) ; StatisticsPlugin poolStats = deploymentMD . getDataSources ( ) [ 0 ] . getPool ( ) . getStatistics ( ) ; int jdbcStatsSize = jdbcStats . getNames ( ) . size ( ) ; int poolStatsSize = poolStats . getNames ( ) . size ( ) ; if ( ( jdbcStatsSize > 0 ) || ( poolStatsSize > 0 ) ) { <START_BUG> ManagementResourceRegistration subRegistration = registration . registerOverrideModel ( dsName , OVERRIDE_DS_DESC ) ; <END_BUG> if ( jdbcStatsSize > 0 ) { ManagementResourceRegistration jdbcRegistration = subRegistration . registerSubModel ( PathElement . pathElement ( "statistics" , "jdbc" ) , new org . jboss . as . connector . StatisticsDescriptionProvider ( DataSourcesSubsystemProviders . RESOURCE_NAME , "statistics" , jdbcStats ) ) ; jdbcRegistration . setRuntimeOnly ( true ) ; jdbcRegistration . registerOperationHandler ( "clear-statistics" , new org . jboss . as . connector . subsystems . ClearStatisticsHandler ( jdbcStats ) , CLEAR_STATISTICS_DESC , false ) ; for ( String statName : jdbcStats . getNames ( ) ) { jdbcRegistration . registerMetric ( statName , new org . jboss . as . connector . pool . PoolMetrics . ParametrizedPoolMetricsHandler ( jdbcStats ) ) ; } } if ( poolStatsSize > 0 ) { ManagementResourceRegistration poolRegistration = subRegistration . registerSubModel ( PathElement . pathElement ( "statistics" , "pool" ) , new org . jboss . as . connector . StatisticsDescriptionProvider ( DataSourcesSubsystemProviders . RESOURCE_NAME , "statistics" , poolStats ) ) ; poolRegistration . setRuntimeOnly ( true ) ; poolRegistration . registerOperationHandler ( "clear-statistics" , new org . jboss . as . connector . subsystems . ClearStatisticsHandler ( poolStats ) , CLEAR_STATISTICS_DESC , false ) ; for ( String statName : poolStats . getNames ( ) ) { poolRegistration . registerMetric ( statName , new org . jboss . as . connector . pool . PoolMetrics . ParametrizedPoolMetricsHandler ( poolStats ) ) ; } } } break ; } case UP_to_STOP_REQUESTED : { ManagementResourceRegistration subRegistration = registration . getOverrideModel ( dsName ) ; if ( subRegistration != null ) { subRegistration . unregisterSubModel ( PathElement . pathElement ( "statistics" , "jdbc" ) ) ; subRegistration . unregisterSubModel ( PathElement . pathElement ( "statistics" , "pool" ) ) ; registration . unregisterOverrideModel ( dsName ) ; } break ; } } } }

Fix:
ManagementResourceRegistration subRegistration = ( registration . isAllowsOverride ( ) ) ? registration . registerOverrideModel ( dsName , OVERRIDE_DS_DESC ) : registration ;