Program: 15385
Project: 15385
Buggy source:
@Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile,long timestamp,UUID session,boolean fromCache,final String mimetype){
  if (mimetype == null || (!Constants.Mime.isImage(mimetype) && !Constants.Mime.isVideo(mimetype))) {
    revertToWeb();
    return;
  }
  final InputStream cacheFileInputStream;
  try {
    cacheFileInputStream=cacheFile.getInputStream();
  }
 catch (  IOException e) {
    notifyFailure(RequestFailureType.PARSE,e,null,"String_Node_Str");
    return;
  }
  if (cacheFileInputStream == null) {
    notifyFailure(RequestFailureType.CACHE_MISS,null,null,"String_Node_Str");
    return;
  }
  if (Constants.Mime.isVideo(mimetype)) {
    General.UI_THREAD_HANDLER.post(new Runnable(){
      public void run(){
        if (mIsDestroyed)         return;
        mRequest=null;
        try {
          final RelativeLayout layout=new RelativeLayout(context);
          layout.setGravity(Gravity.CENTER);
          final VideoView videoView=new VideoView(ImageViewActivity.this);
          videoView.setVideoURI(cacheFile.getUri());
          layout.addView(videoView);
          setContentView(layout);
          layout.getLayoutParams().width=ViewGroup.LayoutParams.MATCH_PARENT;
          layout.getLayoutParams().height=ViewGroup.LayoutParams.MATCH_PARENT;
          videoView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
          videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
            @Override public void onPrepared(            MediaPlayer mp){
              mp.setLooping(true);
              videoView.start();
            }
          }
);
          videoView.setOnErrorListener(new MediaPlayer.OnErrorListener(){
            @Override public boolean onError(            final MediaPlayer mediaPlayer,            final int i,            final int i1){
              revertToWeb();
              return true;
            }
          }
);
          videoView.setOnTouchListener(new View.OnTouchListener(){
            @Override public boolean onTouch(            final View view,            final MotionEvent motionEvent){
              finish();
              return true;
            }
          }
);
        }
 catch (        OutOfMemoryError e) {
          General.quickToast(context,R.string.imageview_oom);
          revertToWeb();
        }
catch (        Throwable e) {
          General.quickToast(context,R.string.imageview_invalid_video);
          revertToWeb();
        }
      }
    }
);
  }
 else   if (Constants.Mime.isImageGif(mimetype)) {
    final PrefsUtility.GifViewMode gifViewMode=PrefsUtility.pref_behaviour_gifview_mode(context,sharedPreferences);
    if (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_BROWSER) {
      revertToWeb();
      return;
    }
 else     if (gifViewMode == PrefsUtility.GifViewMode.EXTERNAL_BROWSER) {
      General.UI_THREAD_HANDLER.post(new Runnable(){
        @Override public void run(){
          LinkHandler.openWebBrowser(ImageViewActivity.this,Uri.parse(mUrl.toString()));
          finish();
        }
      }
);
      return;
    }
    if (AndroidApi.isIceCreamSandwichOrLater() && gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE) {
      General.UI_THREAD_HANDLER.post(new Runnable(){
        public void run(){
          if (mIsDestroyed)           return;
          mRequest=null;
          try {
            final GIFView gifView=new GIFView(ImageViewActivity.this,cacheFileInputStream);
            setContentView(gifView);
            gifView.setOnClickListener(new View.OnClickListener(){
              public void onClick(              View v){
                finish();
              }
            }
);
          }
 catch (          OutOfMemoryError e) {
            General.quickToast(context,R.string.imageview_oom);
            revertToWeb();
          }
catch (          Throwable e) {
            General.quickToast(context,R.string.imageview_invalid_gif);
            revertToWeb();
          }
        }
      }
);
    }
 else {
      gifThread=new GifDecoderThread(cacheFileInputStream,new GifDecoderThread.OnGifLoadedListener(){
        public void onGifLoaded(){
          General.UI_THREAD_HANDLER.post(new Runnable(){
            public void run(){
              if (mIsDestroyed)               return;
              mRequest=null;
              imageView=new ImageView(context);
              imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
              setContentView(imageView);
              gifThread.setView(imageView);
              imageView.setOnClickListener(new View.OnClickListener(){
                public void onClick(                View v){
                  finish();
                }
              }
);
            }
          }
);
        }
        public void onOutOfMemory(){
          General.quickToast(context,R.string.imageview_oom);
          revertToWeb();
        }
        public void onGifInvalid(){
          General.quickToast(context,R.string.imageview_invalid_gif);
          revertToWeb();
        }
      }
);
      gifThread.start();
    }
  }
 else {
    final ImageTileSource imageTileSource;
    try {
      final long bytes=cacheFile.getSize();
      final byte[] buf=new byte[(int)bytes];
      try {
        new DataInputStream(cacheFileInputStream).readFully(buf);
      }
 catch (      IOException e) {
        throw new RuntimeException(e);
      }
      try {
        imageTileSource=new ImageTileSourceWholeBitmap(buf);
      }
 catch (      Throwable t) {
        Log.e("String_Node_Str","String_Node_Str",t);
        General.quickToast(context,R.string.imageview_decode_failed);
        revertToWeb();
        return;
      }
    }
 catch (    OutOfMemoryError e) {
      General.quickToast(context,R.string.imageview_oom);
      revertToWeb();
      return;
    }
    General.UI_THREAD_HANDLER.post(new Runnable(){
      public void run(){
        if (mIsDestroyed)         return;
        mRequest=null;
        mImageViewDisplayerManager=new ImageViewDisplayListManager(imageTileSource,ImageViewActivity.this);
        surfaceView=new RRGLSurfaceView(ImageViewActivity.this,mImageViewDisplayerManager);
        setContentView(surfaceView);
        surfaceView.setOnClickListener(new View.OnClickListener(){
          public void onClick(          View v){
            finish();
          }
        }
);
        if (mIsPaused) {
          surfaceView.onPause();
        }
 else {
          surfaceView.onResume();
        }
      }
    }
);
  }
}

