Skip to content

fix: no-op setup without api key#503

Merged
marandaneto merged 11 commits intomainfrom
fix/noop-empty-api-key
May 7, 2026
Merged

fix: no-op setup without api key#503
marandaneto merged 11 commits intomainfrom
fix/noop-empty-api-key

Conversation

@marandaneto
Copy link
Copy Markdown
Member

@marandaneto marandaneto commented Apr 30, 2026

💡 Motivation and Context

Setup currently continued initializing after the API key trimmed to an empty string. Java callers could also pass a null Android API key and hit SDK init unexpectedly.

This changes null API keys to trim to an empty string and makes core/stateless setup return before initialization when the key is empty after trimming. Android setup skips Android-specific configuration for invalid keys.

💚 How did you test it?

  • ./gradlew :posthog:test --tests "com.posthog.PostHogConfigTest" --tests "com.posthog.PostHogStatelessTest" --tests "com.posthog.PostHogTest"
  • ./gradlew :posthog-android:testDebugUnitTest --tests "com.posthog.android.PostHogAndroidConfigTest" --tests "com.posthog.android.PostHogAndroidConfigJavaTest" --tests "com.posthog.android.PostHogAndroidTest"
  • make checkFormat
  • ./gradlew :posthog:apiCheck :posthog-android:apiCheck

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Added a changeset file for the affected packages
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

posthog-android Compliance Report

Date: 2026-05-07 15:49:23 UTC
Duration: 2859ms

⚠️ Some Tests Failed

0/16 tests passed, 16 failed


Feature_Flags Tests

⚠️ 0/16 tests passed, 16 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 275ms
Request Payload.Flags Request Uses V2 Query Param 27ms
Request Payload.Flags Request Hits Flags Path Not Decide 40ms
Request Payload.Flags Request Omits Authorization Header 20ms
Request Payload.Token In Flags Body Matches Init 18ms
Request Payload.Groups Round Trip 18ms
Request Payload.Groups Default To Empty Object 17ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 16ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 18ms
Request Payload.Disable Geoip Omitted Defaults To False 19ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 19ms
Request Lifecycle.No Flags Request On Init Alone 12ms
Request Lifecycle.No Flags Request On Normal Capture 2057ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 18ms
Request Lifecycle.Mock Response Value Is Returned To Caller 16ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 15ms

Failures

request_payload.request_with_person_properties_device_id

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_uses_v2_query_param

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_hits_flags_path_not_decide

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flags_request_omits_authorization_header

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.token_in_flags_body_matches_init

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.groups_round_trip

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.groups_default_to_empty_object

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.disable_geoip_false_propagates_as_geoip_disable_false

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.disable_geoip_omitted_defaults_to_false

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_payload.flag_keys_to_evaluate_contains_only_requested_key

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_lifecycle.no_flags_request_on_init_alone

Expected 0 /flags requests, got 1

request_lifecycle.no_flags_request_on_normal_capture

Expected 0 /flags requests, got 1

request_lifecycle.two_flag_calls_produce_two_remote_requests

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

request_lifecycle.mock_response_value_is_returned_to_caller

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

side_effect_events.get_feature_flag_captures_feature_flag_called_event

404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'

@marandaneto marandaneto marked this pull request as ready for review May 7, 2026 13:28
@marandaneto marandaneto requested a review from a team as a code owner May 7, 2026 13:28
Comment thread posthog/src/main/java/com/posthog/PostHogStateless.kt
@marandaneto
Copy link
Copy Markdown
Member Author

@dustinbyrne can you check again, i changed a few things most related to personal api key checks

@marandaneto marandaneto requested review from a team and dustinbyrne May 7, 2026 15:46
Copy link
Copy Markdown
Contributor

@dustinbyrne dustinbyrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

@marandaneto marandaneto merged commit e2f9884 into main May 7, 2026
14 checks passed
@marandaneto marandaneto deleted the fix/noop-empty-api-key branch May 7, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants