Skip to content

Fix: Return empty list instead of error when registry resource has no properties#4796

Open
SasinduDilshara wants to merge 1 commit intowso2:masterfrom
SasinduDilshara:fix/4767
Open

Fix: Return empty list instead of error when registry resource has no properties#4796
SasinduDilshara wants to merge 1 commit intowso2:masterfrom
SasinduDilshara:fix/4767

Conversation

@SasinduDilshara
Copy link
Copy Markdown

@SasinduDilshara SasinduDilshara commented Apr 7, 2026

Summary

  • Issue: Error message returned when there are no properties for a registry resource #4767
  • When a registry resource exists but has no associated .properties file, getResourceProperties() returns null.
  • The code was treating this null as an error, returning {"list":"Error while fetching properties"} instead of an empty list.
  • Fix: when propertiesList is null, return Utils.createJSONList(0) to produce {"count":0,"list":[]}.

Root Cause

In RegistryPropertiesResource.populateRegistryProperties(), the else branch (triggered when getResourceProperties() returns null) was constructing an error JSON object instead of an empty list. A null return from getResourceProperties() simply means no .properties metadata file exists for the resource — it is not an error condition.

Change

File: components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RegistryPropertiesResource.java

-                jsonBody = new JSONObject();
-                jsonBody.put(LIST, "Error while fetching properties");
+                jsonBody = Utils.createJSONList(0);

Test plan

  • Created a registry resource (testfolder/sampletext.txt) with no .properties file.
  • Called GET /management/registry-resources/properties?path=registry/governance/mi-resources/testfolder/sampletext.txt.
  • Confirmed response is {"count":0,"list":[]} (empty list, not error string).
  • Confirmed non-existent resource path still returns proper error: {"Error":"Can not find the registry: ..."}.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Updated registry properties endpoint to return an empty list instead of an error message when property retrieval fails, providing more consistent API behavior across integration scenarios.

… properties

When a registry resource exists but has no associated .properties file,
getResourceProperties() returns null. The code was incorrectly treating
this null as an error and returning {"list":"Error while fetching properties"}.

Fix: When propertiesList is null, return Utils.createJSONList(0) to produce
{"count":0,"list":[]} — an empty list — instead of an error string.

Fixes wso2#4767

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SasinduDilshara
Copy link
Copy Markdown
Author

SasinduDilshara commented Apr 7, 2026

Issue Analysis

