Repository navigation
Conversation
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.
Problem
EffectiveVariant.isValidandEffectiveVariant.fromValuedisagree on case.isValidlower-cases its input before looking it up, so it acceptsON,True,Off,FALSEand so on, whilefromValuelooks the raw string up and only accepts the lower-case aliases. Both callers use them as a pair,isValidas the guard andfromValueright after it, so a mixed-case variant key passes the guard and then blows up infromValue:OpenFlagrProvider.getBooleanEvaluationpasses theisValidcheck, thenfromValuethrowsIllegalEnumValueExceptionstraight out of the provider. Every other failure in this provider is reported as aProviderEvaluationwithPARSE_ERROR; this is the only case where an exception escapes.DefaultOpenFlagr.isFeatureFlagOngoes through.filter(EffectiveVariant::isValid).map(EffectiveVariant::fromValue), the exception is caught by the genericcatch (Exception)and the method returnsfalsewith anUnexpected error.log. A flag whose variants are namedON/OFFin Flagr is therefore reported as off even when the evaluation returnedON.Flagr accepts upper-case variant keys (
^[\w\d-/\.\:]+$), so naming the variantsON/OFFin the Flagr UI is enough to hit this.isValid(null)also throwsNullPointerExceptioninstead of returningfalse.The inconsistency is currently pinned by the tests:
EffectiveVariantTestasserts bothisValid("ON") == trueand thatfromValue("ON")throws.Fix
Make
fromValuenormalize its input the same wayisValiddoes, so the two methods agree on what a valid alias is. Both now go through a singlenormalizehelper that usestoLowerCase(Locale.ROOT)(the existingisValidused the default-localetoLowerCase()).isValidreturnsfalsefornullinstead of throwing.The exception message and
getEnumValue()ofIllegalEnumValueExceptionstill carry the original, un-normalized value.I aligned
fromValuetoisValidrather than the other way round.isValidis public API and has been case-insensitive since the initial commit (the coverage tests from #10 also describe it asisValidAcceptsAliasesRegardlessOfCase), and a client that reads variant keys defined on the server side is better off acceptingONthan rejecting it. Making both methods case-sensitive would be a stricter public API change and would still leaveisValid(null)to fix. If you would rather keep the enum strict, I can flip the change to makeisValidcase-sensitive instead.OpenFlagrProviderandDefaultOpenFlagrare not touched; the enum change alone fixes both call sites.The
EffectiveVariantcopy inflagship4j-javaflagr-spring-boot-web-starteris case-sensitive in both methods, so it is consistent and left untouched.Tests
EffectiveVariantTest: the"ON"and"Off"cases move fromfromValueRejectsUnknownValueto a newfromValueResolvesAliasesRegardlessOfCase, so the rejection test only covers genuinely unknown values.isValidRejectsUnknownValuegains a@NullSourcecase.OpenFlagrProviderTest:booleanEvaluationMapsEffectiveVariantAliasesRegardlessOfCasechecks thatON/True/Off/FALSEproduce the right boolean withReason.DEFAULTand no error code.DefaultOpenFlagrTest:isFeatureFlagOnMapsEffectiveVariantAliasesRegardlessOfCasechecks the same keys end to end throughMockWebServer.Before the fix, 14 of the new cases fail:
IllegalEnumValueException: Cannot create enum from ON.in the enum and provider tests,NullPointerExceptionforisValid(null), andisFeatureFlagOnreturningfalseforON/True. With the fix,./gradlew clean buildpasses on JDK 8.