Fixed version (ground truth):
@Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile,long timestamp,UUID session,boolean fromCache,final String mimetype){
  if (mimetype == null || (!Constants.Mime.isImage(mimetype) && !Constants.Mime.isVideo(mimetype))) {
    revertToWeb();
    return;
  }
  final InputStream cacheFileInputStream;
  try {
    cacheFileInputStream=cacheFile.getInputStream();
  }
 catch (  IOException e) {
    notifyFailure(RequestFailureType.PARSE,e,null,"String_Node_Str");
    return;
  }
  if (cacheFileInputStream == null) {
    notifyFailure(RequestFailureType.CACHE_MISS,null,null,"String_Node_Str");
    return;
  }
  if (Constants.Mime.isVideo(mimetype)) {
    AndroidApi.UI_THREAD_HANDLER.post(new Runnable(){
      public void run(){
        if (mIsDestroyed)         return;
        mRequest=null;
        try {
          final RelativeLayout layout=new RelativeLayout(context);
          layout.setGravity(Gravity.CENTER);
          final VideoView videoView=new VideoView(ImageViewActivity.this);
          videoView.setVideoURI(cacheFile.getUri());
          layout.addView(videoView);
          setContentView(layout);
          layout.getLayoutParams().width=ViewGroup.LayoutParams.MATCH_PARENT;
          layout.getLayoutParams().height=ViewGroup.LayoutParams.MATCH_PARENT;
          videoView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
          videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
            @Override public void onPrepared(            MediaPlayer mp){
              mp.setLooping(true);
              videoView.start();
            }
          }
);
          videoView.setOnErrorListener(new MediaPlayer.OnErrorListener(){
            @Override public boolean onError(            final MediaPlayer mediaPlayer,            final int i,            final int i1){
              revertToWeb();
              return true;
            }
          }
);
          videoView.setOnTouchListener(new View.OnTouchListener(){
            @Override public boolean onTouch(            final View view,            final MotionEvent motionEvent){
              finish();
              return true;
            }
          }
);
        }
 catch (        OutOfMemoryError e) {
          General.quickToast(context,R.string.imageview_oom);
          revertToWeb();
        }
catch (        Throwable e) {
          General.quickToast(context,R.string.imageview_invalid_video);
          revertToWeb();
        }
      }
    }
);
  }
 else   if (Constants.Mime.isImageGif(mimetype)) {
    final PrefsUtility.GifViewMode gifViewMode=PrefsUtility.pref_behaviour_gifview_mode(context,sharedPreferences);
    if (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_BROWSER) {
      revertToWeb();
      return;
    }
 else     if (gifViewMode == PrefsUtility.GifViewMode.EXTERNAL_BROWSER) {
      AndroidApi.UI_THREAD_HANDLER.post(new Runnable(){
        @Override public void run(){
          LinkHandler.openWebBrowser(ImageViewActivity.this,Uri.parse(mUrl.toString()));
          finish();
        }
      }
);
      return;
    }
    if (AndroidApi.isIceCreamSandwichOrLater() && gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE) {
      AndroidApi.UI_THREAD_HANDLER.post(new Runnable(){
        public void run(){
          if (mIsDestroyed)           return;
          mRequest=null;
          try {
            final GIFView gifView=new GIFView(ImageViewActivity.this,cacheFileInputStream);
            setContentView(gifView);
            gifView.setOnClickListener(new View.OnClickListener(){
              public void onClick(              View v){
                finish();
              }
            }
);
          }
 catch (          OutOfMemoryError e) {
            General.quickToast(context,R.string.imageview_oom);
            revertToWeb();
          }
catch (          Throwable e) {
            General.quickToast(context,R.string.imageview_invalid_gif);
            revertToWeb();
          }
        }
      }
);
    }
 else {
      gifThread=new GifDecoderThread(cacheFileInputStream,new GifDecoderThread.OnGifLoadedListener(){
        public void onGifLoaded(){
          AndroidApi.UI_THREAD_HANDLER.post(new Runnable(){
            public void run(){
              if (mIsDestroyed)               return;
              mRequest=null;
              imageView=new ImageView(context);
              imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
              setContentView(imageView);
              gifThread.setView(imageView);
              imageView.setOnClickListener(new View.OnClickListener(){
                public void onClick(                View v){
                  finish();
                }
              }
);
            }
          }
);
        }
        public void onOutOfMemory(){
          General.quickToast(context,R.string.imageview_oom);
          revertToWeb();
        }
        public void onGifInvalid(){
          General.quickToast(context,R.string.imageview_invalid_gif);
          revertToWeb();
        }
      }
);
      gifThread.start();
    }
  }
 else {
    final ImageTileSource imageTileSource;
    try {
      final long bytes=cacheFile.getSize();
      final byte[] buf=new byte[(int)bytes];
      try {
        new DataInputStream(cacheFileInputStream).readFully(buf);
      }
 catch (      IOException e) {
        throw new RuntimeException(e);
      }
      try {
        imageTileSource=new ImageTileSourceWholeBitmap(buf);
      }
 catch (      Throwable t) {
        Log.e("String_Node_Str","String_Node_Str",t);
        General.quickToast(context,R.string.imageview_decode_failed);
        revertToWeb();
        return;
      }
    }
 catch (    OutOfMemoryError e) {
      General.quickToast(context,R.string.imageview_oom);
      revertToWeb();
      return;
    }
    AndroidApi.UI_THREAD_HANDLER.post(new Runnable(){
      public void run(){
        if (mIsDestroyed)         return;
        mRequest=null;
        mImageViewDisplayerManager=new ImageViewDisplayListManager(imageTileSource,ImageViewActivity.this);
        surfaceView=new RRGLSurfaceView(ImageViewActivity.this,mImageViewDisplayerManager);
        setContentView(surfaceView);
        surfaceView.setOnClickListener(new View.OnClickListener(){
          public void onClick(          View v){
            finish();
          }
        }
);
        if (mIsPaused) {
          surfaceView.onPause();
        }
 else {
          surfaceView.onResume();
        }
      }
    }
);
  }
}