Fix NPE in CipherTool when deployment.toml has configurations after s…#97
Fix NPE in CipherTool when deployment.toml has configurations after s…#97PasinduSuraweera wants to merge 1 commit intowso2:masterfrom
Conversation
There was a problem hiding this comment.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
| Comment | Accepted (Y/N) | Reason |
|---|---|---|
| #### Log Improvement Suggestion No: 1 |
WalkthroughThe change introduces a null-check in CipherTool.java before replacing deployment configuration lines with encrypted values. When a value from the encryptedKeyMap is null, the line replacement is skipped, preventing NullPointerException errors during the cipher tool's configuration update flow. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
components/ciphertool/src/main/java/org/wso2/ciphertool/CipherTool.java (1)
387-390: Null check prevents NPE; consider adding logging as previously suggested.The null check correctly prevents the NullPointerException when a key is not found in the encryptedKeyMap. However, the fix silently skips the replacement, which could hide configuration issues where expected keys are missing from the encryption map.
As the previous bot review suggested, consider adding logging to improve observability:
String value = encryptedKeyMap.get(key.trim()); // Fix: Check if value exists before replacing if (value != null) { + log.debug("Updating deployment configuration for key: " + key); line = key.concat("= \"").concat(value).concat("\""); + } else { + log.warn("No encrypted value found for key: " + key + ". Skipping update."); }Based on past review comments.
|
Hi @arunans23, following up on this fix for Issue wso2/api-manager#4561. It fixes a NullPointerException in the CipherTool (Issue wso2/api-manager#4561) that occurs when custom sections are added to deployment.toml. I have verified the fix locally with APIM 4.6.0. I’d appreciate a review whenever you have a moment. |
Purpose
Resolves wso2/api-manager#4561
This PR fixes a critical
NullPointerExceptionin the CipherTool that occurs when thedeployment.tomlfile contains configuration sections defined after the[secrets]section.Goals
ciphertoolwhen users add custom configurations or new sections at the end ofdeployment.toml.encryptedKeyMapinstead of throwing a runtime exception.Approach
The crash was caused by the tool attempting to encrypt keys found in sections following the
[secrets]block. When the tool encountered a key from a subsequent section (e.g.,[test_section]), it tried to look up its value in theencryptedKeyMap. Since the key was not a secret, the map returnednull. The code then attempted to concatenate thisnullvalue (.concat(value)), resulting in aNullPointerException.I implemented a null check for the retrieved
value. If the value is null, the code now skips the line modification, preserving the configuration as-is without crashing.User stories
As a System Administrator or DevOps Engineer, I want to be able to add custom configuration sections to the bottom of my
deployment.tomlfile without causing theciphertoolscript to crash, so that I can safely manage my environment configurations and secrets.Release note
Fixed a
NullPointerExceptionin the CipherTool utility that occurred whendeployment.tomlcontained configuration sections placed after the[secrets]block.Documentation
N/A - This is a bug fix for an internal utility and does not require documentation updates.
Training
N/A
Certification
N/A
Marketing
N/A
Automation tests
Security checks
Samples
N/A
Related PRs
N/A
Migrations (if applicable)
N/A
Test environment
Learning
Identified that the tokenizer logic in
CipherTool.javadid not account for scenarios where keys might be parsed from non-secret sections if the section parsing logic allows fall-through, leading to null values in the encryption map.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.