fix: crash due to config packages key with missing value #289
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.
Fixes #285.
This PR addresses an issue where the AppMap agent crashes due to a malformed configuration file, specifically when the
packages
key value is missing. The changes ensure that such scenarios are handled gracefully, avoiding null pointer exceptions.Added tests to verify:
Changes in
AppMapConfig.java
Handling Empty
packages:
Entrypackages
field isnull
after reading theappmap.yml
file.packages
isnull
, it is set to an empty array (AppMapPackage[0]
).packages:
entry or whenpackages: []
is specified explicitly, preventing null pointer exceptions.Error Handling Improvement
System.exit(1)
'load', the method now logs the error and returnsnull
, since 'System.exit(1)' is already called in 'initialize' when the load returns null.Changes in
AppMapConfigTest.java
packages
KeyloadPackagesKeyWithMissingValue
to verify that the configuration loads correctly when thepackages
key is present but has no value.loadPackagesKeyWithScalarValue
to verify that an appropriate error message is logged when thepackages
key has a scalar value instead of an array.Test for Missing Values:
Test for Scalar Values:
These tests ensure that the configuration loading behaves as expected for various malformed
packages
key scenarios, preventing crashes similar to the one reported.