-
Notifications
You must be signed in to change notification settings - Fork 105
Fix NullReferenceException in NpmLockfileDetectorBase when dependencies object is missing #1437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: jcfiorenzano <[email protected]>
…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 <[email protected]>
Co-authored-by: jcfiorenzano <[email protected]>
test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorWithRootsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.Detectors.Tests/NpmLockfile3DetectorTests.cs
Outdated
Show resolved
Hide resolved
…dleGracefully test as requested Co-authored-by: jcfiorenzano <[email protected]>
…racefully test as requested Co-authored-by: jcfiorenzano <[email protected]>
src/Microsoft.ComponentDetection.Detectors/npm/NpmLockfileDetectorBase.cs
Outdated
Show resolved
Hide resolved
@copilot try again |
@copilot try again |
Co-authored-by: jcfiorenzano <[email protected]>
👋 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:
|
Summary
Fixed a
NullReferenceException
that occurred when processingpackage-lock.json
files that don't contain adependencies
(v2) orpackages
(v3) object.Root Cause
When a
package-lock.json
file is missing thedependencies
orpackages
property, 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.json
file like this would crash: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.