New Date() == null?

Hi All,

How is it possible that new Date() could be null? I have this line of code:

state.lastJsonCall = (new Date()).format(“yyyy-MM-dd’T’HH:mm:ss.SSS’Z’”)

But it’s frequently throwing an error:

error java.lang.NullPointerException: Cannot invoke method format() on null object

How is that possible? Any recommendations on working around it?

That shouldn’t happen, and I can’t reproduce it. Is it consistently reproducible? SmartApp or Device Handler?

It started at 11pm on Wednesday and is consistent for one of my Smart Apps.

It only happens for a method that maps to a inbound HTTP request, when it happens the request fails with HTTP 500.

It’a really strange because I haven’t changed the Smart App or the RaspberryPI app that is sending the HTTP request…

Sorry to necro an old thread but this is exactly what’s happening to me and I couldn’t find any answers.

I am using a custom device handler I found in the community. In the logs I see java.lang.NullPointerException @line 114 (zwaveEvent). I think I’ve narrowed it down to the new Date() returning null. It seems to be happening every time.

I can also replace it with and get java.lang.NullPointerException: Cannot invoke method now() on null object.

I can comment it out and the handler otherwise works like a charm.

I would love some help figuring out how this could possibly happen, or if there is an alternative I could just use.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.