diff options
author | Kun Zhang <zhangkun83@users.noreply.github.com> | 2017-01-10 11:10:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 11:10:15 -0800 |
commit | a3a5420922ecf1ddc2c4ab77c273be3df47b74f5 (patch) | |
tree | ec67595ba259b3ab73289333c122f86890c417cb /context | |
parent | de10b94128ab67393dabbb48535a144e25b2d877 (diff) | |
download | grpc-grpc-java-a3a5420922ecf1ddc2c4ab77c273be3df47b74f5.tar.gz |
context: don't log to logger in static initialization. (#2581)
Diffstat (limited to 'context')
-rw-r--r-- | context/src/main/java/io/grpc/Context.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/context/src/main/java/io/grpc/Context.java b/context/src/main/java/io/grpc/Context.java index 1a7ac24cc..cae0e1fa0 100644 --- a/context/src/main/java/io/grpc/Context.java +++ b/context/src/main/java/io/grpc/Context.java @@ -131,7 +131,14 @@ public class Context { Class<?> clazz = Class.forName("io.grpc.override.ContextStorageOverride"); newStorage = (Storage) clazz.getConstructor().newInstance(); } catch (ClassNotFoundException e) { - log.log(Level.FINE, "Storage override doesn't exist. Using default.", e); + if (log.isLoggable(Level.FINE)) { + // Avoid writing to logger because custom log handlers may try to use Context, which is + // problemantic (e.g., NullPointerException) because the Context class has not done loading + // at this point. The caveat is that in environments stderr may be disabled, thus this + // message would go nowhere. + System.err.println("io.grpc.Context: Storage override doesn't exist. Using default."); + e.printStackTrace(); + } newStorage = new ThreadLocalContextStorage(); } catch (Exception e) { error = e; |