Fix issue causing intent without request handler to throw a NullPointerException (NPE), was not fixed in a historical PR: https://github.com/alexa/alexa-skills-kit-sdk-for-java/pull/312. isPresent is not the same as check is the Optional object itself is null. isPresent checks if the value of the Optional is null.
Add corresponding unit test for this change, which was missing and hence didn't catch the issue.
Rename variable name for better readability.
Motivation and Context
Avoid throwing an NPE in case of missing RequestHandler, instead handle the scenario more gracefully by providing an empty or null response.
Testing
Pass all existing and new unit tests.
From the new unit test no_handler_response_returns_envelope_with_empty_response:
Before the null check change:
java.lang.NullPointerException
at com.amazon.ask.CustomSkill.invoke(CustomSkill.java:149)
at com.amazon.ask.CustomSkill.invoke(CustomSkill.java:114)
at com.amazon.ask.CustomSkill.invoke(CustomSkill.java:107)
at com.amazon.ask.SkillTest.no_handler_response_returns_envelope_with_empty_response(SkillTest.java:92)...
After the null check change,can see the mock responseEnvelope contains
Description
Motivation and Context
Avoid throwing an NPE in case of missing RequestHandler, instead handle the scenario more gracefully by providing an empty or null response.
Testing
Pass all existing and new unit tests.
From the new unit test
no_handler_response_returns_envelope_with_empty_response
: Before the null check change:After the null check change,can see the mock
responseEnvelope
contains, which is consistent with the original PR Response JSON format.
Original PR and its testing process, see https://github.com/alexa/alexa-skills-kit-sdk-for-java/pull/320
Types of changes
Checklist
License