Code review comment: You could look into removing the nullness warning suppression at the top of the class to automate this catch if needed.  But that might require more fixes than we want to make in this cl

Code under review:
public void addTimingInfo(Collection<GetWorkStreamTimingInfo> infos) {
      
      
      
      
      
      
      
      
      Map<Event, Instant> getWorkStreamTimings = new HashMap<>();
      for (GetWorkStreamTimingInfo info : infos) {
        getWorkStreamTimings.putIfAbsent(
            info.getEvent(), Instant.ofEpochMilli(info.getTimestampUsec() / 1000));
      }
      Instant workItemCreationStart = getWorkStreamTimings.get(Event.GET_WORK_CREATION_START);
      Instant workItemCreationEnd = getWorkStreamTimings.get(Event.GET_WORK_CREATION_END);
      
      if (workItemCreationStart != null
          && workItemCreationEnd != null
          && workItemCreationLatency == null) {
        workItemCreationLatency =
            LatencyAttribution.newBuilder()
                .setState(State.GET_WORK_IN_WINDMILL_WORKER)
                .setTotalDurationMillis(
                    new Duration(workItemCreationStart, workItemCreationEnd).getMillis())
                .build();
      }
      if (workItemCreationEnd != null && workItemCreationEnd.isAfter(workItemCreationEndTime)) {
        workItemCreationEndTime = workItemCreationEnd;
      }

      Instant receivedByDispatcherTiming =
          getWorkStreamTimings.get(Event.GET_WORK_RECEIVED_BY_DISPATCHER);
      if (workItemCreationEnd != null && receivedByDispatcherTiming != null) {
        aggregatedGetWorkStreamLatencies.compute(
            State.GET_WORK_IN_TRANSIT_TO_DISPATCHER,
            (state_key, duration) -> {
              Duration newDuration = new Duration(workItemCreationEnd, receivedByDispatcherTiming);
              if (duration == null) {
                return newDuration;
              }
              return duration.plus(newDuration);
            });
      }
      Instant forwardedByDispatcherTiming =
          getWorkStreamTimings.get(Event.GET_WORK_FORWARDED_BY_DISPATCHER);
      Instant now = Instant.ofEpochMilli(clock.getMillis());
      if (forwardedByDispatcherTiming != null) {
        aggregatedGetWorkStreamLatencies.compute(
            State.GET_WORK_IN_TRANSIT_TO_USER_WORKER,
            (state_key, duration) -> {
              Duration newDuration = new Duration(forwardedByDispatcherTiming, now);
              if (duration == null) {
                return newDuration;
              }
              return duration.plus(newDuration);
            });
      }
      workItemLastChunkReceivedByWorkerTime = now;
    }

Line commented on: return duration.plus(newDuration);

Revised code:
public void addTimingInfo(Collection<GetWorkStreamTimingInfo> infos) {
      
      
      
      
      
      
      
      
      
      
      Map<Event, Instant> getWorkStreamTimings = new HashMap<>();
      for (GetWorkStreamTimingInfo info : infos) {
        getWorkStreamTimings.putIfAbsent(
            info.getEvent(), Instant.ofEpochMilli(info.getTimestampUsec() / 1000));
      }

      
      
      Instant workItemCreationStart = getWorkStreamTimings.get(Event.GET_WORK_CREATION_START);
      Instant workItemCreationEnd = getWorkStreamTimings.get(Event.GET_WORK_CREATION_END);
      if (workItemCreationStart != null
          && workItemCreationEnd != null
          && workItemCreationLatency == null) {
        workItemCreationLatency =
            LatencyAttribution.newBuilder()
                .setState(State.GET_WORK_IN_WINDMILL_WORKER)
                .setTotalDurationMillis(
                    new Duration(workItemCreationStart, workItemCreationEnd).getMillis())
                .build();
      }
      
      if (workItemCreationEnd != null && workItemCreationEnd.isAfter(workItemCreationEndTime)) {
        workItemCreationEndTime = workItemCreationEnd;
      }

      
      Instant receivedByDispatcherTiming =
          getWorkStreamTimings.get(Event.GET_WORK_RECEIVED_BY_DISPATCHER);
      if (workItemCreationEnd != null && receivedByDispatcherTiming != null) {
        Duration newDuration = new Duration(workItemCreationEnd, receivedByDispatcherTiming);
        aggregatedGetWorkStreamLatencies.compute(
            State.GET_WORK_IN_TRANSIT_TO_DISPATCHER,
            (stateKey, duration) -> {
              if (duration == null) {
                return new SumAndMaxDurations(newDuration, newDuration);
              }
              duration.max = newDuration.isLongerThan(duration.max) ? newDuration : duration.max;
              duration.sum = duration.sum.plus(newDuration);
              return duration;
            });
      }

      
      Instant forwardedByDispatcherTiming =
          getWorkStreamTimings.get(Event.GET_WORK_FORWARDED_BY_DISPATCHER);
      Instant now = Instant.ofEpochMilli(clock.getMillis());
      if (forwardedByDispatcherTiming != null) {
        Duration newDuration = new Duration(forwardedByDispatcherTiming, now);
        aggregatedGetWorkStreamLatencies.compute(
            State.GET_WORK_IN_TRANSIT_TO_USER_WORKER,
            (stateKey, duration) -> {
              if (duration == null) {
                return new SumAndMaxDurations(newDuration, newDuration);
              }
              duration.max = newDuration.isLongerThan(duration.max) ? newDuration : duration.max;
              duration.sum = duration.sum.plus(newDuration);
              return duration;
            });
      }
      workItemLastChunkReceivedByWorkerTime = now;
    }