Skip to content

Why the SDK does not provide a way to fetch Long value? #501

Description

@apulbere

I see we have getDoubleValue and getIntegerValue, but not for Long type.
I can open a PR to add that.

Activity

  1. Kavindu-Dodan commented on Jul 10, 2023

    @Kavindu-Dodan
    Contributor

    @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 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 🤔

    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

  2. justinabrahms commented on Jul 10, 2023

    @justinabrahms
    Member

    I'd support something around Number. I don't think I knew about it at the time.

  3. added
    community
    Needs Triage
    on Jul 10, 2023
  4. toddbaert commented on Sep 6, 2023

    @toddbaert
    Member

    I think Number makes 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 resolveDoublevalue on the provider and use that value to create a Number?

    I'm not sure...

  5. aepfli commented on Oct 16, 2024

    @aepfli
    Member

    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.

  6. toddbaert commented on Oct 18, 2024

    @toddbaert
    Member

    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. 🤔

  7. aepfli commented on May 6, 2025

    @aepfli
    Member

    relates to #872

  8. carla-was-not-available commented on Jul 31, 2025

    @carla-was-not-available
    Contributor

    Hey, I would love to work on this. :)

  9. 11 remaining items

  10. toddbaert commented on May 26, 2026

    @toddbaert
    Member
  11. nicklasl commented on May 27, 2026

    @nicklasl
    Member

    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.

  12. lukas-reining commented on May 27, 2026

    @lukas-reining
    Member

    My take is that this is already covered under Conditional Requirement 1.3.3.1:

    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.

  13. toddbaert commented on May 27, 2026

    @toddbaert
    Member

    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.

  14. lukas-reining commented on May 27, 2026

    @lukas-reining
    Member

    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.

    I agree. It is a compromise but makes the current problem visible which I find is a real improvement.

    What do you all think?

    I support this way forward @toddbaert!

  15. chrfwow commented on May 27, 2026

    @chrfwow
    Contributor

    Why don't we delegate to getDouble? This gives us an even greater range of supported values before we'd have to throw

  16. toddbaert commented on May 27, 2026

    @toddbaert
    Member

    Why don't we delegate to getDouble? This gives us an even greater range of supported values before we'd have to throw

    @chrfwow

    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?

  17. chrfwow commented on May 27, 2026

    @chrfwow
    Contributor

    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

  18. nicklasl commented on May 27, 2026

    @nicklasl
    Member

    What do you all think?

    I can get behind this. Pragmatic 👍

  19. kinyoklion commented on May 27, 2026

    @kinyoklion
    Member

    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:

    } else if (!expectedType.isInstance(flag.getVariants().get(flag.getDefaultVariant()))) {

    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.

  20. added a commit that references this issue on Jun 3, 2026
  21. toddbaert commented on Jun 8, 2026

    @toddbaert
    Member

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Triagecommunityhack.commit.push

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions