NULL variables being passed to Twig templates lead to exceptions - eg. #1961872: Convert html.tpl.php to Twig, #1843746: Convert views/templates/views-view-field.tpl.php to Twig .
NULL variables can simply be the result of calling drupal_render() on a renderable array with '#access' => FALSE within a preprocess/process function - #1975442: drupal_render() should always return a string., so it's very likely that this will turn up more in contrib than we're currently seeing in core.
I believe the offending code is:
<?php
// Optimized version
if (!isset($context[$item])) {
// We don't want to throw an exception, but issue a warning instead.
// This is the easiest way to do so.
// @todo Decide based on prod vs. dev setting
$msg = new \Twig_Error(t('@item could not be found in _context', array('@item'=> $item)));
trigger_error($msg->getMessage(), E_USER_WARNING);
return NULL;
}
?>
in /core/lib/Drupal/Core/Template/TwigTemplate.php
I propose we change:
if (!isset($context[$item])) {
to something like:
if (!isset($context[$item]) && !is_null($context[$item])) {