static Object combineValues(Object newValue, Object existingValue) {
        if (newValue instanceof QueryProfile newProfile) {
            if ( ! (existingValue instanceof QueryProfile)) {
                if ( ! isModifiable(newProfile)) {
                    // Make the query profile reference overridable
                    newProfile = new BackedOverridableQueryProfile(newProfile);
                }
                newProfile.value = existingValue;
                return newProfile;
            }

            // if both are profiles:
            return combineProfiles(newProfile, (QueryProfile)existingValue);
        }
        else {
            if (existingValue instanceof QueryProfile existingProfile) { // we need to set a non-leaf value on a query profile
                if (isModifiable(existingProfile)) {
                    existingProfile.setValue(newValue);
                    return null;
                }
                else {
                    QueryProfile existingOverridable = new BackedOverridableQueryProfile((QueryProfile)existingValue);
                    existingOverridable.setValue(newValue);
                    return existingOverridable;
                }
            }
            else {
                return newValue;
            }
        }
    }
Combines an existing and a new value for a query property key.
Return the new object to add to the state of the owning profile (/variant), or null if no new value needs to
be added (usually because the new value was added to the existing).
container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java