title: Grails - NullPointerException occured when processing request POST
body: <p>I'm building a grails application and getting an error that I really cannot understand here.</p>
  
  <p>So, I'm using ajax calls and the dropdowns send values to the controller.
  The controller is throwing an error : </p>
  
  <pre><code>NullPointerException occured when processing request POST
  </code></pre>
  
  <p>Code #1</p>
  
  <pre><code>    def com = Com.executeQuery("select p.date_hour, (sum(p.atc_visits)*100), 
  case when (sum(atc_visits_ly)) IN (0,null) THEN 0 ELSE (((sum(atc_visits))/(sum(atc_visits_ly)) - 1)*100*100) END as yoy,
   case when (sum(atc_visits_lw)) IN (0,null) THEN 0 ELSE (((sum(atc_visits))/(sum(atc_visits_lw)) - 1)*100*100) END as wow, 
  p.mv, p.browser, p.department, p.platform, p.device, p.time_period from Com p where p.department = ? and p.time_period = ? group by p.date_hour order by col_0_0_ asc ",[params.department, params.time_period])
                      render com as JSON
  </code></pre>
  
  <p>Code #2</p>
  
  <pre><code>    def com = Com.executeQuery("select p.date_hour, (sum(p.atc_visits)*100), 
  case when (sum(atc_visits_ly)) IN (0,null) THEN 0 ELSE (((sum(atc_visits))/(sum(atc_visits_ly)) - 1)*100*100) END as yoy, 
  case when (atc_visits_lw) IN (0,null) THEN 0 ELSE ((atc_visits/atc_visits_lw - 1)*100*100) END as wow, p.mv, p.browser, p.department, p.platform, p.device, p.time_period from Com p where p.department = ? and p.time_period = ? group by p.date_hour order by col_0_0_ asc ",[params.department, params.time_period])
                      render com as JSON
  </code></pre>
  
  <p>In code #2, the error goes away, whereas in code #1 the error comes, this I realized while debugging.
  The only difference is that in code #2, I have changed <code>sum(atc_visits_lw)</code> to <code>atc_visits_lw</code>. But this aggregation has to be done, it's important in this case.
  I also changed - <code>atc_visits -&gt; sum(atc_visits)</code> but this throws no error.
  **Error is only because of :  <code>sum(atc_visits_lw)</code> **</p>
  
  <p>I looked up the error and there was nothing similar to what I am facing here.
  What could I possibly be doing wrong here? How can I resolve this issue?</p>
  
  <p>I ran the same query in sql and checked in excel with the backend, but the values for <code>atc_visits_lw</code> is there everywhere </p>
  
  <p>All feedback is highly appreciated</p>