<p dir="auto">The TypeValidator seems to be useless whenever the value being validated is NULL. It completely ignores the type I've configured it to enforce.</p>
<p dir="auto">After debugging this for quite some time, it turns out the issue lies in the following line(s) of code:</p>
<p dir="auto"><a href="https://github.com/symfony/symfony/blob/2.4/src/Symfony/Component/Validator/Constraints/TypeValidator.php#L29">https://github.com/symfony/symfony/blob/2.4/src/Symfony/Component/Validator/Constraints/TypeValidator.php#L29</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        if (null === $value) {
            return;
        }"><pre class="notranslate"><code class="notranslate">        if (null === $value) {
            return;
        }
</code></pre></div>
<p dir="auto">What is the reasoning behind this short-circuit logic?</p>
<p dir="auto">If I configure my TypeValidator to enforce a value to be of type integer (or string, or whatever), then I expect it to throw a validation error whenever the value is not of the desired type... especially when it's NULL.</p>
<p dir="auto">Allowing NULL to always be valid regardless of what type you've asked it to enforce seems to be counter-intuitive and leads to some unusual/unexpected validation behavior.</p>
<p dir="auto">Coincidentally, I went through the history of this file and noticed that these very lines of code were once removed (2 years ago):</p>
<p dir="auto"><a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/symfony/symfony/commit/474b4abd6df1b9a7ff30e84f0d83b1540c87ed19/hovercard" href="https://github.com/symfony/symfony/commit/474b4abd6df1b9a7ff30e84f0d83b1540c87ed19"><tt>474b4ab</tt></a></p>
<p dir="auto">Why have they been reintroduced? Was this a merging oversight?</p>
<p dir="auto">Hello,</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.2.5</td>
</tr>
</tbody>
</table>
<p dir="auto">When trying to use the url matcher against a route that uses a condition it would crash if the condition is using the request object.</p>
<p dir="auto">I pushed an example of the issue on this branch -&gt; <a href="https://github.com/B-Galati/symfony-demo/tree/url-matcher-bug"></a> so that anyone can check. Going to <code class="notranslate">/en/blog/</code> would produce the bug.</p>
<p dir="auto">Here is an example of output using router:match command.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="❯ bin/console router:match /en/blog/rss.xml -vv

                                             
  [RuntimeException]                         
  Unable to get a property on a non-object.  
                                             

Exception trace:
 () at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php:83
 Symfony\Component\ExpressionLanguage\Node\GetAttrNode-&gt;evaluate() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php:81
 Symfony\Component\ExpressionLanguage\ExpressionLanguage-&gt;evaluate() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php:108
 Symfony\Component\Routing\Matcher\TraceableUrlMatcher-&gt;matchCollection() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Routing/Matcher/UrlMatcher.php:92
 Symfony\Component\Routing\Matcher\UrlMatcher-&gt;match() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php:37
 Symfony\Component\Routing\Matcher\TraceableUrlMatcher-&gt;getTraces() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php:95
 Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand-&gt;execute() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:265
 Symfony\Component\Console\Command\Command-&gt;run() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:852
 Symfony\Component\Console\Application-&gt;doRunCommand() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:189
 Symfony\Component\Console\Application-&gt;doRun() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application-&gt;doRun() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:120
 Symfony\Component\Console\Application-&gt;run() at /home/benoit/workspace/symfony_demo/bin/console:29"><pre class="notranslate"><code class="notranslate">❯ bin/console router:match /en/blog/rss.xml -vv

                                             
  [RuntimeException]                         
  Unable to get a property on a non-object.  
                                             

Exception trace:
 () at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php:83
 Symfony\Component\ExpressionLanguage\Node\GetAttrNode-&gt;evaluate() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php:81
 Symfony\Component\ExpressionLanguage\ExpressionLanguage-&gt;evaluate() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php:108
 Symfony\Component\Routing\Matcher\TraceableUrlMatcher-&gt;matchCollection() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Routing/Matcher/UrlMatcher.php:92
 Symfony\Component\Routing\Matcher\UrlMatcher-&gt;match() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php:37
 Symfony\Component\Routing\Matcher\TraceableUrlMatcher-&gt;getTraces() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php:95
 Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand-&gt;execute() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:265
 Symfony\Component\Console\Command\Command-&gt;run() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:852
 Symfony\Component\Console\Application-&gt;doRunCommand() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:189
 Symfony\Component\Console\Application-&gt;doRun() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application-&gt;doRun() at /home/benoit/workspace/symfony_demo/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:120
 Symfony\Component\Console\Application-&gt;run() at /home/benoit/workspace/symfony_demo/bin/console:29
</code></pre></div>
<p dir="auto">To reproduce, add a condition like <code class="notranslate">condition="request.isXmlHttpRequest()"</code> on any route then try to call the url matcher on this route like <code class="notranslate">$this-&gt;get('router')-&gt;match('&lt;tested_route&gt;')</code>.</p>