Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

fix ContextBuilder.copyFrom NPE #15

Merged
merged 2 commits into from
Nov 9, 2023

Conversation

pedroafonsodias
Copy link
Contributor

base copyOnWrite*Attributes on respective objects nullability otherwise they will not be initialized causing NPE

base copyOnWrite*Attributes on respective objects nullability otherwise they will not be initialized causing NPE
@pedroafonsodias pedroafonsodias requested a review from a team November 9, 2023 15:31
@@ -380,8 +380,8 @@ ContextBuilder copyFrom(LDContext context) {
anonymous = context.isAnonymous();
attributes = context.attributes;
privateAttributes = context.privateAttributes;
copyOnWriteAttributes = true;
copyOnWritePrivateAttributes = true;
copyOnWriteAttributes = context.attributes != null;
Copy link

Choose a reason for hiding this comment

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

Suggestion: Objects.nonNull(context.attributes)

@tanderson-ld
Copy link
Contributor

@pedroafonsodias, thank you for bringing this to our attention. Could you provide steps/pseudocode for reproducing the NPE.

@pedroafonsodias
Copy link
Contributor Author

LDContext customContext = LDContext.builderFromContext(ldContext)
      .set("some_attribute", someValue)
      .build();
    ldClient.identify(customContext);
    @Bean
    public LDContext ldContext(final LaunchDarklyProperties properties) {
      return LDContext.builder(properties.getClientSideId()).build();
    }

Using springboot to create a default context and when reusing it to customize a new context it will fail unless we specify a dummy attribute when creating the initial LDContext.

I have added a test in the mean time.

@tanderson-ld
Copy link
Contributor

@pedroafonsodias, approved but going to take a bit more time making sure there are no adverse consequences that others may have already been accounting for in production. Thank you for your contribution!

@tanderson-ld tanderson-ld changed the base branch from main to main-contrib November 9, 2023 21:56
@tanderson-ld tanderson-ld merged commit bc12d19 into launchdarkly:main-contrib Nov 9, 2023
@driverpt
Copy link

Any ETA when this is going to be released?

@tanderson-ld
Copy link
Contributor

Working on releasing today.

LaunchDarklyReleaseBot added a commit that referenced this pull request Nov 13, 2023
## [2.1.1] - 2023-11-13
### Fixed:
- Fixes NPE when interacting with Context created by use of `copyFrom`.
(Thanks, [

pedroafonsodias](#15))

---------

Co-authored-by: Pedro Dias <[email protected]>
Co-authored-by: Todd Anderson <[email protected]>
@tanderson-ld
Copy link
Contributor

tanderson-ld commented Nov 13, 2023

@pedroafonsodias and @driverpt , what versions of the Java Server SDK are you using?

@driverpt
Copy link

driverpt commented Nov 13, 2023

5.10, very old versions. We detected this while upgrading to the latest version

LaunchDarklyReleaseBot added a commit to launchdarkly/java-sdk-internal that referenced this pull request Nov 14, 2023
## [1.2.1] - 2023-11-13
### Fixed:
- Fixes NPE when interacting with Context created by use of `copyFrom`.
(Thanks, [

pedroafonsodias](launchdarkly/java-sdk-common#15))

---------

Co-authored-by: Eli Bishop <[email protected]>
Co-authored-by: LaunchDarklyReleaseBot <[email protected]>
Co-authored-by: Todd Anderson <[email protected]>
Co-authored-by: tanderson-ld <[email protected]>
Co-authored-by: ld-repository-standards[bot] <113625520+ld-repository-standards[bot]@users.noreply.github.com>
Co-authored-by: Kane Parkinson <[email protected]>
Co-authored-by: Ryan Lamb <[email protected]>
LaunchDarklyReleaseBot added a commit to launchdarkly/java-server-sdk that referenced this pull request Nov 14, 2023
## [7.1.1] - 2023-11-14
### Fixed:
- Fixes NPE when interacting with Context created by copying. (Thanks, [

pedroafonsodias](launchdarkly/java-sdk-common#15))

---------

Co-authored-by: Eli Bishop <[email protected]>
Co-authored-by: LaunchDarklyReleaseBot <[email protected]>
Co-authored-by: Alex Engelberg <[email protected]>
Co-authored-by: Anton Mostovoy <[email protected]>
Co-authored-by: LaunchDarklyCI <[email protected]>
Co-authored-by: LaunchDarklyCI <[email protected]>
Co-authored-by: Gavin Whelan <[email protected]>
Co-authored-by: ssrm <[email protected]>
Co-authored-by: Harpo Roeder <[email protected]>
Co-authored-by: Ben Woskow <[email protected]>
Co-authored-by: Elliot <[email protected]>
Co-authored-by: Robert J. Neal <[email protected]>
Co-authored-by: Robert J. Neal <[email protected]>
Co-authored-by: Sam Stokes <[email protected]>
Co-authored-by: Ember Stevens <[email protected]>
Co-authored-by: ember-stevens <[email protected]>
Co-authored-by: Alex Engelberg <[email protected]>
Co-authored-by: Louis Chan <[email protected]>
Co-authored-by: Louis Chan <[email protected]>
Co-authored-by: Todd Anderson <[email protected]>
Co-authored-by: tanderson-ld <[email protected]>
Co-authored-by: Matthew M. Keeler <[email protected]>
Co-authored-by: ld-repository-standards[bot] <113625520+ld-repository-standards[bot]@users.noreply.github.com>
Co-authored-by: Kane Parkinson <[email protected]>
Co-authored-by: Ryan Lamb <[email protected]>
@tanderson-ld
Copy link
Contributor

tanderson-ld commented Nov 14, 2023

Should now be available in Java Server SDK 7.1.1. May still be propagating through package managers.

tanderson-ld added a commit to launchdarkly/android-client-sdk that referenced this pull request Mar 7, 2024
**Related issues**

This fix never propagated into the Android SDK and another customer
reported it. launchdarkly/java-sdk-common#15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants