Hi, You are correct that it is initialized lazily (or not at all if getInstant is overridden and not delegated to), However constructing a new MutableInstant instance does not initialize it from a clock, the value in both cases is {epochSecond=0, nanoOfSecond=0}, similarl to the default implementation of AbstractLogEvent.getTimeMillis which always returns zero.
Apologies for the confusion! Best, -ck On Wed, Jun 13, 2018 at 10:01 AM, Gary Gregory <garydgreg...@gmail.com> wrote: > Hi, > > The semantics are quite different now, right? Before, the instant ivar was > initialized on object instantiation, 'my instant is when I was created.' > Now, it's value is a random amount of time after instantiation. How can > that be right? > > Gary > > On Wed, Jun 13, 2018 at 6:14 AM <cko...@apache.org> wrote: > >> Repository: logging-log4j2 >> Updated Branches: >> refs/heads/master 1ce2dec9b -> b54045f77 >> >> >> [LOG4J2-2351] Added AbstractLogEvent.getMutableInstant >> >> The MutableInstant may be modified by classes extending >> AbstractLogEvent. >> >> >> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo >> Commit: >> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b54045f7 >> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b54045f7 >> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b54045f7 >> >> Branch: refs/heads/master >> Commit: b54045f77663aac71a9464c5568a38536f43614a >> Parents: 1ce2dec >> Author: Carter Kozak <cko...@apache.org> >> Authored: Tue Jun 12 10:35:20 2018 -0400 >> Committer: Carter Kozak <cko...@apache.org> >> Committed: Wed Jun 13 08:14:11 2018 -0400 >> >> ---------------------------------------------------------------------- >> .../org/apache/logging/log4j/core/AbstractLogEvent.java | 9 ++++++++- >> src/changes/changes.xml | 6 ++++++ >> 2 files changed, 14 insertions(+), 1 deletion(-) >> ---------------------------------------------------------------------- >> >> >> >> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b54045f7/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java >> ---------------------------------------------------------------------- >> diff --git >> a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java >> b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java >> index b9dd2bb..f1e6aed 100644 >> --- >> a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java >> +++ >> b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java >> @@ -37,7 +37,7 @@ public abstract class AbstractLogEvent implements >> LogEvent { >> >> private static final long serialVersionUID = 1L; >> >> - private MutableInstant instant = new MutableInstant(); >> + private volatile MutableInstant instant; >> >> /** >> * Subclasses should implement this method to provide an immutable >> version. >> @@ -127,6 +127,13 @@ public abstract class AbstractLogEvent implements >> LogEvent { >> >> @Override >> public Instant getInstant() { >> + return getMutableInstant(); >> + } >> + >> + protected final MutableInstant getMutableInstant() { >> + if (instant == null) { >> + instant = new MutableInstant(); >> + } >> return instant; >> } >> >> >> >> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b54045f7/src/changes/changes.xml >> ---------------------------------------------------------------------- >> diff --git a/src/changes/changes.xml b/src/changes/changes.xml >> index d777072..e823ca5 100644 >> --- a/src/changes/changes.xml >> +++ b/src/changes/changes.xml >> @@ -180,6 +180,9 @@ >> <action issue="LOG4J2-2347" dev="ggregory" type="fix"> >> Update Apache Commons Compress from 1.16.1 to 1.17. >> </action> >> + <action issue="LOG4J2-2351" dev="ckozak" type="update"> >> + Added AbstractLogEvent.getMutableInstant to allow the >> MutableInstant instance to be modified by classes extending >> AbstractLogEvent. >> + </action> >> </release> >> <release version="2.11.1" date="2018-MM-DD" description="GA Release >> 2.11.1"> >> <action issue="LOG4J2-2268" dev="rgoers" type="fix" due-to="Tilman >> Hausherr"> >> @@ -253,6 +256,9 @@ >> <action issue="LOG4J2-2347" dev="ggregory" type="fix"> >> Update Apache Commons Compress from 1.16.1 to 1.17. >> </action> >> + <action issue="LOG4J2-2351" dev="ckozak" type="update"> >> + Added AbstractLogEvent.getMutableInstant to allow the >> MutableInstant instance to be modified by classes extending >> AbstractLogEvent. >> + </action> >> </release> >> <release version="2.11.0" date="2018-xx-xx" description="GA Release >> 2.11.0"> >> <action issue="LOG4J2-2104" dev="rgoers" type="fix"> >> >>