Buggy code:
public class CameraPreview extends ViewGroup { public interface StateListener { void previewSized ( ) { } void previewStarted ( ) { } void previewStopped ( ) { } void cameraError ( Exception error ) { } } private static final String TAG = CameraPreview . class . getSimpleName ( ) ; private CameraInstance cameraInstance ; private WindowManager windowManager ; private Handler stateHandler ; private boolean useTextureView = false ; private SurfaceView surfaceView ; private TextureView textureView ; private boolean previewActive = false ; private RotationListener rotationListener ; private List < CameraPreview . StateListener > stateListeners = new ArrayList < > ( ) ; private DisplayConfiguration displayConfiguration ; private CameraSettings cameraSettings = new CameraSettings ( ) ; private Size containerSize ; private Size previewSize ; private Rect surfaceRect ; private Size currentSurfaceSize ; private Rect framingRect = null ; private Rect previewFramingRect = null ; private Size framingRectSize = null ; private double marginFraction = 0.1 ; @ TargetApi ( 14 ) private SurfaceTextureListener surfaceTextureListener ( ) { } private final Callback surfaceCallback = new SurfaceHolder . Callback ( ) { @ Override public void surfaceCreated ( SurfaceHolder holder ) { } @ Override public void surfaceDestroyed ( SurfaceHolder holder ) { } @ Override public void surfaceChanged ( SurfaceHolder holder , int format , int width , int height ) { } } ; private final Handler . Callback stateCallback = new Handler . Callback ( ) { @ Override public boolean handleMessage ( Message message ) { } } ; private RotationCallback rotationCallback = new RotationCallback ( ) { @ Override public void onRotationChanged ( int rotation ) { } } ; public CameraPreview ( Context context ) { } public CameraPreview ( Context context , AttributeSet attrs ) { } public CameraPreview ( Context context , AttributeSet attrs , int defStyleAttr ) { } private void initialize ( Context context , AttributeSet attrs , int defStyleAttr , int defStyleRes ) { } @ Override protected void onAttachedToWindow ( ) { } protected void initializeAttributes ( AttributeSet attrs ) { } private void rotationChanged ( ) { } private void setupSurfaceView ( ) { } public void addStateListener ( CameraPreview . StateListener listener ) { } private final CameraPreview . StateListener fireState = new CameraPreview . StateListener ( ) { @ Override public void previewSized ( ) { } @ Override public void previewStarted ( ) { } @ Override public void previewStopped ( ) { } @ Override public void cameraError ( Exception error ) { } } ; private void calculateFrames ( ) { } public void setTorch ( boolean on ) { } private void containerSized ( Size containerSize ) { } private void previewSized ( Size size ) { } protected Matrix calculateTextureTransform ( Size textureSize , Size previewSize ) { } private void startPreviewIfReady ( ) { } @ SuppressLint ( "DrawAllocation" ) @ Override protected void onLayout ( boolean changed , int l , int t , int r , int b ) { containerSized ( new Size ( ( r - l ) , ( b - t ) ) ) ; if ( ( surfaceView ) != null ) { if ( ( surfaceRect ) == null ) { surfaceView . layout ( 0 , 0 , getWidth ( ) , getHeight ( ) ) ; } else { surfaceView . layout ( surfaceRect . left , surfaceRect . top , surfaceRect . right , surfaceRect . bottom ) ; } } else <START_BUG> if ( ( textureView ) != null ) { <END_BUG> textureView . layout ( 0 , 0 , getWidth ( ) , getHeight ( ) ) ; } } public Rect getFramingRect ( ) { } public Rect getPreviewFramingRect ( ) { } public CameraSettings getCameraSettings ( ) { } public void setCameraSettings ( CameraSettings cameraSettings ) { } public void resume ( ) { } public void pause ( ) { } public Size getFramingRectSize ( ) { } public void setFramingRectSize ( Size framingRectSize ) { } public double getMarginFraction ( ) { } public void setMarginFraction ( double marginFraction ) { } public boolean isUseTextureView ( ) { } public void setUseTextureView ( boolean useTextureView ) { } protected boolean isActive ( ) { } private int getDisplayRotation ( ) { } private void initCamera ( ) { } private void startCameraPreview ( CameraSurface surface ) { } protected void previewStarted ( ) { } public CameraInstance getCameraInstance ( ) { } public boolean isPreviewActive ( ) { } protected Rect calculateFramingRect ( Rect container , Rect surface ) { } }

Fix:
if ( ( ( textureView ) != null ) && ( ( VERSION . SDK_INT ) >= 14 ) ) {