joomla/joomla-cms — pull request #3941 by itbra (2014-07-22 13:47:14+00:00)
Title: Don't queue empty messages

Take for instance `JModelAdmin::save()`. This method triggers two events while processing the store - event_before_save and event_after_save. The former event handlers' response is catched and evaluated. However, it is expected that the error that might have occured was thrown by the table object passed in. In fact the error should be expected from the dispatcher, since errors are either thrown directly by the plugin or set via `$this->subject->setError` by the event handler where subject is the JEventDispatcher object. So the error setting block for this example should rather be
```
// Trigger the onContentBeforeSave event.
$result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, $table, $isNew));

if (in_array(false, $result, true))
{
$this->setError($dispatcher->getError());
return false;
}
```

This however might be one place where an empty entry is added to the queue. So this block should additionally check for the error's existance.
```
if (in_array(false, $result, true))
{
if ($dispatcher->getError())
{
$this->setError($dispatcher->getError());
}
}
```

I'm sure there are many more places where this kind of empty errors/messages are produced and added to the messageQueue. To circumvent this issue i added a check to drop empty entries as it makes no sense to render message containers with no content.

Please let me know, what you think about it!