diff options
author | Shawn O. Pearce <sop@google.com> | 2009-08-06 07:17:47 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-08-06 07:17:47 -0700 |
commit | 1ec0bd2969db75af0dfcf75b35aa89b68364d5a4 (patch) | |
tree | aa0e43124ffc0f418e21cce8270134aa8828c9da | |
parent | d7c026dce6613dc6038cdae7fe98a09918116388 (diff) |
Paper bag fix OutgoingEmail initialization
Guice cannot inject the members until after the constructor has
finished running. Thus we cannot access an injected member like
the projectCache during the constructor, and must instead wait
until the init() method is invoked.
Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r-- | src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java b/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java index adf5168b9a..6d41587776 100644 --- a/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java +++ b/src/main/java/com/google/gerrit/server/mail/OutgoingEmail.java @@ -63,7 +63,7 @@ public abstract class OutgoingEmail { private static final Random RNG = new Random(); private final String messageClass; protected final Change change; - protected final String projectName; + protected String projectName; private final HashSet<Account.Id> rcptTo = new HashSet<Account.Id>(); private final Map<String, EmailHeader> headers; private final List<Address> smtpRcptTo = new ArrayList<Address>(); @@ -105,15 +105,6 @@ public abstract class OutgoingEmail { change = c; messageClass = mc; headers = new LinkedHashMap<String, EmailHeader>(); - - if (change != null) { - projectState = projectCache.get(change.getDest().getParentKey()); - projectName = - projectState != null ? projectState.getProject().getName() : null; - } else { - projectState = null; - projectName = null; - } } protected OutgoingEmail(final String mc) { @@ -208,6 +199,15 @@ public abstract class OutgoingEmail { /** Setup the message headers and envelope (TO, CC, BCC). */ protected void init() { + if (change != null && projectCache != null) { + projectState = projectCache.get(change.getDest().getParentKey()); + projectName = + projectState != null ? projectState.getProject().getName() : null; + } else { + projectState = null; + projectName = null; + } + smtpFromAddress = computeFrom(); if (changeMessage != null && changeMessage.getWrittenOn() != null) { setHeader("Date", new Date(changeMessage.getWrittenOn().getTime())); |