Fix NullReferenceException in NpmLockfileDetectorBase when dependencies object is missing#1437
Merged
Conversation
Co-authored-by: jcfiorenzano <5582507+jcfiorenzano@users.noreply.github.com>
…es object is missing - Add null check for dependencies object in ProcessIndividualPackageJTokens method - Use null conditional operator to safely handle missing dependencies/packages properties - Add comprehensive test cases for both lockfile v2 (dependencies) and v3 (packages) scenarios - Ensure backward compatibility and no regression in existing functionality Resolves issue where package-lock.json files without dependencies/packages properties would cause NullReferenceException when calling .Children<JProperty>() on null JToken. Co-authored-by: jcfiorenzano <5582507+jcfiorenzano@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] NullReferenceException in NpmLockfileDetectorBase
Fix NullReferenceException in NpmLockfileDetectorBase when dependencies object is missing
Jun 16, 2025
Co-authored-by: jcfiorenzano <5582507+jcfiorenzano@users.noreply.github.com>
…dleGracefully test as requested Co-authored-by: jcfiorenzano <5582507+jcfiorenzano@users.noreply.github.com>
…racefully test as requested Co-authored-by: jcfiorenzano <5582507+jcfiorenzano@users.noreply.github.com>
Contributor
|
@copilot try again |
Copilot stopped work on behalf of
jcfiorenzano due to an error
June 18, 2025 18:27
jcfiorenzano
approved these changes
Jun 18, 2025
Contributor
|
@copilot try again |
Co-authored-by: jcfiorenzano <5582507+jcfiorenzano@users.noreply.github.com>
jcfiorenzano
approved these changes
Jun 23, 2025
grvillic
approved these changes
Jun 23, 2025
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1437 +/- ##
======================================
Coverage 89.8% 89.8%
======================================
Files 414 414
Lines 32966 33078 +112
Branches 2045 2045
======================================
+ Hits 29616 29731 +115
+ Misses 2938 2934 -4
- Partials 412 413 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jcfiorenzano
approved these changes
Jun 23, 2025
grvillic
approved these changes
Jun 23, 2025
RushabhBhansali
approved these changes
Jun 23, 2025
OBITOONDEADO1MZ
approved these changes
Sep 25, 2025
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.
Summary
Fixed a
NullReferenceExceptionthat occurred when processingpackage-lock.jsonfiles that don't contain adependencies(v2) orpackages(v3) object.Root Cause
When a
package-lock.jsonfile is missing thedependenciesorpackagesproperty, theResolveDependencyObject()method returnsnull. The code then attempts to call.Children<JProperty>()on this null reference, causing aNullReferenceException:Solution
Added a null conditional operator with a fallback to an empty dictionary:
Testing
dependencies) and v3 (packages) scenariosExample
Before this fix, a
package-lock.jsonfile like this would crash:{ "name": "test", "version": "1.0.0", "lockfileVersion": 3 }Now it processes gracefully without throwing an exception.
Fixes #1239.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.