1

Getting IllegalArguementException in Server but not in my local machine.

Date date  = Date.valueOf("2013-13-31");
kosa
  • 65,990
  • 13
  • 130
  • 167
Vamshi
  • 510
  • 2
  • 10
  • 26
  • 3
    There aren't thirteen months in a year. I suspect that your server is parsing date strings more strictly (it will reject that) whereas your local machine is allowing it as 31st Jan 2014. I know there's a property of Calendar instances that controls this, not sure if there's a default JVM setting too. – Anthony Grist Oct 31 '13 at 15:01
  • The result in my local machine is 2014-01-01 – Vamshi Oct 31 '13 at 15:04
  • @VamshiKrishna Really? That doesn't make much sense. – Anthony Grist Oct 31 '13 at 15:08
  • 2
    @AnthonyGrist Well it makes sense, see http://stackoverflow.com/questions/7606387/what-is-the-use-of-lenient Do you have different locales configured on your local machine and your server? – u6f6o Oct 31 '13 at 15:12
  • @UlfGitschthaler I know what lenient does (notice my first comment saying that it's almost certainly caused by a difference in leniency between the two environments), I still don't see how `2013-13-31` becomes `2014-01-01` - that looks like 30 days are being lost. Plus I get `2014-01-31` as I'd expect when I run that code. – Anthony Grist Oct 31 '13 at 15:18
  • 1
    I debugged this code on my local machine and I also get an IllegalArgumentException. In java.sql.Date#valueOf there is a check `if ((month >= 1 && month <= MAX_MONTH) && (day >= 1 && day <= MAX_DAY))` Since 13 > MAX_MONTH this check always evaluates to false. Do you use the same JDK versions on your local machine and your server? – u6f6o Nov 01 '13 at 09:58
  • @AnthonyGrist Ok sorry, I misinterpreted your initial answer. – u6f6o Nov 01 '13 at 09:59

0 Answers0