Issue Analysis — [Issue #4767]: Error message returned when there are no properties for a registry resource

Classification

  • Type: Bug (the API returns an error response instead of an empty list for a valid, existing resource)
  • Severity Assessment: Medium
  • Affected Component(s): org.wso2.micro.integrator.management.apisRegistryPropertiesResource
  • Affected Feature(s): Management REST API — Registry Resource Properties (GET /management/registry-resources/properties)

Reproducibility

  • Reproducible: Yes
  • Reproduction method: curl against a running MI server
  • Environment: MI 4.6.0-SNAPSHOT, macOS Darwin 24.0.0, Java (default), no special config
  • Steps Executed:
    1. Extract wso2mi-4.6.0-SNAPSHOT.zip.
    2. Create a registry resource with no .properties file:
      mkdir -p wso2mi-4.6.0-SNAPSHOT/registry/governance/mi-resources/testfolder
      echo "sample text" > wso2mi-4.6.0-SNAPSHOT/registry/governance/mi-resources/testfolder/sampletext.txt
      
    3. Start the server.
    4. Obtain a Bearer token:
      curl -sk -X GET "https://localhost:9164/management/login" -H "Authorization: Basic YWRtaW46YWRtaW4="
      
    5. Call the properties endpoint:
      curl -sk -X GET "https://localhost:9164/management/registry-resources/properties?path=registry/governance/mi-resources/testfolder/sampletext.txt" \
        -H "accept: application/json" -H "Authorization: Bearer <token>"
      
  • Expected Behavior: HTTP 200 with {"list":[]} (empty list of properties).
  • Actual Behavior: HTTP 200 with {"list":"Error while fetching properties"} — a string error is placed in the list field instead of an empty JSON array.
  • Evidence:
    HTTP/1.1 200 OK
    Content-Type: application/json; charset=UTF-8
    
    {"list":"Error while fetching properties"}
    

Root Cause Analysis

In RegistryPropertiesResource.java (populateRegistryProperties, lines 192–203):

Properties propertiesList = microIntegratorRegistry.getResourceProperties(registryPath);
if (propertiesList != null) {
    // build list JSON...
} else {
    jsonBody = new JSONObject();
    jsonBody.put(LIST, "Error while fetching properties");  // BUG: treats null as error
}

MicroIntegratorRegistry.getResourceProperties() returns null when lookupProperties() returns null — i.e., when no .properties metadata file exists for the resource. This is expected when a resource has never had properties assigned to it. The code incorrectly treats this null as an error rather than as "zero properties defined."

Fix: In populateRegistryProperties, when propertiesList is null, return Utils.createJSONList(0) (an empty list response) instead of the error message string.

File to fix: components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RegistryPropertiesResource.java, lines 201–204.

Test Coverage Assessment

  • Existing tests covering this path:
    • integration/management-api-tests/src/test/java/org/wso2/micro/integrator/api/RegistryResourcesTestCase.java — integration tests for registry properties GET/POST/DELETE. Covers resources that already have properties (test-empty.txt which has a .properties file, even if with no content), error paths (non-existing registry, illegal path).
    • components/mediation/registry/org.wso2.micro.integrator.registry/src/test/java/org/wso2/micro/integrator/registry/TestMicroIntegratorRegistry.java — unit tests for getResourceProperties.
  • Coverage gaps identified:
    • No test covers GET /registry-resources/properties for a resource that exists but has no properties file (i.e., getResourceProperties returns null). This is exactly the scenario in this issue.
  • Proposed test plan:
    • Integration test (in RegistryResourcesTestCase.java): Add a test resource that has no .properties file. Call GET /registry-resources/properties?path=... and assert the response is {"list":[]} (empty JSON array, not an error string).
    • Unit test (in RegistryPropertiesResource or a new unit test class): Mock MicroIntegratorRegistry.getResourceProperties() to return null, invoke populateRegistryProperties, and assert the returned JSON body has list as an empty JSON array.
    • Negative/edge cases: Ensure the fix does not affect the "registry does not exist" error path (handled before getResourceProperties is called via isRegistryExist check).

Verified steps of the issue

Fix Verification Report

Issue: #4767
Verdict: FIXED
Verification method: curl against running patched MI server

Reproduction Steps Executed

  1. Built the patched module (org.wso2.micro.integrator.management.apis) from source with the fix applied.
  2. Extracted a fresh product pack (wso2mi-4.6.0-SNAPSHOT.zip) and applied the patched JAR as patches/patch9999/org.wso2.micro.integrator.management.apis_4.6.0.SNAPSHOT.jar.
  3. Created a test registry resource at registry/governance/mi-resources/testfolder/sampletext.txt with no .properties file (no properties defined).
  4. Started the server — patch was detected, applied, and server restarted automatically. Server started on port 9164.
  5. Obtained a management API access token via GET /management/login.
  6. Called GET /management/registry-resources/properties?path=registry/governance/mi-resources/testfolder/sampletext.txt with the access token.

Result

Before fix (expected): {"list":"Error while fetching properties"}

After fix (observed): {"count":0,"list":[]} — an empty list is returned correctly.

The non-existent resource path still returns a proper error:

{"Error":"Can not find the registry: registry/governance/mi-resources/nonexistent/file.txt"}

Evidence

Case 1: Registry resource with no properties (the reported issue)

GET /management/registry-resources/properties?path=registry/governance/mi-resources/testfolder/sampletext.txt

Response: {"count":0,"list":[]}

Case 2: Non-existent resource path (error case unchanged)

GET /management/registry-resources/properties?path=registry/governance/mi-resources/nonexistent/file.txt

Response: {"Error":"Can not find the registry: registry/governance/mi-resources/nonexistent/file.txt"}

Patch application log

[2026-04-07 21:57:36,175]  INFO {PatchInstaller perform} - Patch changes detected
[2026-04-07 21:57:37,097]  INFO {PatchUtils applyServicepacksAndPatches} - Backed up plugins to patch0000
[2026-04-07 21:57:37,105]  INFO {PatchUtils checkMD5Checksum} - Patch verification started
[2026-04-07 21:57:37,109]  INFO {PatchUtils checkMD5Checksum} - Patch verification successfully completed
[2026-04-07 21:57:43,175]  INFO {StartupFinalizer} - WSO2 Micro Integrator started in 7.45 seconds

Comment on lines 201 to 203
} else {
jsonBody = new JSONObject();
jsonBody.put(LIST, "Error while fetching properties");
jsonBody = Utils.createJSONList(0);
}
Copy link
Copy Markdown
Contributor

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
} else {
jsonBody = new JSONObject();
jsonBody.put(LIST, "Error while fetching properties");
jsonBody = Utils.createJSONList(0);
}
} else {
log.warn("Failed to fetch registry properties for path: " + path);
jsonBody = Utils.createJSONList(0);

Copy link
Copy Markdown
Contributor

@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

@SasinduDilshara
Copy link
Copy Markdown
Author

Fix Plan

Click to expand

$(cat /Users/admin/Desktop/SE-AI_Agent/MI_TEST_PATCH_GENERAL_SKILLS/test-1/product-micro-integrator/.ai/fix-plan-4767.md)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

Walkthrough

The RegistryPropertiesResource.java file is modified to change error handling behavior. When fetching registry resource properties returns null, the response now returns an empty JSON list instead of an error message payload.

Changes

Cohort / File(s) Summary
Registry Properties Error Handling
components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RegistryPropertiesResource.java
Modified null handling in populateRegistryProperties to return empty JSON list via Utils.createJSONList(0) instead of error message when resource properties cannot be retrieved.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A tidy change, so clean and neat,
Empty lists make the response sweet,
No error noise, just silence kind,
A peaceful null we've left behind! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description covers the issue, root cause, the specific change made, and test verification. However, it lacks most required template sections like Goals, Approach, User Stories, Release Notes, Documentation, and other formal sections. Provide the missing formal sections from the template such as Goals, Approach, User Stories, Release Notes, Documentation, Training, Certification, Marketing, and test coverage details to ensure comprehensive documentation.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: returning an empty list instead of an error when a registry resource has no properties file.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

@SasinduDilshara
Copy link
Copy Markdown
Author

Verification Report

Click to expand

$(cat /Users/admin/Desktop/SE-AI_Agent/MI_TEST_PATCH_GENERAL_SKILLS/test-1/product-micro-integrator/.ai/verify-4767.md)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RegistryPropertiesResource.java (1)

232-235: ⚠️ Potential issue | 🟡 Minor

Inconsistent handling of null properties between methods.

populateRegistryProperties (line 202) now returns an empty list when getResourceProperties() returns null, but populateRegistryProperty still returns an INTERNAL_SERVER_ERROR. This creates inconsistent API behavior:

  • GET /registry-resources/properties?path=...{"count":0,"list":[]} (200 OK)
  • GET /registry-resources/properties?path=...&name=foo{"Error":"Error while fetching properties"} (500)

Consider aligning the behavior. For a resource with no properties file, returning BAD_REQUEST with a message like "Property named X does not exist" or "No properties file exists for this resource" would be more consistent and informative than a 500 error.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RegistryPropertiesResource.java`
around lines 232 - 235, populateRegistryProperty currently returns an
INTERNAL_SERVER_ERROR when getResourceProperties() is null, while
populateRegistryProperties returns an empty list; make them consistent by
checking for null in populateRegistryProperty (the method in
RegistryPropertiesResource that builds jsonBody) and return a BAD_REQUEST JSON
error message (e.g., "Property named X does not exist" or "No properties file
exists for this resource") instead of INTERNAL_SERVER_ERROR; update the jsonBody
assignment in populateRegistryProperty to set BAD_REQUEST with a clear message
when properties == null so both populateRegistryProperties and
populateRegistryProperty handle missing properties uniformly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RegistryPropertiesResource.java`:
- Around line 232-235: populateRegistryProperty currently returns an
INTERNAL_SERVER_ERROR when getResourceProperties() is null, while
populateRegistryProperties returns an empty list; make them consistent by
checking for null in populateRegistryProperty (the method in
RegistryPropertiesResource that builds jsonBody) and return a BAD_REQUEST JSON
error message (e.g., "Property named X does not exist" or "No properties file
exists for this resource") instead of INTERNAL_SERVER_ERROR; update the jsonBody
assignment in populateRegistryProperty to set BAD_REQUEST with a clear message
when properties == null so both populateRegistryProperties and
populateRegistryProperty handle missing properties uniformly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3267a783-9d53-4efb-bb02-dc1eedcf6320

📥 Commits

Reviewing files that changed from the base of the PR and between 18a92b7 and e62b284.

📒 Files selected for processing (1)
  • components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RegistryPropertiesResource.java

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