Skip to content

fix: guard AnsiConsole.providers() call to avoid NoSuchMethodError (fixes #1766)#1767

Merged
gnodet merged 2 commits intomasterfrom
ci-issue-1766
Apr 8, 2026
Merged

fix: guard AnsiConsole.providers() call to avoid NoSuchMethodError (fixes #1766)#1767
gnodet merged 2 commits intomasterfrom
ci-issue-1766

Conversation

@gnodet
Copy link
Copy Markdown
Member

@gnodet gnodet commented Apr 7, 2026

Summary

  • Guard the TerminalBuilder.providers() call in AnsiConsole.doInstall() with a null check on the jansi.providers system property
  • Prevents NoSuchMethodError when an older jline-terminal jar (without the providers() method) is loaded first on the classpath
  • Calling .providers(null) was a no-op anyway since the field defaults to null

Fixes #1766

Summary by CodeRabbit

  • Bug Fixes
    • Fixed initialization of the ANSI terminal provider so the app now falls back to the builder's default provider selection when no custom providers are specified via system properties.
    • Improves startup robustness and avoids unintended null/provider misconfiguration, reducing terminal-related initialization errors.

…ixes #1766)

Only call TerminalBuilder.providers() when the jansi.providers system
property is actually set. Passing null was a no-op anyway, and the
unconditional call causes NoSuchMethodError when an older jline-terminal
jar without the providers() method is loaded first on the classpath.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 01fa446e-d03a-493d-841c-7a6f2cceb929

📥 Commits

Reviewing files that changed from the base of the PR and between 113153c and 3d28670.

📒 Files selected for processing (1)
  • jansi-core/src/main/java/org/jline/jansi/AnsiConsole.java

📝 Walkthrough

Walkthrough

The AnsiConsole.doInstall() method was changed to read the jansi.providers system property into a local variable and call builder.providers(providers) only when that variable is non-null, allowing TerminalBuilder to use its default provider selection when the property is absent.

Changes

Cohort / File(s) Summary
Provider configuration
jansi-core/src/main/java/org/jline/jansi/AnsiConsole.java
Read jansi.providers into a local providers variable and invoke builder.providers(providers) only if non-null; avoids passing a null to TerminalBuilder.providers() and prevents a NoSuchMethodError regression.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

bug

Poem

🐰 I sniffed a null where builders tread,
I nudged it gently, left defaults instead.
No crash, no howl, just quiet code at night,
Providers choose, and everything's alright. 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the fix being applied: guarding the providers() call to prevent NoSuchMethodError, with direct reference to the issue being fixed.
Linked Issues check ✅ Passed The code changes directly address the objective in issue #1766 by adding a null check to prevent calling providers() method when it may not exist in older jline-terminal jars.
Out of Scope Changes check ✅ Passed The changes are limited to the specific guard condition required to fix the NoSuchMethodError, with no extraneous modifications outside the stated objective.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci-issue-1766

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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

@gnodet gnodet added this to the 4.0.12 milestone Apr 7, 2026
@gnodet gnodet added the bug label Apr 7, 2026
@gnodet gnodet merged commit 630eaaf into master Apr 8, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JANSI: NoSuchMethodError in 4.0.10 (not present in 4.0.9)

1 participant