Skip to content

Fix NPE when downloading registry resources from Carbon console#4567

Open
Tharsanan1 wants to merge 1 commit intowso2:4.11.xfrom
Tharsanan1:fix/issue-4848
Open

Fix NPE when downloading registry resources from Carbon console#4567
Tharsanan1 wants to merge 1 commit intowso2:4.11.xfrom
Tharsanan1:fix/issue-4848

Conversation

@Tharsanan1
Copy link
Copy Markdown

Summary

  • Fixes NullPointerException: Cannot invoke "String.indexOf(String)" because "returnUrl" is null when downloading registry resources from the Carbon Management Console
  • Migrates UIBundleDeployer servlet registration from the old OSGi HttpService API to the HTTP Whiteboard API, ensuring component servlets share the same session context as the Carbon console JSPs
  • Adds null-safety fallback in CarbonUtils.getServerURL() to construct a URL from server configuration when returnUrl is null

Root Cause

Commit 8e4934287e introduced a regression by moving core servlets to the OSGi HTTP Whiteboard pattern while leaving component-registered servlets (via UIBundleDeployer) on the old HttpService API. In Equinox, each registration mechanism creates a separate ContextController with its own session attribute namespace, so session attributes set during login (like SERVER_URL) were invisible to the ResourceServlet, causing the NPE.

Test plan

  • Reproduced issue on WSO2 AM 4.7.0-SNAPSHOT — confirmed HTTP 500 with NPE stack trace
  • Applied patched jars and verified download returns HTTP 200 with correct content
  • Verified no NPE or error in server logs after fix
  • Tested via Playwright browser automation (login → navigate to registry resource → click Download)

Fixes: wso2/api-manager#4848

🤖 Generated with Claude Code

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c4c3c679-b4b1-4deb-b24a-b30ca7d8582a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +313 to +315
servlet.getName() != null ? servlet.getName()
: servlet.getServletClass());
org.osgi.framework.ServiceRegistration<?> reg =
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
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());

Comment on lines +334 to 336
if (reg != null) {
reg.unregister();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
if (reg != null) {
reg.unregister();
}
if (reg != null) {
reg.unregister();
}
log.info("Unregistered servlet at path: " + servlet.getUrlPatten());

Comment on lines 841 to +844
String returnUrl = url;
if (returnUrl == null) {
String httpsPort =
CarbonUtils.getTransportPort(configCtx, mgtTransport) + "";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 3

Suggested change
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 =

Comment on lines +849 to +852
}
returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/";
return returnUrl;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 4

Suggested change
}
returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/";
return returnUrl;
}
}
returnUrl = mgtTransport + "://" + host + ":" + httpsPort + context + "/services/";
log.info("Constructed server URL: " + returnUrl);
return returnUrl;

Copy link
Copy Markdown

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant