title: Why I obtain this error when I put a null value into the Spring MVC model object? java.lang.IllegalArgumentException: Attribute value must not be null
body: <p>I am pretty new with <strong>FreeMarker</strong> and I am working on a <strong>Spring MVC</strong> application that use <strong>FreeMarker</strong> as template engine.</p>
  
  <p>So I have the following problem tryng to put a null value into the model and trying to evaluate it into my <strong>FreeMarker</strong> page.</p>
  
  <p>So I have the following controller method:</p>
  
  <pre><code>@RequestMapping(value = "/sso/login", method = RequestMethod.POST)
  public String loginPost(HttpServletResponse response, @ModelAttribute DoLoginCommand command, 
          @ModelAttribute("redirect") String redirect, Model model) {
  
      ...................................................................
      ...................................................................
      ...................................................................
  
      if (statusPasswordView.getDataWarning() != null &amp;&amp; statusPasswordView.getDataWarning().before(new Date())) {
          model.addAttribute(MA_EXPIRE_DATE, dataScadenza);
  
          if(redirect.equals("")) {
              model.addAttribute("redirect", null);
          }
          else {
              model.addAttribute("redirect", redirect);
          }
  
          return "/sso/password-toexpire";
      }
      ...................................................................
      ...................................................................
      ...................................................................
  }
  </code></pre>
  
  <p>So, as you can see in the previous code snippet, the <strong>loginPost()</strong> method receive as parameter this String <strong>@ModelAttribute("redirect") String redirect</strong> (that is a <strong>@SessionAttributes</strong> of my controller class but I think that this is not important now).</p>
  
  <p>If the value of the <strong>redirect</strong> variable is an empty String (the "" string) I put in the model an attribite named <strong>redirect</strong> having <strong>null</strong> as value. 
  Else if the <strong>redirect</strong> string is not the empty string I put it value as value of the previous <strong>redirect</strong> model attribute.</p>
  
  <p>Then into my <strong>FreeMarker</strong> page (named <strong>password-toexpire.ftl</strong>) I do:</p>
  
  <pre><code>    &lt;#if redirect??&gt;
          &lt;a href="&lt;@spring.url '/profilo/home' /&gt;" class="btn btn-block btn-success submit-btn"&gt;Continua la navigazione&lt;/a&gt;
      &lt;#else&gt;
          &lt;a href="${redirect}" class="btn btn-block btn-success submit-btn"&gt;Continua la navigazione&lt;/a&gt;
      &lt;/#if&gt;
  </code></pre>
  
  <p>So, in this page, I am checking if the <strong>redirect</strong> attribute is <strong>null</strong> or not to render different element into my final HTML.</p>
  
  <p>The only problem is that when my <strong>password-toexpire.ftl</strong> page is returned I obtain thi error message into the Eclipse stack trace:</p>
  
  <pre><code>14:48:44,092 ERROR [it.mycompany.myprogjet.mypackage.base.SsumExceptionHandlerControllerAdvise] (http-localhost/127.0.0.1:8080-1) Attribute value must not be null: java.lang.IllegalArgumentException: Attribute value must not be null
  </code></pre>
  
  <p>So it seems that in Spring I can't put <strong>null</strong> attribute into the <strong>model</strong> onject but it seems strange to me. </p>
  
  <p>Why? What is the problem? What am I missing? How can I solve this issue?</p>