[hueemulation] Fix NullPointerExceptions#19589
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes NullPointerExceptions that occur when processing HTTP requests with empty request bodies in the Hue emulation service. The primary fix adds null checks after deserializing JSON request bodies using Gson, which returns null for empty bodies. Additionally, the PR includes code cleanup by removing unused @SuppressWarnings annotations, improving test assertions consistency, and applying modern Java patterns.
Key changes:
- Added null checks after
gson.fromJson()calls in REST endpoints to prevent NPEs when request bodies are empty - Standardized test assertions from
assertEquals()toassertThat()with Hamcrest matchers - Modernized code using pattern matching for instanceof and Stream API improvements (
toList()instead ofCollectors.toList())
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| ConfigurationAccess.java | Added null check for empty request body in putFullConfigApi() to fix the NPE described in the PR |
| UserManagement.java | Added null check for empty body in createNewUser() and removed unnecessary @SuppressWarnings |
| Sensors.java | Added null check in renameLightApi() and removed @SuppressWarnings annotations |
| Schedules.java | Added null check and improved validation logic in postNewSchedule() |
| Scenes.java | Added null checks, improved lights list handling with defensive null check, modernized stream collection |
| Rules.java | Added null check in modifyRuleApi() and simplified description handling in postNewRule() |
| LightsAndGroups.java | Added null checks, improved updateGroup0() with defensive null check, removed unused variable |
| UpnpServer.java | Improved resource management with proper try-with-resources, added null check in handleEvent(), fixed inline link documentation |
| HueEmulationConfigWithRuntime.java | Removed redundant implements Runnable, added unnecessary Objects.requireNonNull() |
| HttpActionHandler.java | Added unnecessary Objects.requireNonNull() around Integer.getInteger() |
| TimerTriggerHandler.java | Modernized with pattern matching for instanceof |
| RemoveRuleActionHandler.java | Improved code clarity with local variable extraction |
| HueRuleConditionHandler.java | Removed redundant null check and unused import |
| AbsoluteDateTimeTriggerHandler.java | Added proper nullable annotations, improved field organization, used pattern matching |
| StateUtils.java | Modernized with pattern matching for instanceof checks |
| RuleUtils.java | Removed unnecessary @SuppressWarnings annotations |
| HueEmulationService.java | Fixed inline link documentation for EventAdmin |
| DeviceType.java | Added @NonNullByDefault annotation |
| ConfigStore.java | Improved null handling with local variable extraction |
| Test files (multiple) | Standardized assertions to use assertThat() instead of assertEquals(), added assertNotNull() checks for null safety |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Outdated
Show resolved
Hide resolved
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Outdated
Show resolved
Hide resolved
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Show resolved
Hide resolved
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Show resolved
Hide resolved
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Show resolved
Hide resolved
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/org/openhab/io/hueemulation/internal/upnp/HueEmulationConfigWithRuntime.java
Show resolved
Hide resolved
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Show resolved
Hide resolved
...nhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/SceneTests.java
Outdated
Show resolved
Hide resolved
...ulation/src/main/java/org/openhab/io/hueemulation/internal/automation/HttpActionHandler.java
Show resolved
Hide resolved
lsiepel
left a comment
There was a problem hiding this comment.
Thanks, no new comments besides some of the copilot suggestions. Otherwise LGTM
Fix warnings Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
584473d to
a434ee7
Compare
I have removed unneeded null checks in |
lsiepel
left a comment
There was a problem hiding this comment.
Thanks, LGTM
(awaiting 5.0.3 release)
E.g. on
PUTrequest forhttp://openhab:8080/api/userid/configwith empty body:Also fix warnings.