Repository navigation
Description
Complete Session application and route construction, accepted 7 November 2026
A failed build can leave its OAuth callback attached to a supplied Session. A later build with corrected configuration then sees both the abandoned callback and its replacement and rejects them. Shared rate-limit compatibility is also checked after Session settings have already been applied.
For example, with a Session configured for OAuth2 and an existing factory rate-limit group:
try {
mail.mailerBuilder(session)
.withOAuth2AccessTokenProvider(firstProvider)
.withSendingLimitsConfig(conflictingLimits)
.buildMailer();
} catch (IllegalArgumentException expected) {
// Correct the conflicting rate-limit policy and retry.
}
Mailer replacement = mail.mailerBuilder(session)
.withOAuth2AccessTokenProvider(replacementProvider)
.withSendingLimitsConfig(validLimits)
.buildMailer();The maintainer accepted validating the complete effective configuration and reserving compatible rate-limit rules before applying Session settings. A construction attempt includes its privately constructed failover Mailers: new allowance rules become established only after the complete owned route succeeds. Failure releases this attempt's provisional registrations after retiring the resources that depend on them, preserving existing registrations and compatible concurrent successes. Borrowed Mailers keep their own lifetime.
Session application and failure restoration will use the same internal change description. Every actual property set or removal, selected callback, initial proxy route, native debug change and converter installation must include its restoration requirement. Capture original direct-entry absence and object identity before mutation; preserve inherited defaults and borrowed resources. After claiming a supplied Session, reject a changed relevant captured baseline before applying configuration, without rerunning resolution or invoking opaque object methods. The attempt's own ownership marker is not a conflicting change.
Keep the delivered ownership-ordering guarantee: successful cleanup and restoration precede claim release, while unresolved cleanup retains the claim and dependent reservations. Preserve original and suppressed failures, configuration precedence and locks, lazy token acquisition and successful-shutdown behavior.
Validation remains data-only, with no temporary Session or Transport, no network access and no token-provider invocation. Reuse the existing atomic registry check with initialization outside its monitor. This adds no public API, configuration switch or work per send.
This continues unreleased #867/#755 construction work under ADR 0039, ADR 0015 and ADR 0029. It does not add another released-defect classification. Keep this issue open while this accepted follow-up remains pending.
Earlier accepted Session integration work
Supplied-Session cleanup follow-up, accepted 7 November 2026
A Mailer build that fails after changing a supplied Session currently makes that Session available before it has restored the earlier settings. Another builder can succeed in that gap, and the failed build can then overwrite the replacement's properties or debug state.
For example, these attempts run on separate application threads around the same Session. The first policy conflicts with an already established factory rate-limit group, while the second uses the accepted policy:
// Thread A
mail.mailerBuilder(session)
.withProperty("app.label", "first-attempt")
.withSendingLimitsConfig(conflictingLimits)
.buildMailer(); // Fails during setup.
// Thread B
Mailer replacement = mail.mailerBuilder(session)
.withProperty("app.label", "replacement")
.withSendingLimitsConfig(validLimits)
.buildMailer();The maintainer accepted keeping exclusive ownership until failed setup has finished cleaning up its resources and restoring the caller's original settings. Capture the restoration snapshot only after successfully claiming the Session. A competing builder must receive the existing ownership error while that work is unfinished. Once cleanup and restoration complete, a replacement may build safely. A rejected ownership claim must not restore or otherwise modify another owner's Session; unresolved cleanup must continue preventing takeover.
This completes the unreleased Session integration and rollback work from #867, building on #755/#757's exclusive ownership, under ADR 0015 and ADR 0039. Keep native Session state, original and suppressed failures, borrowed resources, ordinary successful shutdown and existing public usage intact. The separately discussed OAuth callback rollback omission is outside this accepted follow-up.
Earlier Session integration request and delivered scope
Some Session settings still reach Jakarta Mail too late, while a few helpers interpret a different protocol from the one the Session can actually select. This follow-up makes the completed SJM configuration and the supplied or constructed Session agree, building on the existing precedence and lock rules.
For example, an application can request its own executor for Session-scoped mail events:
Properties extra = new Properties();
extra.setProperty("mail.event.scope", "session");
extra.put("mail.event.executor", eventExecutor);
Mailer mailer = mail.mailerBuilder()
.withSMTPServer("smtp.example.org", 25)
.withProperties(extra)
.buildMailer();The executor ends up in the Session's properties, but SJM creates the Session before copying these additional properties. Jakarta Mail has already constructed its Session event queue, so that queue does not use the requested executor. This initialization order also exists in published 9.3.9; the example above uses the current 10.0.0 factory API.
Protocol handling has a related gap. Jakarta Mail can select an SMTPS transport through session.setProtocolForAddress("rfc822", "smtps") without a mail.transport.protocol property. Ordinary sending can then use SMTPS while an SJM helper assumes SMTP and interprets the wrong property namespace or probe endpoint.
The maintainer accepted these directions on 5 November 2026:
- Keep ordinary Session-based sending. Direct OAuth connections should let the already selected provider resolve its username. Where SJM must interpret protocol-specific settings or perform a probe for a supplied Session, require an explicit effective
mail.transport.protocoland explain missing information instead of assuming SMTP. The declaration can come from the Session or an eligible explicit Java property. Do not construct a temporary transport to discover private address mappings. - Assemble the completed resolved properties before creating an SJM-owned Session. Reuse the existing resolution and validation machinery, preserving runtime object identity, property defaults and borrowed-resource ownership.
- Keep a caller-supplied Session intact. Known constructor-only settings must be configured before the caller creates it; reject unsupported late replacements with a helpful explanation instead of accepting an ineffective change. An equivalent already-present choice is not a replacement, and this is not a blanket restriction on unknown provider properties. For the executor, distinguish the already-created Session-scoped queue from service-scoped queues created later; preserve overlays that still take effect.
- Preserve
REJECT_CONFLICTSas the default andALLOW_EXPLICIT_OVERRIDESfor deliberate Java customization. Locks and mandatory transport requirements remain binding. Ordinary factory defaults must not fill unrelated gaps in supplied Sessions.
Earlier property application must preserve debug routing, lazy authentication callbacks, TLS and socket-factory choices, exclusive Session ownership, proxy routing, pool registration and failed-construction cleanup. Debug output must not begin before its configured destination is installed. No new application API, authentication mode, Session replacement or general configuration framework is selected.
The maintainer also accepted passive configuration capture on 5 November 2026. Capture the Session's visible properties and native debug flag/output as ordinary input data, using the existing SessionDebugConfig alongside the property snapshot. Resolve Java/configured choices and locks, validate the completed result, and apply changes to the original sending Session afterward. Capture and inspection must not configure a private live Session or enable debug output merely to represent settings. Preserve a native debug flag that differs from the raw mail.debug property, borrowed stream identity and normal runtime debugging. Install the selected output before enabling debug on the real Session, and cover constructor logging from raw mail.debug=true as well as setter ordering. This completes capture behavior introduced by #867 for unreleased 10.0.0.
The maintainer also accepted standard provider-selector conflict handling on 5 November 2026. Include mail.smtp.class and mail.smtps.class in the recognized connection declarations for the active supported protocol. Reject different explicit Session/configured/Java selections under REJECT_CONFLICTS, accept matching class names, and permit deliberate Java replacement under ALLOW_EXPLICIT_OVERRIDES. Existing locks remain binding. Compare the visible class-name text without loading or constructing providers during resolution. Preserve inactive-protocol entries, implicit native defaults, opaque/default property semantics and unknown vendor extensions.
The design review is complete for S1-S4, with no remaining design decisions from this focused audit. The accepted follow-up is delivered on the 10.0.0 development branches; the completion comment below shows the resulting usage. The strict conflict model and private capture machinery being refined here belong to unreleased #867, alongside the separately identified published initialization/username gaps.
This continues ADR 0038, ADR 0039 and ADR 0015. #867 owns the earlier shared-resolution overhaul, and #785 owns the supplied-Session baseline. The delivered pooled username repair in #966 and the separately approved registration-lifetime repair in #967 retain their own scope. Receipt handling, JVM-global MIME settings and live mutation of existing connections are outside this follow-up.
Target unreleased 10.0.0. Complete the applicable API guidance, architecture records, website/examples and migration records with the agreed behavior. Keep this issue open until the accepted scope has been implemented, reviewed and delivered.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
docs(session): explain configuration timing and Session reuse (#969)
fix(session): complete Session configuration integration (#969)
bbottema commentedon Nov 6, 2026
Session-scoped mail events now use the supplied executor when Simple Java Mail creates the Session. If you supply your own Session, configure that executor before creating it;
buildMailer()rejects an ineffective late replacement. The supplied Session, Authenticator and custom mail providers stay intact.For protocol-specific connection options, inspection or probes on a supplied Session, set
mail.transport.protocolon the Session or through the builder. Ordinary sending can still use the Session's selected transport without that declaration. Direct OAuth connections leave username selection to Jakarta Mail. The activemail.smtp.classormail.smtps.classchoice follows the existing conflict policy: strict by default, deliberate Java overrides when selected, with locks binding in both modes. Configuration inspection stays quiet, and runtime debug logging uses the selected destination.Delivered for unreleased 10.0.0 in the main change and the website guidance. This follows ADR 0015, ADR 0020, ADR 0038 and ADR 0039.
chore(maintenance): record Session integration worktree custody (#969)
docs(session): explain failed construction ownership (#969)
5 remaining items
docs(session): explain whole-route construction and restoration (#969)
fix(session): validate and restore complete construction state (#969)
docs(session): retain proxy routing ownership details (#969)
fix(session): restore only attempted construction changes (#969)
fix(session): attempt native cleanup independently (#969)
docs(api): align construction and inspection guidance (#704, #961, #969…
chore(maintenance): register delegated review artifacts (#704, #961, #…
test(session): separate early refusal from late route cleanup (#969)
bbottema commentedon Nov 7, 2026
The completed configuration and shared sending-limit rules are checked before Session settings are applied. New allowance rules remain
provisional until the primary and its privately constructed failover route finish construction. A failed route does not establish its
children's new policies, and existing or concurrently successful participants retain their rules and history.
Session application and failure restoration now use one internal change description, including callbacks, property removals, proxy
routing, native debug state and the conversion context. A changed captured Session baseline is rejected before application. Later setup
failure restores original absence and borrowed identities while the attempt still owns the Session. Original failures stay primary;
unresolved cleanup retains ownership and dependent reservations. Successful shutdown keeps its existing settings contract.
Validation uses data without temporary Sessions or Transports, token-provider calls or network activity. This completes the accepted
unreleased 10.0.0 construction follow-up under #969.
Delivered changes: complete construction state, attempted-mutation restoration, independent native cleanup, Session construction guidance.
This follows ADR 0039,
ADR 0015
and ADR 0029.
chore(maintenance): preserve review cleanup custody (#488, #704, #961, …
chore(maintenance): retain final review cleanup statements (#488, #704,