diff options
author | Oliver Nguyen <olivernguyen@google.com> | 2022-01-06 23:03:51 +0000 |
---|---|---|
committer | Oliver Nguyen <olivernguyen@google.com> | 2022-01-06 23:03:51 +0000 |
commit | 473f391baad0c5c25a5d82ccda0b31825b11d7be (patch) | |
tree | 6ccb427df3fbc4a579f685327e633b4b142d54a1 | |
parent | f95a4e340e7a75b587c57b02bae0e50f423f0e41 (diff) | |
download | jacoco-android-t-preview-1.tar.gz |
Always recreate the Agent instead of storing a singleton.android-t-preview-2android-t-preview-1android-t-beta-3android-s-v2-beta-3android-s-qpr3-beta-1android-t-preview-1android-s-v2-beta-3android-s-qpr3-beta-1
Fixes an issue where new classes were not included in coverage data when
added after an Agent has already been created.
Test: local testing
Bug: 203236809
Change-Id: I3928ff99a50e4a106749dc96f93d8472c74d4a70
-rw-r--r-- | org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java index 45b7ccdd..c4bf874a 100644 --- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java +++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java @@ -34,8 +34,6 @@ import org.jacoco.core.runtime.RuntimeData; */ public class Agent implements IAgent { - private static Agent singleton; - /** * Returns a global instance which is already started. If the method is * called the first time the instance is created with the given options. @@ -63,18 +61,15 @@ public class Agent implements IAgent { * @return global instance */ public static synchronized Agent getInstance(final AgentOptions options, RuntimeData data) { - if (singleton == null) { - final Agent agent = new Agent(options, IExceptionLogger.SYSTEM_ERR, data); - agent.startup(); - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - agent.shutdown(); - } - }); - singleton = agent; - } - return singleton; + final Agent agent = new Agent(options, IExceptionLogger.SYSTEM_ERR, data); + agent.startup(); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + agent.shutdown(); + } + }); + return agent; } // END android-change @@ -93,9 +88,8 @@ public class Agent implements IAgent { public static synchronized Agent getInstance() throws IllegalStateException { // BEGIN android-change // throw new IllegalStateException("JaCoCo agent not started."); - singleton = Offline.createAgent(); + return Offline.createAgent(); // END android-change - return singleton; } private final AgentOptions options; |