Fix NPE when downloading registry resources from Carbon console#4567
Fix NPE when downloading registry resources from Carbon console#4567Tharsanan1 wants to merge 1 commit intowso2:4.11.xfrom
Conversation
When downloading registry resources from the Carbon console, a NullPointerException occurred because component-registered servlets (via UIBundleDeployer) used the old OSGi HttpService API, creating a separate session context from the Carbon console JSPs which use the HTTP Whiteboard API. This meant session attributes like SERVER_URL set during login were invisible to these servlets. - Migrate UIBundleDeployer servlet registration to OSGi HTTP Whiteboard API so component servlets share the same session context - Add null-safety fallback in CarbonUtils.getServerURL() to construct a URL from server configuration when returnUrl is null Fixes: wso2/api-manager#4848 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
| servlet.getName() != null ? servlet.getName() | ||
| : servlet.getServletClass()); | ||
| org.osgi.framework.ServiceRegistration<?> reg = |
There was a problem hiding this comment.
Log Improvement Suggestion No: 1
| servlet.getName() != null ? servlet.getName() | |
| : servlet.getServletClass()); | |
| org.osgi.framework.ServiceRegistration<?> reg = | |
| props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, | |
| servlet.getName() != null ? servlet.getName() | |
| : servlet.getServletClass()); | |
| log.info("Registering servlet: " + servlet.getServletClass() + " at path: " + servlet.getUrlPatten()); |
| if (reg != null) { | ||
| reg.unregister(); | ||
| } |
There was a problem hiding this comment.
Log Improvement Suggestion No: 2
| if (reg != null) { | |
| reg.unregister(); | |
| } | |
| if (reg != null) { | |
| reg.unregister(); | |
| } | |
| log.info("Unregistered servlet at path: " + servlet.getUrlPatten()); |
| String returnUrl = url; | ||
| if (returnUrl == null) { | ||
| String httpsPort = | ||
| CarbonUtils.getTransportPort(configCtx, mgtTransport) + ""; |
There was a problem hiding this comment.
Log Improvement Suggestion No: 3
| String returnUrl = url; | |
| if (returnUrl == null) { | |
| String httpsPort = | |
| CarbonUtils.getTransportPort(configCtx, mgtTransport) + ""; | |
| String returnUrl = url; | |
| if (returnUrl == null) { | |
| log.debug("Server URL is null, constructing default URL"); | |
| String httpsPort = |
| } | ||
| returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/"; | ||
| return returnUrl; | ||
| } |
There was a problem hiding this comment.
Log Improvement Suggestion No: 4
| } | |
| returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/"; | |
| return returnUrl; | |
| } | |
| } | |
| returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/"; | |
| log.info("Constructed server URL: " + returnUrl); | |
| return returnUrl; |
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 | ||
| #### Log Improvement Suggestion No: 2 | ||
| #### Log Improvement Suggestion No: 3 | ||
| #### Log Improvement Suggestion No: 4 |
Summary
NullPointerException: Cannot invoke "String.indexOf(String)" because "returnUrl" is nullwhen downloading registry resources from the Carbon Management ConsoleUIBundleDeployerservlet registration from the old OSGi HttpService API to the HTTP Whiteboard API, ensuring component servlets share the same session context as the Carbon console JSPsCarbonUtils.getServerURL()to construct a URL from server configuration whenreturnUrlis nullRoot Cause
Commit
8e4934287eintroduced a regression by moving core servlets to the OSGi HTTP Whiteboard pattern while leaving component-registered servlets (viaUIBundleDeployer) on the old HttpService API. In Equinox, each registration mechanism creates a separateContextControllerwith its own session attribute namespace, so session attributes set during login (likeSERVER_URL) were invisible to the ResourceServlet, causing the NPE.Test plan
Fixes: wso2/api-manager#4848
🤖 Generated with Claude Code