Description
Elasticsearch Version
8.1
Problem Description
AnsiConsoleLoader is using setAccessible(true)
to gain access to the internals of JANSI, in order to determine the charset that JANSI has determined is appropriate to use for its print streams. The use of setAccessible(true) is problematic, since it highlights a dependency on an internal implementation detail.
JANSI determines the charset to use by inspecting the sun.stdout.encoding
/sun.stderr.encoding
system properties, falling back to the Charset::defaultCharset
where the relevant property is not set. Since Java 17 System.console().charset()
returns the appropriate console charset, see JDK-8264209 . The System.console().charset()
method determines the charset in a similar way to that of JANSI. In fact, it would be appropriate for JANSI to use same (if it compiles to a minimum of Java 17).
Note: System.console().charset()
only inspects sun.stdout.encoding
, not sun.stderr.encoding
, but the usage in AnsiConsoleLoader is only interest in stdout (not stderr).