Fix NRE in CompSuppressable.IsHunkering when pawn.CurJob is null - #4652
Open
WhiteGiverMa wants to merge 1 commit into
Open
Fix NRE in CompSuppressable.IsHunkering when pawn.CurJob is null#4652WhiteGiverMa wants to merge 1 commit into
WhiteGiverMa wants to merge 1 commit into
Conversation
Add null-conditional access (pawn.CurJob?.def) to prevent NullReferenceException when a pawn enters the hunkering recovery path (has suppression but isSuppressed==false) with no current job. The recovery path accesses pawn.CurJob.def to check for the HunkerDown job, but CurJob can be null when the pawn is idle. This matches the existing pattern in ExternalPawnDrafter.cs:11: (pawn.CurJob == null || pawn.CurJob.def.playerInterruptible)
|
You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-28716298666.zip |
4 tasks
mszabo-wikia
approved these changes
Jul 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Add null-conditional access (
pawn.CurJob?.def) inCompSuppressable.IsHunkeringto prevent NullReferenceException when a pawn enters the hunkering recovery path with no current job.Reasoning
CompSuppressable.IsHunkeringhas a recovery path that runs when a pawn has suppression buildup butisSuppressed == false(an abnormal but possible state). In this path, it checks if the pawn currently has aHunkerDownjob by accessingpawn.CurJob.def. However,pawn.CurJobcan benullwhen the pawn is idle or between jobs, causingNullReferenceException.Stack trace:
The same codebase already uses this null-check pattern in
ExternalPawnDrafter.cs:11:Alternatives
Could use
pawn.CurJob != null && pawn.CurJob.def == ...instead of?., but the null-conditional operator is more concise and already in use elsewhere in the CE codebase.Testing
dotnet build -c Release: 0 warnings, 0 errors)