Handle runtime exception for older versions#157
Handle runtime exception for older versions#157NipunaMadhushan merged 4 commits intoballerina-platform:mainfrom
Conversation
📝 WalkthroughWalkthroughAdds error handling to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 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
NoSuchMethodErrorcatch 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 thatgetTagValueis 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.
Purpose
$subject
Examples
Checklist
Summary
This pull request improves the stability of the
GetTagValuecomponent 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.javaThe 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 returnsnullinstead of causing a runtime exception, ensuring the module remains functional across different runtime versions.Impact