title: Java null java.lang.IllegalArgumentException parsing issue using If-Statement
body: <p>I have an issue with parsing both a date using java.sql.Date.valueOf (java.lang.IllegalArgumentException) and an integer using Integer.parseInt (java.lang.NumberFormatException).</p>
  
  <p>I have a form that requests a barcode number, a date-from and date-to using HTML5 and Chrome, this connects to a PostgreSQL database in the background returning a table with the items. This works perfectly when all 3 are specified.</p>
  
  <p>However, I want the user to be able to search using just the barcode, so all relevant entries, regardless of what date, are returned. Similarly, using just dates to get any entry between the specified dates.</p>
  
  <p>This is my Form:</p>
  
  <pre><code>&lt;th&gt;&lt;input type="text" name="barcode" size="20"&gt;&lt;/th&gt;
          &lt;th&gt;&lt;input type="date" name="dateFrom"&gt;&lt;/th&gt;
          &lt;th&gt;&lt;input type="date" name="dateTo"&gt;&lt;/th&gt;
          &lt;th&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/th&gt;
  </code></pre>
  
  <p>Now, I understand that the parsing functions do not like null values, and to this end I have used an If-statement to check for a null value and assign a value:</p>
  
  <pre><code>Date dateFrom;
  String stringDateFrom = request.getParameter("dateFrom");
  
  if (stringDateFrom == null){
          dateFrom = Date.valueOf(LocalDate.MIN);
      } else {
          dateFrom = Date.valueOf(stringDateFrom);
      }
  </code></pre>
  
  <p>My understanding is that the If-statement checks if the statement is True, if it is, it processes the code and exits, if the statement is False it skips to the "else" section and processes its code. So, if I don't input a value for the dateFrom field in the form the String 'stringDateFrom' would be null, and so the first portion of the If-statement should run and skip the second portion.</p>
  
  <p>This does not happen, even with a null value for 'stringDateFrom' I get the error 'java.lang.IllegalArgumentException' at the line below of the If-statement, which I thought should have been skipped?</p>
  
  <pre><code>dateFrom = Date.valueOf(stringDateFrom);
  </code></pre>
  
  <p>I get the error 'java.lang.NumberFormatException' with exactly the same setup but parsing an integer, the line of code being;</p>
  
  <pre><code>barcode = Integer.parseInt(stringBarcode);
  </code></pre>
  
  <p>Is this something with my parsing code or my if-statement code?</p>
  
  <p>Sorry for the long post, I'm a student and this is part of my project, I'm not a java programmer by trade ;-)</p>
  
  <p>Thanks for any and all help.</p>
  
  <p><strong>Edit: Solved</strong></p>
  
  <p>Thanks to unholysampler for pointing me in the right direction. The problem was that the setParameter was returning an empty String as apposed to null and so the condition was never met.</p>
  
  <p>I changed the code to check for an empty String, or not an empty String, and it works, i.e.</p>
  
  <p><code>if (stringDateFrom == null)</code> to <code>if (stringDateFrom.equals(""))</code></p>
  
  <p>and</p>
  
  <p><code>if (stringBarcode != null)</code> to <code>if (!stringBarcode.equals(""))</code></p>
  
  <p>Thanks all for your help.</p>
  
  <p><strong>Edit: Stacktrace</strong></p>
  
  <p>The line 'at java.sql.Date.valueOf(Date.java:143)' refers to the code;</p>
  
  <pre><code>if (d == null) {
              throw new java.lang.IllegalArgumentException();
          }
  </code></pre>
  
  <p>Within java.sql.Data</p>
  
  <pre><code>Warning:   StandardWrapperValve[logListServlet]: Servlet.service() for servlet logListServlet threw exception java.lang.IllegalArgumentException
  
  at java.sql.Date.valueOf(Date.java:143)
  at org.mypackage.HOIS.logListServlet.doPost(logListServlet.java:57)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
  at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
  at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
  at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
  at java.lang.Thread.run(Thread.java:744)
  </code></pre>