Skip to content

NPE and API Error when evaluating segments with missing Traits #200

@luisboch

Description

@luisboch

Description

A critical issue occurs when attempting to resolve flags for an identity if the Flagsmith dashboard has a Segment defined with a rule using a Trait that is not provided by the Java client.

This break occurs regardless of the evaluation mode (Local or Remote), though the symptoms differ:

Local Evaluation: Throws a NullPointerException during the comparison logic.

Remote Evaluation: Fails with a FlagsmithApiError.

Environment

Java Version: 21

Flagsmith Java Client Version: 7.4.3

Steps to Reproduce

Create a Segment in the Flagsmith dashboard with a rule based on a trait (e.g., plan_type == 'premium').

Create a Feature Flag that is enabled only for that Segment.

In the Java Client, attempt to get flags for an identity without passing the plan_type trait.

Observed Behavior

  1. Local Evaluation Mode
    The client fails while trying to compare the missing trait value, resulting in the following stack trace:
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "value1" is null
    at com.flagsmith.internal.SegmentEvaluator.compare(SegmentEvaluator.java:...) 
  1. Remote Evaluation Mode
    The API request fails to process the identity resolution, returning a 500 or 400 series error wrapped by the SDK:
Caused by: com.flagsmith.exceptions.FlagsmithApiError: Failed to get feature flags.
	at com.flagsmith.FlagsmithClient.getIdentityFlagsFromApi(FlagsmithClient.java:287)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions