public final Span joinSpan(TraceContext context) {
    if (context == null) throw new NullPointerException("context == null");
    if (!supportsJoin) return newChild(context);

    // set shared flag if not already done
    int flags = InternalPropagation.instance.flags(context);
    if (!context.shared()) {
      flags |= FLAG_SHARED;
      return toSpan(context, InternalPropagation.instance.withFlags(context, flags));
    } else {
      flags &= ~FLAG_SHARED;
      return toSpan(InternalPropagation.instance.withFlags(context, flags), context);
    }
  }
@Test void join_idempotent() {
    TraceContext incoming = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true)
      .shared(true).build();

    TraceContext joined = tracer.joinSpan(incoming).context();
    assertThat(joined).isNotSameAs(incoming);
    assertThat(tracer.joinSpan(incoming).context()).isSameAs(joined);
  }