You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Why the SDK does not provide a way to fetch Long value? #501
From your description, I assume you are referring to the feature flag evaluation contract [1]. I am not sure about the historical reason for ignoring the Long type. However, it could be a valuable addition for providers.
From the spec point of view, we only enforce number evaluation [2]. When it comes to implementation, this translates into language-specific representations.
Maybe we could aim for a generic representation of numbers via Java Number [3] type evaluation instead of supporting each sub-type of Number such as Long and Short 🤔
If we add it though, what do we do with providers that don't specifically implement this? Or would we even expect them to? Might we instead just call resolveDoublevalue on the provider and use that value to create a Number?
I like this idea :) I also like Todd's suggestion to maintain backward compatibility.
IMHO: we should
add NumberEvaluation as a default method to the interface and redirect it per default to the DoubleEvaluation (this way, we won't break existing providers)
Now, my question would be if we deprecate the existing ones or want to keep them in place with a default implementation pointing to NumberEvaluation (I know a possible circular call if both are not implemented).
This ticket has been open for quite a while, and I think we should continue with this improvement. So, what do you think? especially about having default methods for all kinds of number sub-types or not.
I think it is reasonable to support Longs, no doubt there. We've heard it from customers of the Confidence SDKs as well.
I am very much on the fence of adding the default implementation of the FeatureProvider. getLongEvaluation that is using getIntegerEvaluation though. I don't think it is up to the SDK to make that decision but rather leave that to provider authors. This aligns with how we thought about it when adding Long support in the Kotlin SDK (I see how breaking the FeatureProvider API here feel more painful since we are post 1.0).
A default implementation that throws sounds tempting but I also see the issue with provider authors not realizing there's a new method to implement, end/sdk users would only discover the gap at runtime, which isn't great either, BUT it would push provider authors to implement the functionality based on the signals they listen to the most :).
I don't think there's a perfect answer here for post 1.0 SDKs. But if I had to pick, I'd lean toward the throwing + default value over the widening one. The widening default has the SDK silently narrowing the Long default value to Int before passing it to the provider, that'll produce bugs that are only found when integer numbers are large enough, a bit nasty. At least a clear error tells the user "this provider doesn't support Long yet" rather than quietly truncating.
On the spec side, I agree with @dd-oleksii that the spec already somewhat covers this: the client SHOULD provide functions "consistent with language idioms." Long is idiomatic Java, just like int64 is idiomatic Go. I'm open to making that more clear though.
I agree, I think the spec defines what is needed already good enough, changing the example makes sense to me.
A default implementation that throws sounds tempting but I also see the issue with provider authors not realizing there's a new method to implement, end/sdk users would only discover the gap at runtime, which isn't great either, BUT it would push provider authors to implement the functionality based on the signals they listen to the most :).
I agree with this @nicklasl! I fear that the getLongValue would error in many providers for a long time which could be even more confusing for app authors than the default implementation. This also with what @toddbaert says:
In fact, based on how few SDKs out there have long support, I'd worry that very few will support it at all and then you would get lots of defaulting here
For example, with the LaunchDarly provider, I think that would get you (2^53)-1 without any provider changes (we would put the double into the value and it would get basically cast on the way out). Though it would have to obviously narrow for providers which are setting integers directly into the values, which would have been a problem for any provider which had true 64-bit types already.
I would say that getObjectValue would also be a better backing method than getIntegerValue, but unfortunately it would change the semantics for the provider in the value of type mismatches. So that probably isn't viable.
I think passing the long into the getIntegerValue in the default implementation as @toddbaert proposes seems like the most viable solution.
When the default implementation is in use and a value larger than Integer.MAX_VALUE is passed to getLongValue we should at least log that this may lead to issues as the value is being floored.
I think based on everything above, there seems to be an ideal solution.
Premise 1: defaulting due to unimplemented methods is bad
Premise 2: truncating the default silently is bad
Premise 3: all ints can be widened to longs safely
Conclusion:
We should attempt to delegate to the getInt method(s), throwing and logging only if the supplied long default is out of the int range.
This seems like the best of both worlds; we throw less than we would if we hand't implemented anything, and we resolve some value at least in most cases. We may want to warn either way when this happens, or at least warn on the first time such an evaluation is attempted. There's an another case here as well where the "backend" is storing longs but the associated provider doesn't support the retrial of longs. IMO, this is a situation where the provider is falling short of the contract of it's own system, and it should simply implement getLong, so I don't think it's something we have to worry about too much. Hopefully such providers will be enhanced quickly.
What do you all think?
I should mention, there's a similar conversation in flagd to officially limit numeric values to (2^53)-1, due to problems with parsing and JS handling. This number is bigger than a Java int, but smaller than a Java long.
I think you are right... Check my logic then... in that case my proposal becomes:
We should attempt to delegate to the getDouble method(s), throwing and logging only if the supplied long default is beyond (2^53) -1.
I guess one caveat here is what to do if the getDouble value is a non-integer less than (2^53)-1... we've let providers decide to round or not in general for such questions, but in this case the SDK would have to make a call... throw? Round?
There could be some problems with providers that internally store flag representations more strongly typed. Such that if the storage is an integer than it cannot be accessed as a double.
Probably this would also affect 32/64 bit representations.
I think that the in-memory provider for Java is one such provider:
I think that that flagd RPC resolver would similarly produce a type mismatch error when the double variation method is used to resolve an integer.
Not insurmountable, but we will want to determine if you can coerce a 32-bit integer to a 64-bit one and if you can coerce a safe double to either of the integer types.
I think that that flagd RPC resolver would similarly produce a type mismatch error when the double variation method is used to resolve an integer.
flagd has some specific inconsistencies around numeric conversion, but they're somewhat separate from this discussion; I'll file those independently.
Proposing: add getLongValue with a default getLongEvaluation that delegates to getDoubleEvaluation, throwing on out-of-safe-range or fractional values. At the end of the day this is best-effort; providers can opt into whatever getLong implementation they feel is right, or leave it unimplemented. That said, @kinyoklion's observation is valid, and we may want to specify the expected coercion behavior here and update the in-memory provider's type-checking along with this change. It will take some time for consumers to start using this anyway.
Activity
Kavindu-Dodan commentedon Jul 10, 2023
@apulbere thank you for raising your concern.
From your description, I assume you are referring to the feature flag evaluation contract [1]. I am not sure about the historical reason for ignoring the
Longtype. However, it could be a valuable addition for providers.From the spec point of view, we only enforce
numberevaluation [2]. When it comes to implementation, this translates into language-specific representations.Maybe we could aim for a generic representation of numbers via Java
Number[3] type evaluation instead of supporting each sub-type ofNumbersuch asLongandShort🤔cc - @toddbaert @justinabrahms appreciate opnion here
[1] - https://github.com/open-feature/java-sdk/blob/main/src/main/java/dev/openfeature/sdk/FeatureProvider.java#L16-L24
[2] - https://github.com/open-feature/spec/blob/main/specification/sections/01-flag-evaluation.md#13-flag-evaluation
[3] - https://docs.oracle.com/javase/8/docs/api/java/lang/Number.html
justinabrahms commentedon Jul 10, 2023
I'd support something around
Number. I don't think I knew about it at the time.toddbaert commentedon Sep 6, 2023
I think
Numbermakes sense.If we add it though, what do we do with providers that don't specifically implement this? Or would we even expect them to? Might we instead just call
resolveDoublevalueon the provider and use that value to create aNumber?I'm not sure...
aepfli commentedon Oct 16, 2024
I like this idea :) I also like Todd's suggestion to maintain backward compatibility.
IMHO: we should
NumberEvaluationas a default method to the interface and redirect it per default to theDoubleEvaluation(this way, we won't break existing providers)NumberEvaluation(I know a possible circular call if both are not implemented).This ticket has been open for quite a while, and I think we should continue with this improvement. So, what do you think? especially about having default methods for all kinds of number sub-types or not.
toddbaert commentedon Oct 18, 2024
I like your plan. I'm really not sure about your question though. My gut says deprecate the other numerics, but I'm not sure. 🤔
aepfli commentedon May 6, 2025
relates to #872
feat: add getNumberEvaluation method delegating to getDoubleEvaluation (
carla-was-not-available commentedon Jul 31, 2025
Hey, I would love to work on this. :)
feat: add getNumberEvaluation method delegating to getDoubleEvaluation (
11 remaining items
toddbaert commentedon May 26, 2026
@erka also brought up that the openfeature CLI might have issues generating Java code with this: https://cloud-native.slack.com/archives/C0344AANLA1/p1779809278908259?thread_ts=1779737896.685529&cid=C0344AANLA1
nicklasl commentedon May 27, 2026
I think it is reasonable to support Longs, no doubt there. We've heard it from customers of the Confidence SDKs as well.
I am very much on the fence of adding the default implementation of the
FeatureProvider. getLongEvaluationthat is usinggetIntegerEvaluationthough. I don't think it is up to the SDK to make that decision but rather leave that to provider authors. This aligns with how we thought about it when adding Long support in the Kotlin SDK (I see how breaking theFeatureProviderAPI here feel more painful since we are post 1.0).A default implementation that throws sounds tempting but I also see the issue with provider authors not realizing there's a new method to implement, end/sdk users would only discover the gap at runtime, which isn't great either, BUT it would push provider authors to implement the functionality based on the signals they listen to the most :).
I don't think there's a perfect answer here for post 1.0 SDKs. But if I had to pick, I'd lean toward the throwing + default value over the widening one. The widening default has the SDK silently narrowing the Long default value to Int before passing it to the provider, that'll produce bugs that are only found when integer numbers are large enough, a bit nasty. At least a clear error tells the user "this provider doesn't support Long yet" rather than quietly truncating.
On the spec side, I agree with @dd-oleksii that the spec already somewhat covers this: the client SHOULD provide functions "consistent with language idioms." Long is idiomatic Java, just like int64 is idiomatic Go. I'm open to making that more clear though.
lukas-reining commentedon May 27, 2026
I agree, I think the spec defines what is needed already good enough, changing the example makes sense to me.
I agree with this @nicklasl! I fear that the
getLongValuewould error in many providers for a long time which could be even more confusing for app authors than the default implementation. This also with what @toddbaert says:I think passing the long into the getIntegerValue in the default implementation as @toddbaert proposes seems like the most viable solution.
When the default implementation is in use and a value larger than
Integer.MAX_VALUEis passed togetLongValuewe should at least log that this may lead to issues as the value is being floored.toddbaert commentedon May 27, 2026
I think based on everything above, there seems to be an ideal solution.
Premise 1: defaulting due to unimplemented methods is bad
Premise 2: truncating the default silently is bad
Premise 3: all ints can be widened to longs safely
Conclusion:
We should attempt to delegate to the
getIntmethod(s), throwing and logging only if the supplied long default is out of the int range.This seems like the best of both worlds; we throw less than we would if we hand't implemented anything, and we resolve some value at least in most cases. We may want to warn either way when this happens, or at least warn on the first time such an evaluation is attempted. There's an another case here as well where the "backend" is storing longs but the associated provider doesn't support the retrial of longs. IMO, this is a situation where the provider is falling short of the contract of it's own system, and it should simply implement
getLong, so I don't think it's something we have to worry about too much. Hopefully such providers will be enhanced quickly.What do you all think?
I should mention, there's a similar conversation in flagd to officially limit numeric values to (2^53)-1, due to problems with parsing and JS handling. This number is bigger than a Java int, but smaller than a Java long.
lukas-reining commentedon May 27, 2026
I agree. It is a compromise but makes the current problem visible which I find is a real improvement.
I support this way forward @toddbaert!
chrfwow commentedon May 27, 2026
Why don't we delegate to
getDouble? This gives us an even greater range of supported values before we'd have to throwtoddbaert commentedon May 27, 2026
@chrfwow
I think you are right... Check my logic then... in that case my proposal becomes:
I guess one caveat here is what to do if the
getDoublevalue is a non-integer less than (2^53)-1... we've let providers decide to round or not in general for such questions, but in this case the SDK would have to make a call... throw? Round?chrfwow commentedon May 27, 2026
We should not deliver random values to users. If we can't seliver the value from the management system, we should throw instead of rounding
nicklasl commentedon May 27, 2026
I can get behind this. Pragmatic 👍
kinyoklion commentedon May 27, 2026
There could be some problems with providers that internally store flag representations more strongly typed. Such that if the storage is an integer than it cannot be accessed as a double.
Probably this would also affect 32/64 bit representations.
I think that the in-memory provider for Java is one such provider:
java-sdk/src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java
Line 164 in 5562cb9
I think that that flagd RPC resolver would similarly produce a type mismatch error when the double variation method is used to resolve an integer.
Not insurmountable, but we will want to determine if you can coerce a 32-bit integer to a 64-bit one and if you can coerce a safe double to either of the integer types.
fix: expand example for 1.3.3.1 (#387)
toddbaert commentedon Jun 8, 2026
flagd has some specific inconsistencies around numeric conversion, but they're somewhat separate from this discussion; I'll file those independently.
Proposing: add getLongValue with a default getLongEvaluation that delegates to getDoubleEvaluation, throwing on out-of-safe-range or fractional values. At the end of the day this is best-effort; providers can opt into whatever getLong implementation they feel is right, or leave it unimplemented. That said, @kinyoklion's observation is valid, and we may want to specify the expected coercion behavior here and update the in-memory provider's type-checking along with this change. It will take some time for consumers to start using this anyway.