Program: 174882
Project: 174882
Buggy source:
protected boolean initializeCamera(int width,int height){
  Log.d(TAG,"String_Node_Str");
  boolean result=true;
synchronized (this) {
    mCamera=null;
    if (mCameraIndex == CAMERA_ID_ANY) {
      Log.d(TAG,"String_Node_Str");
      try {
        mCamera=Camera.open();
      }
 catch (      Exception e) {
        Log.e(TAG,"String_Node_Str" + e.getLocalizedMessage());
      }
      if (mCamera == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        boolean connected=false;
        for (int camIdx=0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
          Log.d(TAG,"String_Node_Str" + Integer.valueOf(camIdx) + "String_Node_Str");
          try {
            mCamera=Camera.open(camIdx);
            connected=true;
          }
 catch (          RuntimeException e) {
            Log.e(TAG,"String_Node_Str" + camIdx + "String_Node_Str"+ e.getLocalizedMessage());
          }
          if (connected)           break;
        }
      }
    }
 else {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        int localCameraIndex=mCameraIndex;
        if (mCameraIndex == CAMERA_ID_BACK) {
          Log.i(TAG,"String_Node_Str");
          Camera.CameraInfo cameraInfo=new Camera.CameraInfo();
          for (int camIdx=0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
            Camera.getCameraInfo(camIdx,cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
              localCameraIndex=camIdx;
              break;
            }
          }
        }
 else         if (mCameraIndex == CAMERA_ID_FRONT) {
          Log.i(TAG,"String_Node_Str");
          Camera.CameraInfo cameraInfo=new Camera.CameraInfo();
          for (int camIdx=0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
            Camera.getCameraInfo(camIdx,cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
              localCameraIndex=camIdx;
              break;
            }
          }
        }
        if (localCameraIndex == CAMERA_ID_BACK) {
          Log.e(TAG,"String_Node_Str");
        }
 else         if (localCameraIndex == CAMERA_ID_FRONT) {
          Log.e(TAG,"String_Node_Str");
        }
 else {
          Log.d(TAG,"String_Node_Str" + Integer.valueOf(localCameraIndex) + "String_Node_Str");
          try {
            mCamera=Camera.open(localCameraIndex);
          }
 catch (          RuntimeException e) {
            Log.e(TAG,"String_Node_Str" + localCameraIndex + "String_Node_Str"+ e.getLocalizedMessage());
          }
        }
      }
    }
    if (mCamera == null)     return false;
    try {
      Camera.Parameters params=mCamera.getParameters();
      Log.d(TAG,"String_Node_Str");
      List<android.hardware.Camera.Size> sizes=params.getSupportedPreviewSizes();
      if (sizes != null) {
        Size frameSize=calculateCameraFrameSize(sizes,new MagicCameraView.JavaCameraSizeAccessor(),width,height);
        params.setPreviewFormat(ImageFormat.NV21);
        Log.d(TAG,"String_Node_Str" + Integer.valueOf((int)frameSize.width) + "String_Node_Str"+ Integer.valueOf((int)frameSize.height));
        params.setPreviewSize((int)frameSize.width,(int)frameSize.height);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && !android.os.Build.MODEL.equals("String_Node_Str"))         params.setRecordingHint(true);
        List<String> FocusModes=params.getSupportedFocusModes();
        if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
          params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        }
        setPreviewFPS(30000,30000);
        mCamera.setParameters(params);
        params=mCamera.getParameters();
        mFrameWidth=params.getPreviewSize().width;
        mFrameHeight=params.getPreviewSize().height;
        if ((getLayoutParams().width == LayoutParams.MATCH_PARENT) && (getLayoutParams().height == LayoutParams.MATCH_PARENT))         mScale=Math.min(((float)height) / mFrameHeight,((float)width) / mFrameWidth);
 else         mScale=0;
        if (mFpsMeter != null) {
          mFpsMeter.setResolution(mFrameWidth,mFrameHeight);
        }
        int size=mFrameWidth * mFrameHeight;
        size=size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8;
        mBuffer=new byte[size];
        mCamera.addCallbackBuffer(mBuffer);
        mCamera.setPreviewCallbackWithBuffer(this);
        mFrameChain=new Mat[2];
        mFrameChain[0]=new Mat(mFrameHeight + (mFrameHeight / 2),mFrameWidth,CvType.CV_8UC1);
        mFrameChain[1]=new Mat(mFrameHeight + (mFrameHeight / 2),mFrameWidth,CvType.CV_8UC1);
        AllocateCache();
        mCameraFrame=new MagicCameraView.MagicCameraFrame[2];
        mCameraFrame[0]=new MagicCameraView.MagicCameraFrame(mFrameChain[0],mFrameWidth,mFrameHeight);
        mCameraFrame[1]=new MagicCameraView.MagicCameraFrame(mFrameChain[1],mFrameWidth,mFrameHeight);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
          mSurfaceTexture=new SurfaceTexture(MAGIC_TEXTURE_ID);
          mCamera.setPreviewTexture(mSurfaceTexture);
        }
 else         mCamera.setPreviewDisplay(null);
        Log.d(TAG,"String_Node_Str");
        mCamera.startPreview();
      }
 else       result=false;
    }
 catch (    Exception e) {
      result=false;
      e.printStackTrace();
    }
  }
  return result;
}

Fixed version (ground truth):
protected boolean initializeCamera(int width,int height){
  Log.d(TAG,"String_Node_Str");
  boolean result=true;
synchronized (this) {
    mCamera=null;
    if (mCameraIndex == CAMERA_ID_ANY) {
      Log.d(TAG,"String_Node_Str");
      try {
        mCamera=Camera.open();
      }
 catch (      Exception e) {
        Log.e(TAG,"String_Node_Str" + e.getLocalizedMessage());
      }
      if (mCamera == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        boolean connected=false;
        for (int camIdx=0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
          Log.d(TAG,"String_Node_Str" + Integer.valueOf(camIdx) + "String_Node_Str");
          try {
            mCamera=Camera.open(camIdx);
            connected=true;
          }
 catch (          RuntimeException e) {
            Log.e(TAG,"String_Node_Str" + camIdx + "String_Node_Str"+ e.getLocalizedMessage());
          }
          if (connected)           break;
        }
      }
    }
 else {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        int localCameraIndex=mCameraIndex;
        if (mCameraIndex == CAMERA_ID_BACK) {
          Log.i(TAG,"String_Node_Str");
          Camera.CameraInfo cameraInfo=new Camera.CameraInfo();
          for (int camIdx=0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
            Camera.getCameraInfo(camIdx,cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
              localCameraIndex=camIdx;
              break;
            }
          }
        }
 else         if (mCameraIndex == CAMERA_ID_FRONT) {
          Log.i(TAG,"String_Node_Str");
          Camera.CameraInfo cameraInfo=new Camera.CameraInfo();
          for (int camIdx=0; camIdx < Camera.getNumberOfCameras(); ++camIdx) {
            Camera.getCameraInfo(camIdx,cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
              localCameraIndex=camIdx;
              break;
            }
          }
        }
        if (localCameraIndex == CAMERA_ID_BACK) {
          Log.e(TAG,"String_Node_Str");
        }
 else         if (localCameraIndex == CAMERA_ID_FRONT) {
          Log.e(TAG,"String_Node_Str");
        }
 else {
          Log.d(TAG,"String_Node_Str" + Integer.valueOf(localCameraIndex) + "String_Node_Str");
          try {
            mCamera=Camera.open(localCameraIndex);
          }
 catch (          RuntimeException e) {
            Log.e(TAG,"String_Node_Str" + localCameraIndex + "String_Node_Str"+ e.getLocalizedMessage());
          }
        }
      }
    }
    if (mCamera == null)     return false;
    try {
      Camera.Parameters params=mCamera.getParameters();
      Log.d(TAG,"String_Node_Str");
      List<android.hardware.Camera.Size> sizes=params.getSupportedPreviewSizes();
      if (sizes != null) {
        Size frameSize=calculateCameraFrameSize(sizes,new JavaCameraSizeAccessor(),width,height);
        params.setPreviewFormat(ImageFormat.NV21);
        Log.d(TAG,"String_Node_Str" + Integer.valueOf((int)frameSize.width) + "String_Node_Str"+ Integer.valueOf((int)frameSize.height));
        params.setPreviewSize((int)frameSize.width,(int)frameSize.height);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && !android.os.Build.MODEL.equals("String_Node_Str"))         params.setRecordingHint(true);
        List<String> FocusModes=params.getSupportedFocusModes();
        if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
          params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        }
        mCamera.setParameters(params);
        params=mCamera.getParameters();
        mFrameWidth=params.getPreviewSize().width;
        mFrameHeight=params.getPreviewSize().height;
        if ((getLayoutParams().width == LayoutParams.MATCH_PARENT) && (getLayoutParams().height == LayoutParams.MATCH_PARENT))         mScale=Math.min(((float)height) / mFrameHeight,((float)width) / mFrameWidth);
 else         mScale=0;
        if (mFpsMeter != null) {
          mFpsMeter.setResolution(mFrameWidth,mFrameHeight);
        }
        int size=mFrameWidth * mFrameHeight;
        size=size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8;
        mBuffer=new byte[size];
        mCamera.addCallbackBuffer(mBuffer);
        mCamera.setPreviewCallbackWithBuffer(this);
        mFrameChain=new Mat[2];
        mFrameChain[0]=new Mat(mFrameHeight + (mFrameHeight / 2),mFrameWidth,CvType.CV_8UC1);
        mFrameChain[1]=new Mat(mFrameHeight + (mFrameHeight / 2),mFrameWidth,CvType.CV_8UC1);
        AllocateCache();
        mCameraFrame=new MagicCameraFrame[2];
        mCameraFrame[0]=new MagicCameraFrame(mFrameChain[0],mFrameWidth,mFrameHeight);
        mCameraFrame[1]=new MagicCameraFrame(mFrameChain[1],mFrameWidth,mFrameHeight);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
          mSurfaceTexture=new SurfaceTexture(MAGIC_TEXTURE_ID);
          mCamera.setPreviewTexture(mSurfaceTexture);
        }
 else         mCamera.setPreviewDisplay(null);
        Log.d(TAG,"String_Node_Str");
        mCamera.startPreview();
      }
 else       result=false;
    }
 catch (    Exception e) {
      result=false;
      e.printStackTrace();
    }
  }
  return result;
}