diff -r f2d57d49d36b jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java --- a/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java Fri Sep 11 19:03:00 2015 +0300 +++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java Mon Sep 21 03:25:30 2015 +0300 @@ -29,10 +29,7 @@ import java.io.*; import java.lang.management.ManagementFactory; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.nio.charset.Charset; -import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; import java.util.*; import java.util.concurrent.ExecutorService; @@ -198,10 +195,10 @@ // reflectively poking out the Charset from Console, and use it for our own private output streams. try { - Field f = Console.class.getDeclaredField("cs"); - f.setAccessible(true); Console console = System.console(); if (console != null) { + Field f = Console.class.getDeclaredField("cs"); + f.setAccessible(true); Object res = f.get(console); if (res instanceof Charset) { return (Charset) res; @@ -214,20 +211,22 @@ } try { - Method m = Console.class.getDeclaredMethod("encoding"); - m.setAccessible(true); - Object res = m.invoke(null); - if (res instanceof String) { - return Charset.forName((String) res); + PrintStream out = System.out; + if (out != null) { + Field f = PrintStream.class.getDeclaredField("charOut"); + f.setAccessible(true); + Object res = f.get(out); + if (res instanceof OutputStreamWriter) { + String encoding = ((OutputStreamWriter) res).getEncoding(); + if (encoding != null) { + return Charset.forName(encoding); + } + } } - } catch (NoSuchMethodException e) { - // fall-through - } catch (InvocationTargetException e) { + } catch (NoSuchFieldException e) { // fall-through } catch (IllegalAccessException e) { // fall-through - } catch (IllegalCharsetNameException e) { - // fall-through } catch (UnsupportedCharsetException e) { // fall-through }