diff --git a/includes/common.inc b/includes/common.inc
index c6638dc..512535d 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -6140,9 +6140,14 @@ function element_children(&$elements, $sort = FALSE) {
   $sortable = FALSE;
   foreach ($elements as $key => $value) {
     if ($key === '' || $key[0] !== '#') {
-      $children[$key] = $value;
-      if (is_array($value) && isset($value['#weight'])) {
-        $sortable = TRUE;
+      if (is_array($value)) {
+        $children[$key] = $value;
+        if (isset($value['#weight'])) {
+          $sortable = TRUE;
+        }
+      }
+      else {
+        drupal_set_message(t('@key is an invalid render array key.', array('@key' => $key)));
       }
     }
   }
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 177e457..2663eea 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -1708,6 +1708,19 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
     ));
   }
 
+  /**
+   * Test rendering elements with invalid keys.
+   */
+  function testDrupalRenderInvalidKeys() {
+    // Define an element with an invalid key.
+    $key = 'not valid';
+    $element = array(
+      $key => 'fail',
+    );
+    $this->drupalSetContent(drupal_render($element));
+    $this->assertText(t('@key is an invalid render array key.', array('@key' => $key)));
+  }
+
   protected function assertRenderedElement(array $element, $xpath, array $xpath_args = array()) {
     $original_element = $element;
     $this->drupalSetContent(drupal_render($element));
