Program: 33165
Project: 33165
Buggy source:
protected void writeEntity(final ServiceMetadata metadata,final EdmEntityType entityType,final Entity entity,final ContextURL contextURL,final ExpandOption expand,final SelectOption select,final boolean onlyReference,final JsonGenerator json) throws IOException, SerializerException {
  json.writeStartObject();
  if (!isODataMetadataNone) {
    if (contextURL != null) {
      writeContextURL(contextURL,json);
      writeMetadataETag(metadata,json);
    }
    if (entity.getETag() != null) {
      json.writeStringField(Constants.JSON_ETAG,entity.getETag());
    }
    if (entityType.hasStream()) {
      if (entity.getMediaETag() != null) {
        json.writeStringField(Constants.JSON_MEDIA_ETAG,entity.getMediaETag());
      }
      if (entity.getMediaContentType() != null) {
        json.writeStringField(Constants.JSON_MEDIA_CONTENT_TYPE,entity.getMediaContentType());
      }
      if (entity.getMediaContentSource() != null) {
        json.writeStringField(Constants.JSON_MEDIA_READ_LINK,entity.getMediaContentSource().toString());
      }
      if (entity.getMediaEditLinks() != null && !entity.getMediaEditLinks().isEmpty()) {
        json.writeStringField(Constants.JSON_MEDIA_EDIT_LINK,entity.getMediaEditLinks().get(0).getHref());
      }
    }
  }
  if (onlyReference) {
    json.writeStringField(Constants.JSON_ID,entity.getId().toASCIIString());
  }
 else {
    final EdmEntityType resolvedType=resolveEntityType(metadata,entityType,entity.getType());
    if (!isODataMetadataNone && !resolvedType.equals(entityType)) {
      json.writeStringField(Constants.JSON_TYPE,"String_Node_Str" + entity.getType());
    }
    writeProperties(resolvedType,entity.getProperties(),select,json);
    writeNavigationProperties(metadata,resolvedType,entity,expand,json);
    json.writeEndObject();
  }
}

Fixed version (ground truth):
protected void writeEntity(final ServiceMetadata metadata,final EdmEntityType entityType,final Entity entity,final ContextURL contextURL,final ExpandOption expand,final SelectOption select,final boolean onlyReference,final JsonGenerator json) throws IOException, SerializerException {
  json.writeStartObject();
  if (!isODataMetadataNone) {
    if (contextURL != null) {
      writeContextURL(contextURL,json);
      writeMetadataETag(metadata,json);
    }
    if (entity.getETag() != null) {
      json.writeStringField(Constants.JSON_ETAG,entity.getETag());
    }
    if (entityType.hasStream()) {
      if (entity.getMediaETag() != null) {
        json.writeStringField(Constants.JSON_MEDIA_ETAG,entity.getMediaETag());
      }
      if (entity.getMediaContentType() != null) {
        json.writeStringField(Constants.JSON_MEDIA_CONTENT_TYPE,entity.getMediaContentType());
      }
      if (entity.getMediaContentSource() != null) {
        json.writeStringField(Constants.JSON_MEDIA_READ_LINK,entity.getMediaContentSource().toString());
      }
      if (entity.getMediaEditLinks() != null && !entity.getMediaEditLinks().isEmpty()) {
        json.writeStringField(Constants.JSON_MEDIA_EDIT_LINK,entity.getMediaEditLinks().get(0).getHref());
      }
    }
  }
  if (onlyReference) {
    json.writeStringField(Constants.JSON_ID,entity.getId().toASCIIString());
  }
 else {
    final EdmEntityType resolvedType=resolveEntityType(metadata,entityType,entity.getType());
    if (!isODataMetadataNone && !resolvedType.equals(entityType)) {
      json.writeStringField(Constants.JSON_TYPE,"String_Node_Str" + entity.getType());
    }
    writeProperties(metadata,resolvedType,entity.getProperties(),select,json);
    writeNavigationProperties(metadata,resolvedType,entity,expand,json);
    json.writeEndObject();
  }
}