diff --git a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
index 4c8feb0..f60c8b2 100644
--- a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
+++ b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
@@ -90,7 +90,10 @@ protected function getDerivatives(array $base_plugin_definitions) {
           // Use this definition as defaults if a plugin already defined
           // itself as this derivative.
           if ($derivative_id && isset($base_plugin_definitions[$plugin_id])) {
-            $derivative_definition = $base_plugin_definitions[$plugin_id] + ($derivative_definition ?: array());
+            $filtered_base = array_filter($base_plugin_definitions[$plugin_id]);
+            $derivative_definition = $filtered_base + ($derivative_definition ?: array());
+            // Add back any empty keys that the derivative didn't have.
+            $derivative_definition += $base_plugin_definitions[$plugin_id];
           }
           $plugin_definitions[$plugin_id] = $derivative_definition;
         }
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php
index a46f42c..002f071 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php
@@ -17,6 +17,13 @@
 class DerivativeDiscoveryDecoratorTest extends UnitTestCase {
 
   /**
+   * The mock main discovery object.
+   *
+   * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $discoveryMain;
+
+  /**
    * {@inheritdoc}
    */
   public static function getInfo() {
@@ -28,6 +35,13 @@ public static function getInfo() {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    $this->discoveryMain = $discovery_main = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface');
+  }
+
+  /**
    * Tests the getDerivativeFetcher method.
    *
    * @see  \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDerivativeFetcher().
@@ -39,12 +53,11 @@ public function testGetDerivativeFetcher() {
       'derivative' => '\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery',
     );
 
-    $discovery_main = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface');
-    $discovery_main->expects($this->any())
+    $this->discoveryMain->expects($this->any())
       ->method('getDefinitions')
       ->will($this->returnValue($definitions));
 
-    $discovery = new DerivativeDiscoveryDecorator($discovery_main);
+    $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
     $definitions = $discovery->getDefinitions();
 
     // Ensure that both test derivatives got added.
@@ -66,12 +79,11 @@ public function testGetDerivativeFetcherWithAnnotationObjects() {
       'derivative' => '\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscoveryWithObject',
     );
 
-    $discovery_main = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface');
-    $discovery_main->expects($this->any())
+    $this->discoveryMain->expects($this->any())
       ->method('getDefinitions')
       ->will($this->returnValue($definitions));
 
-    $discovery = new DerivativeDiscoveryDecorator($discovery_main);
+    $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
     $definitions = $discovery->getDefinitions();
 
     // Ensure that both test derivatives got added.
@@ -99,12 +111,52 @@ public function testInvalidDerivativeFetcher() {
       'id' => 'invalid_discovery',
       'derivative' => '\Drupal\system\Tests\Plugin\DerivativeTest',
     );
-    $discovery_main = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface');
-    $discovery_main->expects($this->any())
+    $this->discoveryMain->expects($this->any())
       ->method('getDefinitions')
       ->will($this->returnValue($definitions));
 
-    $discovery = new DerivativeDiscoveryDecorator($discovery_main);
+    $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
     $discovery->getDefinitions();
   }
+
+  /**
+   * Tests derivative definitions when a definition already exists.
+   */
+  public function testExistingDerivative() {
+    $definitions = array();
+    $definitions['non_container_aware_discovery'] = array(
+      'id' => 'non_container_aware_discovery',
+      'derivative' => '\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery',
+      'string' => 'string',
+      'empty_string' => 'not_empty',
+      'array' => array('one', 'two'),
+      'empty_array' => array('three'),
+      'null_value' => TRUE,
+    );
+    // This will clash with a derivative id.
+    // @see \Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery
+    $definitions['non_container_aware_discovery:test_discovery_1'] = array(
+      'id' => 'non_container_aware_discovery:test_discovery_1',
+      'string' => 'string',
+      'empty_string' => '',
+      'array' => array('one', 'two'),
+      'empty_array' => array(),
+      'null_value' => NULL,
+    );
+
+    $this->discoveryMain->expects($this->any())
+      ->method('getDefinitions')
+      ->will($this->returnValue($definitions));
+
+    $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
+    $returned_definitions = $discovery->getDefinitions();
+
+    // If the definition was merged, there should only be two.
+    $this->assertCount(2, $returned_definitions);
+
+    $expected = $definitions['non_container_aware_discovery'];
+    $expected['id'] = 'non_container_aware_discovery:test_discovery_1';
+    $this->assertArrayEquals($expected, $returned_definitions['non_container_aware_discovery:test_discovery_1']);
+  }
+
 }
diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php
index f64dca0..898f40e 100644
--- a/core/tests/Drupal/Tests/UnitTestCase.php
+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -83,6 +83,18 @@ protected function getRandomGenerator() {
     return $this->randomGenerator;
   }
 
+  /**
+   * Asserts if two arrays are equal by sorting them first.
+   *
+   * @param array $expected
+   * @param array $actual
+   * @param string $message
+   */
+  protected function assertArrayEquals(array $expected, array $actual, $message = NULL) {
+    ksort($expected);
+    ksort($actual);
+    $this->assertEquals($expected, $actual, $message);
+  }
 
   /**
    * Returns a stub config factory that behaves according to the passed in array.
