This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/master by this push: new 94bb93b [KARAF-5448] Fix illegal access on Java 9 for ShellTable 94bb93b is described below commit 94bb93b22f1edfab7db99b6d5eec0e57a20424f5 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Tue Feb 13 18:23:55 2018 +0100 [KARAF-5448] Fix illegal access on Java 9 for ShellTable --- .../karaf/shell/support/table/ShellTable.java | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/shell/core/src/main/java/org/apache/karaf/shell/support/table/ShellTable.java b/shell/core/src/main/java/org/apache/karaf/shell/support/table/ShellTable.java index bbde016..8235692 100644 --- a/shell/core/src/main/java/org/apache/karaf/shell/support/table/ShellTable.java +++ b/shell/core/src/main/java/org/apache/karaf/shell/support/table/ShellTable.java @@ -17,6 +17,8 @@ package org.apache.karaf.shell.support.table; import org.apache.felix.gogo.runtime.threadio.ThreadPrintStream; +import org.apache.felix.service.command.Job; +import org.jline.terminal.Terminal; import java.io.OutputStreamWriter; import java.io.PrintStream; @@ -106,7 +108,11 @@ public class ShellTable { } public void print(PrintStream out, boolean format) { - boolean unicode = supportsUnicode(out); + print(out, null, format); + } + + public void print(PrintStream out, Charset charset, boolean format) { + boolean unicode = supportsUnicode(out, charset); String separator = unicode ? this.separator : DEFAULT_SEPARATOR_ASCII; // "normal" table rendering, with borders @@ -150,23 +156,30 @@ public class ShellTable { } } - private boolean supportsUnicode(PrintStream out) { + private boolean supportsUnicode(PrintStream out, Charset charset) { if (forceAscii) { return false; } - String encoding = getEncoding(out); - if (encoding == null) { + if (charset == null) { + charset = getEncoding(out); + } + if (charset == null) { return false; } - CharsetEncoder encoder = Charset.forName(encoding).newEncoder(); + CharsetEncoder encoder = charset.newEncoder(); return encoder.canEncode(separator) && encoder.canEncode(SEP_HORIZONTAL) && encoder.canEncode(SEP_CROSS); } - private String getEncoding(PrintStream ps) { + private Charset getEncoding(PrintStream ps) { if (ps.getClass() == ThreadPrintStream.class) { try { + return ((Terminal) Job.Utils.current().session().get(".jline.terminal")).encoding(); + } catch (Throwable t) { + // ignore + } + try { ps = (PrintStream) ps.getClass().getMethod("getCurrent").invoke(ps); } catch (Throwable t) { // ignore @@ -176,7 +189,7 @@ public class ShellTable { Field f = ps.getClass().getDeclaredField("charOut"); f.setAccessible(true); OutputStreamWriter osw = (OutputStreamWriter) f.get(ps); - return osw.getEncoding(); + return Charset.forName(osw.getEncoding()); } catch (Throwable t) { // ignore } -- To stop receiving notification emails like this one, please contact gno...@apache.org.