Program: 188861
Project: 188861
Buggy source:
/** 
 * Downloads media (GET /<channel>/<mediaId>) 
 */
@Get public Representation getMedia(){
  setServerHeader();
  Request request=getRequest();
  String userId=null;
  String token=null;
  String entityId=(String)request.getAttributes().get(Constants.ENTITY_ARG);
  String mediaId=(String)request.getAttributes().get(Constants.MEDIA_ARG);
  boolean isChannelPublic=XMPPToolBox.getInstance().getPubSubClient().isChannelPublic(entityId);
  if (!isChannelPublic && !mediaId.equals(Constants.AVATAR_ARG)) {
    String auth=getQueryValue(Constants.AUTH_QUERY);
    try {
      userId=getUserId(request,auth);
      token=getTransactionId(request,auth);
    }
 catch (    Throwable t) {
      setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
      return new StringRepresentation("String_Node_Str",MediaType.APPLICATION_JSON);
    }
    Representation verifyRequest=verifyRequest(userId,token,request.getResourceRef().getIdentifier());
    if (verifyRequest != null) {
      return verifyRequest;
    }
  }
  Integer maxHeight=null;
  Integer maxWidth=null;
  try {
    String queryValue=getQueryValue(Constants.MAX_HEIGHT_QUERY);
    if (queryValue != null) {
      maxHeight=Integer.valueOf(queryValue);
    }
    queryValue=getQueryValue(Constants.MAX_WIDTH_QUERY);
    if (queryValue != null) {
      maxWidth=Integer.valueOf(queryValue);
    }
  }
 catch (  Throwable t) {
    setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    return new StringRepresentation("String_Node_Str",MediaType.APPLICATION_JSON);
  }
  try {
    MediaDAO mediaDAO=DAOFactory.getInstance().getDAO();
    int maxAge=mediaDAO.getMaxAge();
    addCacheHeaders(maxAge);
    if (maxHeight == null && maxWidth == null) {
      MediaType mediaType=new MediaType(mediaDAO.getMediaType(entityId,mediaId));
      File media=mediaDAO.getMedia(userId,entityId,mediaId);
      return new FileRepresentation(media,mediaType,maxAge);
    }
    Thumbnail thumbnail=null;
    if (maxHeight != null && maxWidth == null) {
      thumbnail=mediaDAO.getMediaPreview(userId,entityId,mediaId,maxHeight);
    }
 else     if (maxHeight == null && maxWidth != null) {
      thumbnail=mediaDAO.getMediaPreview(userId,entityId,mediaId,maxWidth);
    }
 else {
      thumbnail=mediaDAO.getMediaPreview(userId,entityId,mediaId,maxHeight,maxWidth);
    }
    return new DynamicFileRepresentation(new MediaType(thumbnail.getMimeType()),thumbnail.getImg(),maxAge);
  }
 catch (  MetadataSourceException e) {
    setStatus(Status.SERVER_ERROR_INTERNAL);
  }
catch (  IOException e) {
    setStatus(Status.SERVER_ERROR_INTERNAL);
  }
catch (  MediaNotFoundException e) {
    setStatus(Status.CLIENT_ERROR_NOT_FOUND);
  }
catch (  InvalidPreviewFormatException e) {
    setStatus(Status.CLIENT_ERROR_PRECONDITION_FAILED);
  }
catch (  UserNotAllowedException e) {
    setStatus(Status.CLIENT_ERROR_FORBIDDEN);
  }
catch (  Throwable t) {
    return unexpectedError(t);
  }
  return new EmptyRepresentation();
}

Fixed version (ground truth):
/** 
 * Downloads media (GET /<channel>/<mediaId>) 
 */
@Get public Representation getMedia(){
  setServerHeader();
  Request request=getRequest();
  String userId=null;
  String token=null;
  String entityId=(String)request.getAttributes().get(Constants.ENTITY_ARG);
  String mediaId=(String)request.getAttributes().get(Constants.MEDIA_ARG);
  boolean isChannelPublic=XMPPToolBox.getInstance().getPubSubClient().isChannelPublic(entityId);
  if (!isChannelPublic && !mediaId.equals(Constants.AVATAR_ARG)) {
    String auth=getQueryValue(Constants.AUTH_QUERY);
    try {
      userId=getUserId(request,auth);
      token=getTransactionId(request,auth);
    }
 catch (    Throwable t) {
      setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
      return new StringRepresentation("String_Node_Str",MediaType.APPLICATION_JSON);
    }
    Representation verifyRequest=checkRequest(userId,token,request.getResourceRef().getIdentifier());
    if (verifyRequest != null) {
      return verifyRequest;
    }
  }
  Integer maxHeight=null;
  Integer maxWidth=null;
  try {
    String queryValue=getQueryValue(Constants.MAX_HEIGHT_QUERY);
    if (queryValue != null) {
      maxHeight=Integer.valueOf(queryValue);
    }
    queryValue=getQueryValue(Constants.MAX_WIDTH_QUERY);
    if (queryValue != null) {
      maxWidth=Integer.valueOf(queryValue);
    }
  }
 catch (  Throwable t) {
    setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    return new StringRepresentation("String_Node_Str",MediaType.APPLICATION_JSON);
  }
  try {
    MediaDAO mediaDAO=DAOFactory.getInstance().getDAO();
    int maxAge=mediaDAO.getMaxAge();
    addCacheHeaders(maxAge);
    if (maxHeight == null && maxWidth == null) {
      MediaType mediaType=new MediaType(mediaDAO.getMediaType(entityId,mediaId));
      File media=mediaDAO.getMedia(userId,entityId,mediaId);
      return new FileRepresentation(media,mediaType,maxAge);
    }
    Thumbnail thumbnail=null;
    if (maxHeight != null && maxWidth == null) {
      thumbnail=mediaDAO.getMediaPreview(userId,entityId,mediaId,maxHeight);
    }
 else     if (maxHeight == null && maxWidth != null) {
      thumbnail=mediaDAO.getMediaPreview(userId,entityId,mediaId,maxWidth);
    }
 else {
      thumbnail=mediaDAO.getMediaPreview(userId,entityId,mediaId,maxHeight,maxWidth);
    }
    return new DynamicFileRepresentation(new MediaType(thumbnail.getMimeType()),thumbnail.getImg(),maxAge);
  }
 catch (  MetadataSourceException e) {
    setStatus(Status.SERVER_ERROR_INTERNAL);
  }
catch (  IOException e) {
    setStatus(Status.SERVER_ERROR_INTERNAL);
  }
catch (  MediaNotFoundException e) {
    setStatus(Status.CLIENT_ERROR_NOT_FOUND);
  }
catch (  InvalidPreviewFormatException e) {
    setStatus(Status.CLIENT_ERROR_PRECONDITION_FAILED);
  }
catch (  UserNotAllowedException e) {
    setStatus(Status.CLIENT_ERROR_FORBIDDEN);
  }
catch (  Throwable t) {
    return unexpectedError(t);
  }
  return new EmptyRepresentation();
}