Skip to content

Comments

Handle runtime exception for older versions#157

Merged
NipunaMadhushan merged 4 commits intoballerina-platform:mainfrom
NipunaMadhushan:update-versions-1.7.0
Feb 24, 2026
Merged

Handle runtime exception for older versions#157
NipunaMadhushan merged 4 commits intoballerina-platform:mainfrom
NipunaMadhushan:update-versions-1.7.0

Conversation

@NipunaMadhushan
Copy link
Contributor

@NipunaMadhushan NipunaMadhushan commented Feb 24, 2026

Purpose

$subject

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests

Summary

This pull request improves the stability of the GetTagValue component by adding proper exception handling for compatibility with older versions of the runtime environment.

Changes

Modified Files:

  • native/src/main/java/io/ballerina/stdlib/observe/nativeimpl/GetTagValue.java

The change wraps the tag value retrieval logic in a try-catch block to gracefully handle cases where the underlying method may not be available in older versions. When the method is unavailable (resulting in a NoSuchMethodError), the operation returns null instead of causing a runtime exception, ensuring the module remains functional across different runtime versions.

Impact

  • Enhances backward compatibility with older runtime versions
  • Prevents runtime exceptions that would occur when expected methods are unavailable
  • Maintains existing behavior for current versions while adding a fallback mechanism

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

Adds error handling to GetTagValue.java by wrapping a method call in a try-catch block to gracefully handle NoSuchMethodError when observerContext is null. Returns null if the exception is caught, preserving existing control flow otherwise.

Changes

Cohort / File(s) Summary
Error Handling Addition
native/src/main/java/io/ballerina/stdlib/observe/nativeimpl/GetTagValue.java
Wraps ObserveUtils.getCustomTag() call in try-catch to defensively handle NoSuchMethodError when observerContext is null; returns null on exception, preserves original behavior otherwise.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • keizer619
  • chathurace
  • anuruddhal

Poem

🐰 A tag that once would throw with might,
Now catches errors left and right,
With gentle null returns so kind,
Our observer finds peace of mind! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding exception handling (try-catch for NoSuchMethodError) to support compatibility with older versions where the method may not exist.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

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

🧹 Nitpick comments (1)
native/src/main/java/io/ballerina/stdlib/observe/nativeimpl/GetTagValue.java (1)

31-37: The exception-handling approach is correct for backward compatibility, but optimize only if profiling shows this as a hot path.

The NoSuchMethodError catch is sound for supporting older runtimes. However, caching a support flag is beneficial only if this function is called very frequently in production. Without profiling evidence that getTagValue is a bottleneck, the current implementation is simpler and clearer. If performance becomes an issue, then consider adding a cached flag to short-circuit the try-catch on subsequent calls.

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

In `@native/src/main/java/io/ballerina/stdlib/observe/nativeimpl/GetTagValue.java`
around lines 31 - 37, The current try-catch in GetTagValue that catches
NoSuchMethodError for backward compatibility is acceptable and simpler; do not
add a cached support flag or short-circuit logic unless you have profiling
evidence that getTagValue (or the code path in GetTagValue.java where
ObserveUtils.getCustomTag is invoked) is a hot path. Keep the existing
catch(NoSuchMethodError) behavior in the method and avoid introducing stateful
caching or extra branching now; only implement a cached boolean guard around
ObserveUtils.getCustomTag after measuring performance and confirming it's
necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@native/src/main/java/io/ballerina/stdlib/observe/nativeimpl/GetTagValue.java`:
- Around line 31-37: The current try-catch in GetTagValue that catches
NoSuchMethodError for backward compatibility is acceptable and simpler; do not
add a cached support flag or short-circuit logic unless you have profiling
evidence that getTagValue (or the code path in GetTagValue.java where
ObserveUtils.getCustomTag is invoked) is a hot path. Keep the existing
catch(NoSuchMethodError) behavior in the method and avoid introducing stateful
caching or extra branching now; only implement a cached boolean guard around
ObserveUtils.getCustomTag after measuring performance and confirming it's
necessary.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6f1391 and a3de862.

📒 Files selected for processing (1)
  • native/src/main/java/io/ballerina/stdlib/observe/nativeimpl/GetTagValue.java

@NipunaMadhushan NipunaMadhushan merged commit 43cac35 into ballerina-platform:main Feb 24, 2026
5 checks passed
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.

2 participants