X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust-java-agent%2Fjava%2Flttng-ust-agent-common%2Forg%2Flttng%2Fust%2Fagent%2FLTTngAgent.java;h=f6aae3513ac42acae5834fd833ea1fe3552b0038;hb=c0c0989ab70574e09b2f7e8b48c2da6af664a849;hp=3c9a7997d558950d40064130c18f2a21596356bd;hpb=d60dfbe48a0ceff16852f46419bcbc405502c61d;p=lttng-ust.git diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/LTTngAgent.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/LTTngAgent.java index 3c9a7997..f6aae351 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/LTTngAgent.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/LTTngAgent.java @@ -1,23 +1,13 @@ /* - * Copyright (C) 2013 - David Goulet + * SPDX-License-Identifier: LGPL-2.1-only * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (C) 2013 David Goulet */ package org.lttng.ust.agent; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.logging.Handler; import java.util.logging.Logger; @@ -48,12 +38,16 @@ public class LTTngAgent { /** * Dispose the agent. Applications should call this once they are done - * logging. + * logging. This dispose function is non-static for backwards + * compatibility purposes. */ - public static synchronized void dispose() { - if (instance != null) { - instance.disposeInstance(); - instance = null; + @SuppressWarnings("static-method") + public void dispose() { + synchronized (LTTngAgent.class) { + if (instance != null) { + instance.disposeInstance(); + instance = null; + } } return; } @@ -95,11 +89,19 @@ public class LTTngAgent { /* Attach the handler to the root JUL logger */ Logger.getLogger("").addHandler((Handler) julHandler); - } catch (ReflectiveOperationException e) { + /* - * LTTng JUL classes not found, no need to create the relevant - * objects + * If any of the following exceptions happen, it means we could not + * find or initialize LTTng JUL classes. We will not setup LTTng JUL + * tracing in this case. */ + } catch (SecurityException e) { + } catch (IllegalAccessException e) { + } catch (IllegalArgumentException e) { + } catch (ClassNotFoundException e) { + } catch (NoSuchMethodException e) { + } catch (InstantiationException e) { + } catch (InvocationTargetException e) { } } @@ -119,11 +121,25 @@ public class LTTngAgent { Class log4jAppenderClass = Class.forName("org.lttng.ust.agent.log4j.LttngLogAppender"); Constructor log4jAppendCtor = log4jAppenderClass.getConstructor(); log4jAppender = (ILttngHandler) log4jAppendCtor.newInstance(); - } catch (ReflectiveOperationException e) { + /* - * LTTng Log4j classes not found, no need to create the relevant - * objects. + * If any of the following exceptions happen, it means we could not + * find or initialize LTTng log4j classes. We will not setup LTTng + * log4j tracing in this case. */ + } catch (SecurityException e) { + return; + } catch (ClassNotFoundException e) { + return; + } catch (NoSuchMethodException e) { + return; + } catch (IllegalArgumentException e) { + return; + } catch (InstantiationException e) { + return; + } catch (IllegalAccessException e) { + return; + } catch (InvocationTargetException e) { return; } @@ -143,12 +159,22 @@ public class LTTngAgent { Object rootLogger = getRootLoggerMethod.invoke(null, (Object[]) null); addAppenderMethod.invoke(rootLogger, log4jAppender); - } catch (ReflectiveOperationException e) { /* - * We have checked for the log4j library version previously, these - * classes should exist. + * We have checked for the log4j library version previously, none of + * the following exceptions should happen. */ - throw new IllegalStateException(); + } catch (SecurityException e) { + throw new IllegalStateException(e); + } catch (ClassNotFoundException e) { + throw new IllegalStateException(e); + } catch (NoSuchMethodException e) { + throw new IllegalStateException(e); + } catch (IllegalArgumentException e) { + throw new IllegalStateException(e); + } catch (IllegalAccessException e) { + throw new IllegalStateException(e); + } catch (InvocationTargetException e) { + throw new IllegalStateException(e); } } @@ -228,12 +254,22 @@ public class LTTngAgent { Object rootLogger = getRootLoggerMethod.invoke(null, (Object[]) null); removeAppenderMethod.invoke(rootLogger, log4jAppender); - } catch (ReflectiveOperationException e) { /* - * We were able to attach the appender, we should not have problems - * here either! + * We were able to attach the appender previously, we should not + * have problems here either! */ - throw new IllegalStateException(); + } catch (SecurityException e) { + throw new IllegalStateException(e); + } catch (ClassNotFoundException e) { + throw new IllegalStateException(e); + } catch (NoSuchMethodException e) { + throw new IllegalStateException(e); + } catch (IllegalArgumentException e) { + throw new IllegalStateException(e); + } catch (IllegalAccessException e) { + throw new IllegalStateException(e); + } catch (InvocationTargetException e) { + throw new IllegalStateException(e); } /* Close the appender */