Repository navigation
Return false from PropertiesConfigReader.canLoad for missing resources - #770
Open
abhiishek340 wants to merge 1 commit into
Open
abhiishek340 wants to merge 1 commit into
abhiishek340 wants to merge 1 commit into
Conversation
canLoad(ClassLoader, String) returned `getResources(...) != null`, but getResources always returns a set, so the reader claimed every resource name. DefaultConfigLoader stops at the first reader whose canLoad is true, so when it was tried first, a missing `foo.properties` kept other readers (such as TypesafeConfigReader for `foo.conf`) from being tried. Check that the set is non-empty instead. Fixes Netflix#511
This branch has not been deployed
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.
Fixes #511.
PropertiesConfigReader.canLoad(ClassLoader, String)returnsgetResources(loader, name) != null. ButgetResourcesalways returns a (possibly empty)LinkedHashSet, socanLoadis true for every resource name.DefaultConfigLoader'sLoader.load(String)uses the first reader whosecanLoadis true and thenbreaks. WhenPropertiesConfigReaderis tried first, a missingfoo.propertiesstops any other reader from being tried. For example,TypesafeConfigReader(whosecanLoadis always true) never gets a chance atfoo.conf. Because the builder keeps readers in aHashSet, whether this happens depends on hash order, so the symptom can come and go between runs.The fix checks
!getResources(loader, name).isEmpty()instead. If no reader can load a name,load(String)already skips it without an error, so a missing resource still loads nothing; the only change is that later readers get their turn.Testing:
PropertyConfigReaderTest.canLoadOnlyExistingResources:canLoadis true forapplication/application.properties(test resources) and false for a missing name, with or without the suffix. It fails before the fix and passes after../gradlew :archaius2-core:test :archaius2-typesafe:test -DtestJdk=21: 201 tests, 0 failures (Java 8 toolchain for compilation, as the build configures).