Skip to content

FIX: Added checks to prevent NullReferenceException#2364

Open
SamCYu wants to merge 1 commit intodevelopfrom
statemonitor/nre
Open

FIX: Added checks to prevent NullReferenceException#2364
SamCYu wants to merge 1 commit intodevelopfrom
statemonitor/nre

Conversation

@SamCYu
Copy link
Member

@SamCYu SamCYu commented Mar 2, 2026

Description

This PR fixes a NullPointerReferenceException in certain cases when thelistener.monitor or listener.control is null.

Jira Ticket

Testing status & QA

Local testing

Overall Product Risks

Please rate the potential complexity and halo effect from low to high for the reviewers. Note down potential risks to specific Editor branches if any.

  • Complexity: 0
  • Halo Effect: 0

Comments to reviewers

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

@cla-assistant-unity
Copy link

cla-assistant-unity bot commented Mar 2, 2026

CLA assistant check
All committers have signed the CLA.

@SamCYu SamCYu changed the title Added checks to fix nullpointerexception FIX: Added checks to fix nullpointerexception Mar 2, 2026
@SamCYu SamCYu changed the title FIX: Added checks to fix nullpointerexception FIX: Added checks to prevent NullReferenceException Mar 2, 2026
@SamCYu SamCYu marked this pull request as ready for review March 3, 2026 10:05
@u-pr
Copy link
Contributor

u-pr bot commented Mar 3, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪

Very small change localized to exception logging with minimal behavioral impact and low review surface area.

🏅 Score: 88

The fix meaningfully prevents a secondary NullReferenceException during error reporting, but lacks test coverage to lock in the regression.

🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Robust Logging

The new log message uses null-propagation, but it still calls listener.control?.ToString() which could theoretically throw or be unexpectedly expensive; consider logging a safer identifier (e.g., name/path) or guarding against ToString() failures to ensure the catch block never throws.

$"Exception '{exception.GetType().Name}' thrown from state change monitor '{(listener.monitor?.GetType().Name ?? "null")}' on '{(listener.control?.ToString() ?? "null")}'");
  • Update review

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@u-pr
Copy link
Contributor

u-pr bot commented Mar 3, 2026

PR Code Suggestions ✨

No code suggestions found for the PR.

@codecov-github-com
Copy link

codecov-github-com bot commented Mar 3, 2026

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff             @@
##           develop    #2364      +/-   ##
===========================================
- Coverage    77.90%   77.89%   -0.02%     
===========================================
  Files          476      476              
  Lines        97613    97616       +3     
===========================================
- Hits         76048    76034      -14     
- Misses       21565    21582      +17     
Flag Coverage Δ
inputsystem_MacOS_2022.3 5.52% <ø> (-0.01%) ⬇️
inputsystem_MacOS_2022.3_project 75.39% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.0 5.30% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.0_project 77.29% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.3 5.30% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.3_project 77.28% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.4 5.31% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.4_project 77.30% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.5 5.31% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.5_project 77.29% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.6 5.31% <ø> (-0.01%) ⬇️
inputsystem_MacOS_6000.6_project 77.29% <ø> (-0.02%) ⬇️
inputsystem_Ubuntu_2022.3 5.53% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_2022.3_project 75.19% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.0 5.31% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.0_project 77.09% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.3 5.31% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.3_project 77.09% <ø> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.4 5.32% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.4_project 77.10% <ø> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.5 5.32% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.5_project 77.09% <ø> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.6 5.32% <ø> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.6_project 77.09% <ø> (-0.02%) ⬇️
inputsystem_Windows_2022.3 5.52% <ø> (-0.01%) ⬇️
inputsystem_Windows_2022.3_project 75.52% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.0 5.30% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.0_project 77.42% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.3 5.30% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.3_project 77.41% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.4 5.31% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.4_project 77.42% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.5 5.31% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.5_project 77.42% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.6 5.31% <ø> (-0.01%) ⬇️
inputsystem_Windows_6000.6_project 77.42% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...putsystem/InputSystem/InputManagerStateMonitors.cs 95.56% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants