@@ -54,7 +54,7 @@ public class PreMain {
5454 * System property that we use to prevent this agent from being attached to the same VM twice. This can happen if
5555 * the agent is registered via multiple JVM environment variables and/or the command line at the same time.
5656 */
57- private static final String LOCKING_SYSTEM_PROPERTY = "TEAMSCALE_JAVA_PROFILER_ATTACHED" ;
57+ static final String LOCKING_SYSTEM_PROPERTY = "TEAMSCALE_JAVA_PROFILER_ATTACHED" ;
5858
5959 /**
6060 * Environment variable from which to read the config ID to use. This is an ID for a profiler configuration that is
@@ -79,8 +79,6 @@ public static void premain(String options, Instrumentation instrumentation) {
7979 try {
8080 startProfiler (options , instrumentation );
8181 } catch (Throwable t ) {
82- // Top-level safety net: an exception escaping premain would be re-thrown by the JVM as
83- // IllegalAgentException and abort the profiled application. See class-level Javadoc.
8482 logStartupFailure (t );
8583 }
8684 }
@@ -125,8 +123,7 @@ private static void startProfiler(String options, Instrumentation instrumentatio
125123 agentOptions .configurationViaTeamscale .unregisterProfiler ();
126124 }
127125
128- // Previously rethrown. We now swallow the exception so a misconfigured agent cannot abort the profiled
129- // application. The error has been logged above.
126+ // Swallow to avoid aborting startup on misconfiguration (see class Javadoc).
130127 return ;
131128 } catch (AgentOptionReceiveException e ) {
132129 // When Teamscale is not available, we don't want to fail hard to still allow for testing even if no
@@ -158,16 +155,9 @@ private static void logStartupFailure(Throwable t) {
158155 "Teamscale Java Profiler failed to start up. The profiled application will continue to run "
159156 + "without coverage collection." , t );
160157 } catch (Throwable loggingFailure ) {
161- // The logger may not be initialized yet or may itself be broken. Fall back to stderr so the failure is
162- // at least visible somewhere, then give up silently.
163- try {
164- System .err .println (
165- "[Teamscale Java Profiler] Failed to start up and will not collect coverage: " + t );
166- loggingFailure .addSuppressed (t );
167- loggingFailure .printStackTrace ();
168- } catch (Throwable ignored ) {
169- // Nothing we can do; the alternative is to crash the profiled application, which we must not do.
170- }
158+ // Logger may not be initialized yet or may itself be broken. Fall back to stderr.
159+ System .err .println ("[Teamscale Java Profiler] Failed to start up and will not collect coverage: " + t );
160+ System .err .println ("[Teamscale Java Profiler] Logging itself failed: " + loggingFailure );
171161 }
172162 }
173163
0 commit comments