fix: add fail-fast validation to SolrConfigurationProperties - #104
Open
adityamparikh wants to merge 2 commits into
Open
fix: add fail-fast validation to SolrConfigurationProperties#104adityamparikh wants to merge 2 commits into
adityamparikh wants to merge 2 commits into
Conversation
adityamparikh
force-pushed
the
fix/solr-config-properties-validation
branch
from
May 2, 2026 17:04
a3f6b1a to
b2c8af9
Compare
adityamparikh
force-pushed
the
fix/solr-config-properties-validation
branch
from
June 15, 2026 16:42
b2c8af9 to
184bdd3
Compare
adityamparikh
force-pushed
the
fix/solr-config-properties-validation
branch
from
August 18, 2026 23:33
b4159ef to
b1c961d
Compare
Add @validated and @notblank to SolrConfigurationProperties.url so that missing or empty Solr URL is caught at startup instead of failing at runtime. Add spring-boot-starter-validation dependency to enable Bean Validation. The existing @NullMarked JSpecify annotation on the package already covers the null-safety contract. Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
@notblank rejects only null, empty and all-whitespace values, so solr.url=localhost:8983 still binds successfully. java.net.URI parses that as scheme "localhost" with a null host, and SolrConfig normalizes it by pure string concatenation into localhost:8983/solr/ without noticing, so the misconfiguration only surfaces later as an opaque SolrJ connection error. Add a @SolrUrl constraint that parses the value with Spring's UriComponentsBuilder and requires an absolute URL whose scheme is http or https and which carries a non-empty host -- exactly the set HttpJdkSolrClient can talk to. Null and blank stay @notblank's responsibility so a single mistake yields a single message. The two ApplicationContextRunner tests are @DisabledInNativeImage: that runner builds its AssertableApplicationContext through java.lang.reflect.Proxy, which GraalVM cannot materialize without a build-time registration. The constraint itself runs natively and is covered there by the parameterized tests. Verified: ./gradlew build passes; nativeTest -Pnative shows 68 failures both with and without this change (pre-existing on this branch's base) with 15 added passing tests and no new failures. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
adityamparikh
force-pushed
the
fix/solr-config-properties-validation
branch
from
August 19, 2026 11:58
b1c961d to
0f3e043
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fail-fast validation for
solr.url, so a misconfigured deployment dies at startup with an actionable message instead of at first request with an opaque SolrJ error.@Validated+@NotBlanktoSolrConfigurationProperties.url@SolrUrl, a Bean Validation constraint requiring an absolutehttp/httpsURL with a non-empty host, implemented with Spring'sUriComponentsBuilderspring-boot-starter-validationdependencyWhy
@NotBlankalone isn't enough@NotBlankrejects onlynull,""and all-whitespace.solr.url=localhost:8983— omitting the scheme is an easy mistake — binds successfully.java.net.URIparses it as schemelocalhostwith anullhost, andSolrConfignormalizes it by pure string concatenation intolocalhost:8983/solr/without ever noticing.http://localhost:8983localhost:8983(schemelocalhost, no host)http://localhost:8983/solr/solr.example.com(not absolute)https://solr.internal:8983/custom/solr/ftp://…,file://…(SolrJ can't speak them)/solr,not a url,http://Null and blank remain
@NotBlank's responsibility, so a single mistake produces a single message rather than two overlapping ones.Test plan
Rebased onto
main@a84033b../gradlew buildpasses (full Testcontainers suite)./gradlew nativeTest -Pnative— 242 successful, 0 failedSolrUrlValidatorTest— 17 tests. Verified the suite actually detects the feature's absence: with the predicate neutered, exactly the 8 tests encoding the new behavior fail.SolrNativeHintschange needed — Spring'sBeanValidationBeanRegistrationAotProcessorregistersSolrUrlValidatorautomatically, confirmed by the 15 constraint tests passing inside the native test binary.Note for reviewers
The two
ApplicationContextRunnertests are@DisabledInNativeImage. That runner builds itsAssertableApplicationContextviajava.lang.reflect.Proxy, which GraalVM cannot materialize without a build-time registration. This is a test-harness limitation, not a constraint limitation — registering that proxy inSolrNativeHintswould push test-only scaffolding into the production image. The JVM build covers this path, and the constraint itself runs natively (15 passing, 2 skipped).🤖 Generated with Claude Code