diff --git includes/form.inc includes/form.inc
index 41967f9..1478197 100644
--- includes/form.inc
+++ includes/form.inc
@@ -1164,7 +1164,9 @@ function form_get_error($element) {
   $form = form_set_error();
   $key = $element['#parents'][0];
   if (isset($form[$key])) {
-    return $form[$key];
+    // If the value is empty, return a default error string. This is needed
+    // for _form_set_class() which tests whether the returned value is empty.
+    return $form[$key] ? $form[$key] : 'error';
   }
   $key = implode('][', $element['#parents']);
   if (isset($form[$key])) {
diff --git modules/simpletest/tests/form.test modules/simpletest/tests/form.test
index 8997cb1..222cf05 100644
--- modules/simpletest/tests/form.test
+++ modules/simpletest/tests/form.test
@@ -784,3 +784,48 @@ class FormsRebuildTestCase extends DrupalWebTestCase {
     $this->assertFieldById('edit-text-2', 'DEFAULT 2', t('A newly added textfield was initialized with its default value.'));
   }
 }
+
+/**
+ * Test error class handling.
+ */
+class FormsErrorClassTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Form element error class',
+      'description' => 'Tests that form elements get an error class when form_set_error() is called with an empty message.',
+      'group' => 'Form API',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('form_test');
+  }
+
+  /**
+   * Tests if the error class is applied to all three texfields on a form.
+   */
+  function testErrorClasses() {
+    $edit = array();
+    $this->drupalPost('form-test/error-classes', $edit, t('Submit'));
+    $this->assertFieldByXPath('//input[@name="title1" and contains(@class,"error")]', "DEFAULT", 'Error class added to title1.');
+    $this->assertFieldByXPath('//input[@name="title2" and contains(@class,"error")]', "DEFAULT", 'Error class added to title2.');
+    $this->assertFieldByXPath('//input[@name="title3" and contains(@class,"error")]', "DEFAULT", 'Error class added to title3.');
+    $this->assertNoText('form_test_error_class success.', t('The form failed validation.'));
+
+    $edit['title3'] = $edit['title2'] = $edit['title1'] = $this->randomName();
+    $this->drupalPost('form-test/error-classes', $edit, t('Submit'));
+    $this->assertFieldByXPath('//input[@name="title1" and contains(@class,"error")]', $edit['title1'], 'Error class added to title1.');
+    $this->assertFieldByXPath('//input[@name="title2" and contains(@class,"error")]', $edit['title2'], 'Error class added to title2.');
+    $this->assertFieldByXPath('//input[@name="title3" and contains(@class,"error")]', $edit['title3'], 'Error class added to title3.');
+    $this->assertNoText('form_test_error_class success.', t('The form failed validation.'));
+
+    $edit['title2'] = $edit['title1'] . $this->randomName();
+    $edit['title3'] = $edit['title2'] . $this->randomName();
+    $this->drupalPost('form-test/error-classes', $edit, t('Submit'));
+    $this->assertNoFieldByXPath('//input[@name="title1" and contains(@class,"error")]', $edit['title1'], 'Error class not added to title1.');
+    $this->assertNoFieldByXPath('//input[@name="title2" and contains(@class,"error")]', $edit['title2'], 'Error class not added to title2.');
+    $this->assertNoFieldByXPath('//input[@name="title3" and contains(@class,"error")]', $edit['title3'], 'Error class not added to title3.');
+    $this->assertText('form_test_error_class success.', t('The form passed validation.'));
+  }
+}
+
diff --git modules/simpletest/tests/form_test.module modules/simpletest/tests/form_test.module
index b7b2b5c..ae42fca 100644
--- modules/simpletest/tests/form_test.module
+++ modules/simpletest/tests/form_test.module
@@ -118,6 +118,14 @@ function form_test_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  $items['form-test/error-classes'] = array(
+    'title' => 'Form error class test',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('form_test_error_class'),
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+
   return $items;
 }
 
@@ -889,3 +897,55 @@ function form_test_form_form_test_state_persist_alter(&$form, &$form_state) {
     $form_state['cache'] = TRUE;
   }
 }
+
+/**
+ * Form constructor for testing error classes.
+ */
+function form_test_error_class($form, &$form_state) {
+  // Three textfeilds with the same default value.
+  $form['title1'] = array(
+    '#type' => 'textfield',
+    '#title' => 'title1',
+    '#default_value' => 'DEFAULT',
+    '#required' => TRUE,
+  );
+  $form['title2'] = array(
+    '#type' => 'textfield',
+    '#title' => 'title2',
+    '#default_value' => 'DEFAULT',
+    '#required' => TRUE,
+  );
+  $form['title3'] = array(
+    '#type' => 'textfield',
+    '#title' => 'title3',
+    '#default_value' => 'DEFAULT',
+    '#required' => TRUE,
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit'),
+  );
+  return $form;
+}
+
+/**
+ * Form validation handler which requires all title values to be unique.
+ */
+function form_test_error_class_validate($form, &$form_state) {
+  $values[] = $form_state['values']['title1'];
+  $values[] = $form_state['values']['title3'];
+  $values[] = $form_state['values']['title2'];
+  $unique = array_unique($values);
+  if (count($unique) < count($values)) {
+    form_set_error('title1', 'Fields must have unique values');
+    form_set_error('title2');
+    form_set_error('title3');
+  }
+}
+
+/**
+ * Form submit handler that just sets a message.
+ */
+function form_test_error_class_submit($form, &$form_state) {
+  drupal_set_message('form_test_error_class success.');
+}
