fix: catch LinkageError during provider loading#1752
Conversation
When running on JDK 21, loading the FFM terminal provider (compiled for Java 22) throws UnsupportedClassVersionError, which is a LinkageError (an Error, not an Exception). The catch clause only caught Exception, letting the error escape. Catch LinkageError as well so provider loading failures are properly wrapped in IOException and handled gracefully by the fallback logic.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
When running on JDK 21, loading the FFM terminal provider (compiled for Java 22) throws UnsupportedClassVersionError, which is a LinkageError (an Error, not an Exception). The catch clause only caught Exception, letting the error escape. Catch LinkageError as well so provider loading failures are properly wrapped in IOException and handled gracefully by the fallback logic.
When running on JDK 21, loading the FFM terminal provider (compiled for Java 22) throws UnsupportedClassVersionError, which is a LinkageError (an Error, not an Exception). The catch clause only caught Exception, letting the error escape. Catch LinkageError as well so provider loading failures are properly wrapped in IOException and handled gracefully by the fallback logic.
When running on JDK 21, loading the FFM terminal provider (compiled for Java 22) throws UnsupportedClassVersionError, which is a LinkageError (an Error, not an Exception). The catch clause only caught Exception, letting the error escape. Catch LinkageError as well so provider loading failures are properly wrapped in IOException and handled gracefully by the fallback logic.



Fixes #1751
Problem
When using the
jlinebundle jar on JDK 21, loading the FFM terminal provider fails with:The FFM provider is compiled for Java 22+ (class file version 66.0). When
TerminalProvider.load()attempts to load it on an older JDK,ClassLoader.loadClass()throwsUnsupportedClassVersionError, which is aLinkageError(anError, not anException). The catch clause only caughtException, so the error escaped rather than being wrapped in anIOExceptionfor graceful fallback.Fix
Change
catch (Exception e)tocatch (Exception | LinkageError e)inTerminalProvider.load(). This catches class-loading errors likeUnsupportedClassVersionErrorandNoClassDefFoundError, wrapping them inIOExceptionso the fallback logic inTerminalBuilder.checkProvider()can handle them gracefully.Workaround
Users on JDK < 22 can avoid the issue by using the individual small jars instead of the
jlinebundle jar, and simply not including thejline-terminal-ffmdependency:Alternatively, use the
jdk11classifier of the bundle jar which excludes FFM classes:Summary by CodeRabbit