Skip to content

SOLR-18394: Simplify JettyConfig construction - #4786

Open
janhoy wants to merge 3 commits into
apache:mainfrom
janhoy:SOLR-18394-simplify-jettyconfig
Open

SOLR-18394: Simplify JettyConfig construction#4786
janhoy wants to merge 3 commits into
apache:mainfrom
janhoy:SOLR-18394-simplify-jettyconfig

Conversation

@janhoy

@janhoy janhoy commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-18394

Test-framework-only refactor of JettyConfig, prompted by feedback in #4738 that the
10-arg private constructor had gotten out of control.

  • Private constructor takes the Builder and reads fields directly from it
  • build() passes a deep clone, so builder reuse can't leak into a built config
  • builder(JettyConfig other) clones the config's builder snapshot — manual copy
    factory removed
  • Built config's maps are wrapped unmodifiable; public final fields unchanged, no
    call-site impact

Adding a new option now only touches the builder field/setter and the public field.

The private constructor now reads its fields directly from the Builder,
and the copy factory returns a clone of the builder snapshot kept by the
built config. This removes the 10-argument constructor and the manual
field-by-field copy logic, so adding a new Jetty option only requires a
field and setter in the Builder plus the public final field.

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach, mostly! I'm looking forward to this being done where it's most needed -- NodeConfig.

RE clone: why? Can we instead stop/prevent re-use, by adding a boolean like _used to the builder that then prevents build() from being called on it a second time? The cause of my concern is that the clone you implemented is shallow, which means additional build() has gotchas that I could easily see bugs stemming from. Or we could just document that limitation/issue.

janhoy added 2 commits August 21, 2026 19:34
…fiable

Addresses review feedback: the shallow clone left extraServlets/extraFilters
aliased between the builder, built configs, and copies from builder(JettyConfig),
so a second build() or a mutated copy could silently change an existing config.
The clone now copies both maps, and the built config exposes unmodifiable views.
…-jettyconfig

# Conflicts:
#	solr/test-framework/src/java/org/apache/solr/embedded/JettyConfig.java
@janhoy

janhoy commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

RE clone: why? Can we instead stop/prevent re-use, by adding a boolean like _used

The clone is what lets builder(JettyConfig other) snapshot the builder without the
field-by-field copy factory — a _used flag wouldn't remove that need, and would ban
the build-a-base-config-then-tweak pattern the copy factory exists for.

You're right about the shallow maps though (an aliasing that predates this PR).
Pushed a fix: clone() now deep-copies both maps, and the built config exposes them
via Collections.unmodifiableMap. Repeated build() and copied builders are now
fully independent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants