google / openrtb-doubleclick

Utilities for DoubleClick Ad Exchange, including OpenRTB mapping, DoubleClick cryptography, metadata and validation
Apache License 2.0
198 stars 82 forks source link

Checking if playback method is null before attempting to add it #62

Closed marcelomalcher closed 9 years ago

marcelomalcher commented 9 years ago

The mapper is throwing a NullPointerException when dealing with bid requests for video opportunities.

From Adx spec we have the following regarding Playback Method:

// Describes how the ad was played.
enum VideoPlaybackMethod {
  METHOD_UNKNOWN = 0;
  AUTO_PLAY_SOUND_ON = 1;
  AUTO_PLAY_SOUND_OFF = 2;
  CLICK_TO_PLAY = 3;
};
optional VideoPlaybackMethod playback_method = 14 [default = METHOD_UNKNOWN];

This field is optional and the default value is unknown.

Then, the static method VideoPlaybackMethodMapper.toOpenRtb returns null for the default value (unknown) when mapping video requests.

Well, the OpenRtb Video.Builder.addPlaybackmethod does not allow null values:

public OpenRtb.BidRequest.Imp.Video.Builder addPlaybackmethod(OpenRtb.BidRequest.Imp.Video.VideoPlaybackMethod value) {
  if(value == null) {
    throw new NullPointerException();
  } else {
    this.ensurePlaybackmethodIsMutable();
    this.playbackmethod_.add(value);
    this.onChanged();
    return this;
  }
}

Therefore, it is necessary to add the check to prevent adding the playback method when the value is null.

opinali commented 9 years ago

Good catch, thanks!