nus-yam/ex-repair huggingface dataset:
Program: 21766
Project: 21766
Buggy source:
private Request createRequest(String requestType,SipProfile userProfile,String tag) throws ParseException, SipException {
  FromHeader fromHeader=createFromHeader(userProfile,tag);
  ToHeader toHeader=createToHeader(userProfile);
  SipURI requestURI=mAddressFactory.createSipURI("String_Node_Str" + userProfile.getSipDomain());
  List<ViaHeader> viaHeaders=createViaHeaders();
  CallIdHeader callIdHeader=createCallIdHeader();
  CSeqHeader cSeqHeader=createCSeqHeader(requestType);
  MaxForwardsHeader maxForwards=createMaxForwardsHeader();
  Request request=mMessageFactory.createRequest(requestURI,requestType,callIdHeader,cSeqHeader,fromHeader,toHeader,viaHeaders,maxForwards);
  Header userAgentHeader=mHeaderFactory.createHeader("String_Node_Str","String_Node_Str");
  request.addHeader(userAgentHeader);
  return request;
}

Fixed version (ground truth):
private Request createRequest(String requestType,SipProfile userProfile,String tag) throws ParseException, SipException {
  FromHeader fromHeader=createFromHeader(userProfile,tag);
  ToHeader toHeader=createToHeader(userProfile);
  SipURI requestURI=mAddressFactory.createSipURI(userProfile.getUriString().replaceFirst(userProfile.getUserName() + "String_Node_Str","String_Node_Str"));
  List<ViaHeader> viaHeaders=createViaHeaders();
  CallIdHeader callIdHeader=createCallIdHeader();
  CSeqHeader cSeqHeader=createCSeqHeader(requestType);
  MaxForwardsHeader maxForwards=createMaxForwardsHeader();
  Request request=mMessageFactory.createRequest(requestURI,requestType,callIdHeader,cSeqHeader,fromHeader,toHeader,viaHeaders,maxForwards);
  Header userAgentHeader=mHeaderFactory.createHeader("String_Node_Str","String_Node_Str");
  request.addHeader(userAgentHeader);
  return request;
}
Program: 21769
Project: 21769
Buggy source:
private void startTextSelectionMode(){
  if (!mIsInTextSelectionMode) {
    if (mSelectionModifierCursorController == null) {
      Log.w(LOG_TAG,"String_Node_Str");
      return;
    }
    if (!requestFocus()) {
      return;
    }
    selectCurrentWord();
    mSelectionModifierCursorController.show();
    mIsInTextSelectionMode=true;
  }
}

Fixed version (ground truth):
private void startTextSelectionMode(){
  if (!mIsInTextSelectionMode) {
    if (!hasSelectionController()) {
      Log.w(LOG_TAG,"String_Node_Str");
      return;
    }
    if (!requestFocus()) {
      return;
    }
    selectCurrentWord();
    mIsInTextSelectionMode=true;
  }
}
Program: 21770
Project: 21770
Buggy source:
public void beginBatchEdit(){
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=++ims.mBatchEditNesting;
    if (nesting == 1) {
      ims.mCursorChanged=false;
      ims.mChangedDelta=0;
      if (ims.mContentChanged) {
        ims.mChangedStart=0;
        ims.mChangedEnd=mText.length();
      }
 else {
        ims.mChangedStart=EXTRACT_UNKNOWN;
        ims.mChangedEnd=EXTRACT_UNKNOWN;
        ims.mContentChanged=false;
      }
      onBeginBatchEdit();
    }
  }
}

Fixed version (ground truth):
public void beginBatchEdit(){
  mInBatchEditControllers=true;
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=++ims.mBatchEditNesting;
    if (nesting == 1) {
      ims.mCursorChanged=false;
      ims.mChangedDelta=0;
      if (ims.mContentChanged) {
        ims.mChangedStart=0;
        ims.mChangedEnd=mText.length();
      }
 else {
        ims.mChangedStart=EXTRACT_UNKNOWN;
        ims.mChangedEnd=EXTRACT_UNKNOWN;
        ims.mContentChanged=false;
      }
      onBeginBatchEdit();
    }
  }
}
Program: 21772
Project: 21772
Buggy source:
private void onTapUpEvent(int prevStart,int prevEnd){
  final int start=getSelectionStart();
  final int end=getSelectionEnd();
  if (start == end) {
    if (start >= prevStart && start < prevEnd) {
      Selection.setSelection((Spannable)mText,prevStart,prevEnd);
      if (mSelectionModifierCursorController != null && !mSelectionModifierCursorController.isShowing()) {
        mSelectionModifierCursorController.show();
      }
 else {
        showContextMenu();
      }
      return;
    }
 else {
      stopTextSelectionMode();
      if (mInsertionPointCursorController != null && mText.length() > 0) {
        mInsertionPointCursorController.show();
      }
    }
  }
 else   if (hasSelection() && mSelectionModifierCursorController != null) {
    mSelectionModifierCursorController.show();
  }
}

Fixed version (ground truth):
private void onTapUpEvent(int prevStart,int prevEnd){
  final int start=getSelectionStart();
  final int end=getSelectionEnd();
  if (start == end) {
    if (start >= prevStart && start < prevEnd) {
      Selection.setSelection((Spannable)mText,prevStart,prevEnd);
      if (hasSelectionController() && !getSelectionController().isShowing()) {
        getSelectionController().show();
      }
 else {
        showContextMenu();
      }
      return;
    }
 else {
      stopTextSelectionMode();
      if (hasInsertionController() && mText.length() > 0) {
        getInsertionController().show();
      }
    }
  }
 else   if (hasSelection() && hasSelectionController()) {
    getSelectionController().show();
  }
}
Program: 21773
Project: 21773
Buggy source:
public void show(){
  mIsShowing=true;
  updatePosition();
  mStartHandle.show();
  mEndHandle.show();
  hideInsertionPointCursorController();
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}

Fixed version (ground truth):
public void show(){
  if (isInBatchEditMode()) {
    return;
  }
  mIsShowing=true;
  updatePosition();
  mStartHandle.show();
  mEndHandle.show();
  hideInsertionPointCursorController();
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}
Program: 21774
Project: 21774
Buggy source:
public void endBatchEdit(){
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=--ims.mBatchEditNesting;
    if (nesting == 0) {
      finishBatchEdit(ims);
    }
  }
}

Fixed version (ground truth):
public void endBatchEdit(){
  mInBatchEditControllers=false;
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=--ims.mBatchEditNesting;
    if (nesting == 0) {
      finishBatchEdit(ims);
    }
  }
}
Program: 21775
Project: 21775
Buggy source:
private void prepareCursorControllers(){
  boolean windowSupportsHandles=false;
  ViewGroup.LayoutParams params=getRootView().getLayoutParams();
  if (params instanceof WindowManager.LayoutParams) {
    WindowManager.LayoutParams windowParams=(WindowManager.LayoutParams)params;
    windowSupportsHandles=windowParams.type < WindowManager.LayoutParams.FIRST_SUB_WINDOW || windowParams.type > WindowManager.LayoutParams.LAST_SUB_WINDOW;
  }
  if (windowSupportsHandles && mCursorVisible && mLayout != null) {
    if (mInsertionPointCursorController == null) {
      mInsertionPointCursorController=new InsertionPointCursorController();
    }
  }
 else {
    mInsertionPointCursorController=null;
  }
  if (windowSupportsHandles && textCanBeSelected() && mLayout != null) {
    if (mSelectionModifierCursorController == null) {
      mSelectionModifierCursorController=new SelectionModifierCursorController();
    }
  }
 else {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}

Fixed version (ground truth):
private void prepareCursorControllers(){
  boolean windowSupportsHandles=false;
  ViewGroup.LayoutParams params=getRootView().getLayoutParams();
  if (params instanceof WindowManager.LayoutParams) {
    WindowManager.LayoutParams windowParams=(WindowManager.LayoutParams)params;
    windowSupportsHandles=windowParams.type < WindowManager.LayoutParams.FIRST_SUB_WINDOW || windowParams.type > WindowManager.LayoutParams.LAST_SUB_WINDOW;
  }
  mInsertionControllerEnabled=windowSupportsHandles && mCursorVisible && mLayout != null;
  mSelectionControllerEnabled=windowSupportsHandles && textCanBeSelected() && mLayout != null;
  if (!mInsertionControllerEnabled) {
    mInsertionPointCursorController=null;
  }
  if (!mSelectionControllerEnabled) {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}
Program: 21776
Project: 21776
Buggy source:
/** 
 * {@inheritDoc}
 */
public boolean onPreDraw(){
  if (mPreDrawState != PREDRAW_PENDING) {
    return true;
  }
  if (mLayout == null) {
    assumeLayout();
  }
  boolean changed=false;
  SelectionModifierCursorController selectionController=null;
  if (mSelectionModifierCursorController != null) {
    selectionController=(SelectionModifierCursorController)mSelectionModifierCursorController;
  }
  if (mMovement != null) {
    int curs=getSelectionEnd();
    if (selectionController != null && selectionController.isSelectionStartDragged()) {
      curs=getSelectionStart();
    }
    if (curs < 0 && (mGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
      curs=mText.length();
    }
    if (curs >= 0) {
      changed=bringPointIntoView(curs);
    }
  }
 else {
    changed=bringTextIntoView();
  }
  if (selectionController != null && hasSelection()) {
    startTextSelectionMode();
  }
  mPreDrawState=PREDRAW_DONE;
  return !changed;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
public boolean onPreDraw(){
  if (mPreDrawState != PREDRAW_PENDING) {
    return true;
  }
  if (mLayout == null) {
    assumeLayout();
  }
  boolean changed=false;
  SelectionModifierCursorController selectionController=null;
  if (mSelectionModifierCursorController != null) {
    selectionController=(SelectionModifierCursorController)mSelectionModifierCursorController;
  }
  if (mMovement != null) {
    int curs=getSelectionEnd();
    if (selectionController != null && selectionController.isSelectionStartDragged()) {
      curs=getSelectionStart();
    }
    if (curs < 0 && (mGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
      curs=mText.length();
    }
    if (curs >= 0) {
      changed=bringPointIntoView(curs);
    }
  }
 else {
    changed=bringTextIntoView();
  }
  if (this instanceof ExtractEditText && selectionController != null && hasSelection()) {
    startTextSelectionMode();
  }
  mPreDrawState=PREDRAW_DONE;
  return !changed;
}
Program: 21777
Project: 21777
Buggy source:
public void updatePosition(){
  final int selectionStart=getSelectionStart();
  final int selectionEnd=getSelectionEnd();
  if ((selectionStart < 0) || (selectionEnd < 0)) {
    Log.w(LOG_TAG,"String_Node_Str");
    hide();
    return;
  }
  mStartHandle.positionAtCursor(selectionStart,true);
  mEndHandle.positionAtCursor(selectionEnd,true);
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}

Fixed version (ground truth):
public void updatePosition(){
  if (!isShowing()) {
    return;
  }
  final int selectionStart=getSelectionStart();
  final int selectionEnd=getSelectionEnd();
  if ((selectionStart < 0) || (selectionEnd < 0)) {
    Log.w(LOG_TAG,"String_Node_Str");
    hide();
    return;
  }
  mStartHandle.positionAtCursor(selectionStart,true);
  mEndHandle.positionAtCursor(selectionEnd,true);
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}
Program: 21778
Project: 21778
Buggy source:
private boolean isPositionVisible(){
  if (mIsDragging) {
    return true;
  }
  final int extendedPaddingTop=getExtendedPaddingTop();
  final int extendedPaddingBottom=getExtendedPaddingBottom();
  final int compoundPaddingLeft=getCompoundPaddingLeft();
  final int compoundPaddingRight=getCompoundPaddingRight();
  final TextView hostView=TextView.this;
  final int left=0;
  final int right=hostView.getWidth();
  final int top=0;
  final int bottom=hostView.getHeight();
  if (mTempRect == null) {
    mTempRect=new Rect();
  }
  final Rect clip=mTempRect;
  clip.left=left + compoundPaddingLeft;
  clip.top=top + extendedPaddingTop;
  clip.right=right - compoundPaddingRight;
  clip.bottom=bottom - extendedPaddingBottom;
  final ViewParent parent=hostView.getParent();
  if (parent == null || !parent.getChildVisibleRect(hostView,clip,null)) {
    return false;
  }
  final int[] coords=mTempCoords;
  hostView.getLocationInWindow(coords);
  final int posX=coords[0] + mPositionX + (int)mHotspotX;
  final int posY=coords[1] + mPositionY + (int)mHotspotY;
  return posX >= clip.left && posX <= clip.right && posY >= clip.top && posY <= clip.bottom;
}

Fixed version (ground truth):
private boolean isPositionVisible(){
  if (mIsDragging) {
    return true;
  }
  if (isInBatchEditMode()) {
    return false;
  }
  final int extendedPaddingTop=getExtendedPaddingTop();
  final int extendedPaddingBottom=getExtendedPaddingBottom();
  final int compoundPaddingLeft=getCompoundPaddingLeft();
  final int compoundPaddingRight=getCompoundPaddingRight();
  final TextView hostView=TextView.this;
  final int left=0;
  final int right=hostView.getWidth();
  final int top=0;
  final int bottom=hostView.getHeight();
  if (mTempRect == null) {
    mTempRect=new Rect();
  }
  final Rect clip=mTempRect;
  clip.left=left + compoundPaddingLeft;
  clip.top=top + extendedPaddingTop;
  clip.right=right - compoundPaddingRight;
  clip.bottom=bottom - extendedPaddingBottom;
  final ViewParent parent=hostView.getParent();
  if (parent == null || !parent.getChildVisibleRect(hostView,clip,null)) {
    return false;
  }
  final int[] coords=mTempCoords;
  hostView.getLocationInWindow(coords);
  final int posX=coords[0] + mPositionX + (int)mHotspotX;
  final int posY=coords[1] + mPositionY + (int)mHotspotY;
  return posX >= clip.left && posX <= clip.right && posY >= clip.top && posY <= clip.bottom;
}
Program: 21779
Project: 21779
Buggy source:
private void startTextSelectionMode(){
  if (!mIsInTextSelectionMode) {
    if (mSelectionModifierCursorController == null) {
      Log.w(LOG_TAG,"String_Node_Str");
      return;
    }
    if (!requestFocus()) {
      return;
    }
    selectCurrentWord();
    mSelectionModifierCursorController.show();
    mIsInTextSelectionMode=true;
  }
}

Fixed version (ground truth):
private void startTextSelectionMode(){
  if (!mIsInTextSelectionMode) {
    if (!hasSelectionController()) {
      Log.w(LOG_TAG,"String_Node_Str");
      return;
    }
    if (!requestFocus()) {
      return;
    }
    selectCurrentWord();
    mIsInTextSelectionMode=true;
  }
}
Program: 21780
Project: 21780
Buggy source:
public void beginBatchEdit(){
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=++ims.mBatchEditNesting;
    if (nesting == 1) {
      ims.mCursorChanged=false;
      ims.mChangedDelta=0;
      if (ims.mContentChanged) {
        ims.mChangedStart=0;
        ims.mChangedEnd=mText.length();
      }
 else {
        ims.mChangedStart=EXTRACT_UNKNOWN;
        ims.mChangedEnd=EXTRACT_UNKNOWN;
        ims.mContentChanged=false;
      }
      onBeginBatchEdit();
    }
  }
}

Fixed version (ground truth):
public void beginBatchEdit(){
  mInBatchEditControllers=true;
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=++ims.mBatchEditNesting;
    if (nesting == 1) {
      ims.mCursorChanged=false;
      ims.mChangedDelta=0;
      if (ims.mContentChanged) {
        ims.mChangedStart=0;
        ims.mChangedEnd=mText.length();
      }
 else {
        ims.mChangedStart=EXTRACT_UNKNOWN;
        ims.mChangedEnd=EXTRACT_UNKNOWN;
        ims.mContentChanged=false;
      }
      onBeginBatchEdit();
    }
  }
}
Program: 21782
Project: 21782
Buggy source:
private void onTapUpEvent(int prevStart,int prevEnd){
  final int start=getSelectionStart();
  final int end=getSelectionEnd();
  if (start == end) {
    if (start >= prevStart && start < prevEnd) {
      Selection.setSelection((Spannable)mText,prevStart,prevEnd);
      if (mSelectionModifierCursorController != null && !mSelectionModifierCursorController.isShowing()) {
        mSelectionModifierCursorController.show();
      }
 else {
        showContextMenu();
      }
      return;
    }
 else {
      stopTextSelectionMode();
      if (mInsertionPointCursorController != null && mText.length() > 0) {
        mInsertionPointCursorController.show();
      }
    }
  }
 else   if (hasSelection() && mSelectionModifierCursorController != null) {
    mSelectionModifierCursorController.show();
  }
}

Fixed version (ground truth):
private void onTapUpEvent(int prevStart,int prevEnd){
  final int start=getSelectionStart();
  final int end=getSelectionEnd();
  if (start == end) {
    if (start >= prevStart && start < prevEnd) {
      Selection.setSelection((Spannable)mText,prevStart,prevEnd);
      if (hasSelectionController() && !getSelectionController().isShowing()) {
        getSelectionController().show();
      }
 else {
        showContextMenu();
      }
      return;
    }
 else {
      stopTextSelectionMode();
      if (hasInsertionController() && mText.length() > 0) {
        getInsertionController().show();
      }
    }
  }
 else   if (hasSelection() && hasSelectionController()) {
    getSelectionController().show();
  }
}
Program: 21783
Project: 21783
Buggy source:
public void show(){
  mIsShowing=true;
  updatePosition();
  mStartHandle.show();
  mEndHandle.show();
  hideInsertionPointCursorController();
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}

Fixed version (ground truth):
public void show(){
  if (isInBatchEditMode()) {
    return;
  }
  mIsShowing=true;
  updatePosition();
  mStartHandle.show();
  mEndHandle.show();
  hideInsertionPointCursorController();
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}
Program: 21784
Project: 21784
Buggy source:
public void endBatchEdit(){
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=--ims.mBatchEditNesting;
    if (nesting == 0) {
      finishBatchEdit(ims);
    }
  }
}

Fixed version (ground truth):
public void endBatchEdit(){
  mInBatchEditControllers=false;
  final InputMethodState ims=mInputMethodState;
  if (ims != null) {
    int nesting=--ims.mBatchEditNesting;
    if (nesting == 0) {
      finishBatchEdit(ims);
    }
  }
}
Program: 21785
Project: 21785
Buggy source:
private void prepareCursorControllers(){
  boolean windowSupportsHandles=false;
  ViewGroup.LayoutParams params=getRootView().getLayoutParams();
  if (params instanceof WindowManager.LayoutParams) {
    WindowManager.LayoutParams windowParams=(WindowManager.LayoutParams)params;
    windowSupportsHandles=windowParams.type < WindowManager.LayoutParams.FIRST_SUB_WINDOW || windowParams.type > WindowManager.LayoutParams.LAST_SUB_WINDOW;
  }
  if (windowSupportsHandles && mCursorVisible && mLayout != null) {
    if (mInsertionPointCursorController == null) {
      mInsertionPointCursorController=new InsertionPointCursorController();
    }
  }
 else {
    mInsertionPointCursorController=null;
  }
  if (windowSupportsHandles && textCanBeSelected() && mLayout != null) {
    if (mSelectionModifierCursorController == null) {
      mSelectionModifierCursorController=new SelectionModifierCursorController();
    }
  }
 else {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}

Fixed version (ground truth):
private void prepareCursorControllers(){
  boolean windowSupportsHandles=false;
  ViewGroup.LayoutParams params=getRootView().getLayoutParams();
  if (params instanceof WindowManager.LayoutParams) {
    WindowManager.LayoutParams windowParams=(WindowManager.LayoutParams)params;
    windowSupportsHandles=windowParams.type < WindowManager.LayoutParams.FIRST_SUB_WINDOW || windowParams.type > WindowManager.LayoutParams.LAST_SUB_WINDOW;
  }
  mInsertionControllerEnabled=windowSupportsHandles && mCursorVisible && mLayout != null;
  mSelectionControllerEnabled=windowSupportsHandles && textCanBeSelected() && mLayout != null;
  if (!mInsertionControllerEnabled) {
    mInsertionPointCursorController=null;
  }
  if (!mSelectionControllerEnabled) {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}
Program: 21786
Project: 21786
Buggy source:
/** 
 * {@inheritDoc}
 */
public boolean onPreDraw(){
  if (mPreDrawState != PREDRAW_PENDING) {
    return true;
  }
  if (mLayout == null) {
    assumeLayout();
  }
  boolean changed=false;
  SelectionModifierCursorController selectionController=null;
  if (mSelectionModifierCursorController != null) {
    selectionController=(SelectionModifierCursorController)mSelectionModifierCursorController;
  }
  if (mMovement != null) {
    int curs=getSelectionEnd();
    if (selectionController != null && selectionController.isSelectionStartDragged()) {
      curs=getSelectionStart();
    }
    if (curs < 0 && (mGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
      curs=mText.length();
    }
    if (curs >= 0) {
      changed=bringPointIntoView(curs);
    }
  }
 else {
    changed=bringTextIntoView();
  }
  if (selectionController != null && hasSelection()) {
    startTextSelectionMode();
  }
  mPreDrawState=PREDRAW_DONE;
  return !changed;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
public boolean onPreDraw(){
  if (mPreDrawState != PREDRAW_PENDING) {
    return true;
  }
  if (mLayout == null) {
    assumeLayout();
  }
  boolean changed=false;
  SelectionModifierCursorController selectionController=null;
  if (mSelectionModifierCursorController != null) {
    selectionController=(SelectionModifierCursorController)mSelectionModifierCursorController;
  }
  if (mMovement != null) {
    int curs=getSelectionEnd();
    if (selectionController != null && selectionController.isSelectionStartDragged()) {
      curs=getSelectionStart();
    }
    if (curs < 0 && (mGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
      curs=mText.length();
    }
    if (curs >= 0) {
      changed=bringPointIntoView(curs);
    }
  }
 else {
    changed=bringTextIntoView();
  }
  if (this instanceof ExtractEditText && selectionController != null && hasSelection()) {
    startTextSelectionMode();
  }
  mPreDrawState=PREDRAW_DONE;
  return !changed;
}
Program: 21787
Project: 21787
Buggy source:
public void updatePosition(){
  final int selectionStart=getSelectionStart();
  final int selectionEnd=getSelectionEnd();
  if ((selectionStart < 0) || (selectionEnd < 0)) {
    Log.w(LOG_TAG,"String_Node_Str");
    hide();
    return;
  }
  mStartHandle.positionAtCursor(selectionStart,true);
  mEndHandle.positionAtCursor(selectionEnd,true);
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}

Fixed version (ground truth):
public void updatePosition(){
  if (!isShowing()) {
    return;
  }
  final int selectionStart=getSelectionStart();
  final int selectionEnd=getSelectionEnd();
  if ((selectionStart < 0) || (selectionEnd < 0)) {
    Log.w(LOG_TAG,"String_Node_Str");
    hide();
    return;
  }
  mStartHandle.positionAtCursor(selectionStart,true);
  mEndHandle.positionAtCursor(selectionEnd,true);
  hideDelayed(DELAY_BEFORE_FADE_OUT);
}
Program: 21788
Project: 21788
Buggy source:
private boolean isPositionVisible(){
  if (mIsDragging) {
    return true;
  }
  final int extendedPaddingTop=getExtendedPaddingTop();
  final int extendedPaddingBottom=getExtendedPaddingBottom();
  final int compoundPaddingLeft=getCompoundPaddingLeft();
  final int compoundPaddingRight=getCompoundPaddingRight();
  final TextView hostView=TextView.this;
  final int left=0;
  final int right=hostView.getWidth();
  final int top=0;
  final int bottom=hostView.getHeight();
  if (mTempRect == null) {
    mTempRect=new Rect();
  }
  final Rect clip=mTempRect;
  clip.left=left + compoundPaddingLeft;
  clip.top=top + extendedPaddingTop;
  clip.right=right - compoundPaddingRight;
  clip.bottom=bottom - extendedPaddingBottom;
  final ViewParent parent=hostView.getParent();
  if (parent == null || !parent.getChildVisibleRect(hostView,clip,null)) {
    return false;
  }
  final int[] coords=mTempCoords;
  hostView.getLocationInWindow(coords);
  final int posX=coords[0] + mPositionX + (int)mHotspotX;
  final int posY=coords[1] + mPositionY + (int)mHotspotY;
  return posX >= clip.left && posX <= clip.right && posY >= clip.top && posY <= clip.bottom;
}

Fixed version (ground truth):
private boolean isPositionVisible(){
  if (mIsDragging) {
    return true;
  }
  if (isInBatchEditMode()) {
    return false;
  }
  final int extendedPaddingTop=getExtendedPaddingTop();
  final int extendedPaddingBottom=getExtendedPaddingBottom();
  final int compoundPaddingLeft=getCompoundPaddingLeft();
  final int compoundPaddingRight=getCompoundPaddingRight();
  final TextView hostView=TextView.this;
  final int left=0;
  final int right=hostView.getWidth();
  final int top=0;
  final int bottom=hostView.getHeight();
  if (mTempRect == null) {
    mTempRect=new Rect();
  }
  final Rect clip=mTempRect;
  clip.left=left + compoundPaddingLeft;
  clip.top=top + extendedPaddingTop;
  clip.right=right - compoundPaddingRight;
  clip.bottom=bottom - extendedPaddingBottom;
  final ViewParent parent=hostView.getParent();
  if (parent == null || !parent.getChildVisibleRect(hostView,clip,null)) {
    return false;
  }
  final int[] coords=mTempCoords;
  hostView.getLocationInWindow(coords);
  final int posX=coords[0] + mPositionX + (int)mHotspotX;
  final int posY=coords[1] + mPositionY + (int)mHotspotY;
  return posX >= clip.left && posX <= clip.right && posY >= clip.top && posY <= clip.bottom;
}
Program: 21791
Project: 21791
Buggy source:
/** 
 * Called when the application is stopping.  There are no more application objects running and the process will exit.  <em>Note: never depend on this method being called; in many cases an unneeded application process will simply be killed by the kernel without executing any application code.</em> If you override this method, be sure to call super.onTerminate().
 */
public void onTerminate(){
}

Fixed version (ground truth):
/** 
 * This method is for use in emulated process environments.  It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.
 */
public void onTerminate(){
}
Program: 21792
Project: 21792
Buggy source:
/** 
 * Called when the application is stopping.  There are no more application objects running and the process will exit.  <em>Note: never depend on this method being called; in many cases an unneeded application process will simply be killed by the kernel without executing any application code.</em> If you override this method, be sure to call super.onTerminate().
 */
public void onTerminate(){
}

Fixed version (ground truth):
/** 
 * This method is for use in emulated process environments.  It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.
 */
public void onTerminate(){
}
Program: 21793
Project: 21793
Buggy source:
public void setAudioMode(){
  Context context=getContext();
  if (context == null)   return;
  AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  int mode=AudioManager.MODE_NORMAL;
switch (getState()) {
case RINGING:
    mode=AudioManager.MODE_RINGTONE;
  break;
case OFFHOOK:
Phone fgPhone=getFgPhone();
if (!(fgPhone instanceof SipPhone)) {
mode=AudioManager.MODE_IN_CALL;
}
break;
}
if (audioManager.getMode() != mode) audioManager.setMode(mode);
}

Fixed version (ground truth):
public void setAudioMode(){
  Context context=getContext();
  if (context == null)   return;
  AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  int mode=AudioManager.MODE_NORMAL;
switch (getState()) {
case RINGING:
    mode=AudioManager.MODE_RINGTONE;
  break;
case OFFHOOK:
Phone fgPhone=getFgPhone();
if (hasActiveFgCall() && !(fgPhone instanceof SipPhone)) {
mode=AudioManager.MODE_IN_CALL;
}
break;
}
if (audioManager.getMode() != mode) audioManager.setMode(mode);
}
Program: 21794
Project: 21794
Buggy source:
/** 
 * Resolves the value of a resource, if the value references a theme or resource value. <p/> This method ensures that it returns a   {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return a new instance of IResourceValue that contains the input value.
 * @param type the type of the resource
 * @param name the name of the attribute containing this value.
 * @param value the resource value, or reference to resolve
 * @return the resolved resource value or <code>null</code> if it failed to resolve it.
 */
private IResourceValue resolveValue(String type,String name,String value){
  if (value == null) {
    return null;
  }
  IResourceValue resValue=findResValue(value);
  if (resValue == null) {
    return new ResourceValue(type,name,value);
  }
  return resolveResValue(resValue);
}

Fixed version (ground truth):
/** 
 * Resolves the value of a resource, if the value references a theme or resource value. <p/> This method ensures that it returns a   {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return a new instance of IResourceValue that contains the input value.
 * @param type the type of the resource
 * @param name the name of the attribute containing this value.
 * @param value the resource value, or reference to resolve
 * @return the resolved resource value or <code>null</code> if it failed to resolve it.
 */
private IResourceValue resolveValue(String type,String name,String value){
  if (value == null) {
    return null;
  }
  IResourceValue resValue=findResValue(value,false);
  if (resValue == null) {
    return new ResourceValue(type,name,value);
  }
  return resolveResValue(resValue);
}
Program: 21796
Project: 21796
Buggy source:
/** 
 * Returns the   {@link IResourceValue} referenced by the value of <var>value</var>.<p/> This method ensures that it returns a  {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return the input value.
 * @param value the value containing the reference to resolve.
 * @return a {@link IResourceValue} object or <code>null</code>
 */
IResourceValue resolveResValue(IResourceValue value){
  if (value == null) {
    return null;
  }
  if (value instanceof IStyleResourceValue) {
    return value;
  }
  IResourceValue resolvedValue=findResValue(value.getValue());
  if (resolvedValue == null) {
    return value;
  }
  return resolveResValue(resolvedValue);
}

Fixed version (ground truth):
/** 
 * Returns the   {@link IResourceValue} referenced by the value of <var>value</var>.<p/> This method ensures that it returns a  {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return the input value.
 * @param value the value containing the reference to resolve.
 * @return a {@link IResourceValue} object or <code>null</code>
 */
IResourceValue resolveResValue(IResourceValue value){
  if (value == null) {
    return null;
  }
  if (value instanceof IStyleResourceValue) {
    return value;
  }
  IResourceValue resolvedValue=findResValue(value.getValue(),value.isFramework());
  if (resolvedValue == null) {
    return value;
  }
  return resolveResValue(resolvedValue);
}
Program: 21797
Project: 21797
Buggy source:
private int resolveResourceValue(String value,int defaultValue){
  IResourceValue resource=mContext.resolveResValue(mContext.findResValue(value));
  if (resource != null) {
    Integer id=null;
    if (mPlatformFile || resource.isFramework()) {
      id=Bridge.getResourceValue(resource.getType(),resource.getName());
    }
 else {
      id=mContext.getProjectCallback().getResourceValue(resource.getType(),resource.getName());
    }
    if (id != null) {
      return id;
    }
  }
  return defaultValue;
}

Fixed version (ground truth):
private int resolveResourceValue(String value,int defaultValue){
  IResourceValue resource=mContext.resolveResValue(mContext.findResValue(value,mPlatformFile));
  if (resource != null) {
    Integer id=null;
    if (mPlatformFile || resource.isFramework()) {
      id=Bridge.getResourceValue(resource.getType(),resource.getName());
    }
 else {
      id=mContext.getProjectCallback().getResourceValue(resource.getType(),resource.getName());
    }
    if (id != null) {
      return id;
    }
  }
  return defaultValue;
}
Program: 21799
Project: 21799
Buggy source:
/** 
 * Resolves the value of a resource, if the value references a theme or resource value. <p/> This method ensures that it returns a   {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return a new instance of IResourceValue that contains the input value.
 * @param type the type of the resource
 * @param name the name of the attribute containing this value.
 * @param value the resource value, or reference to resolve
 * @return the resolved resource value or <code>null</code> if it failed to resolve it.
 */
private IResourceValue resolveValue(String type,String name,String value){
  if (value == null) {
    return null;
  }
  IResourceValue resValue=findResValue(value);
  if (resValue == null) {
    return new ResourceValue(type,name,value);
  }
  return resolveResValue(resValue);
}

Fixed version (ground truth):
/** 
 * Resolves the value of a resource, if the value references a theme or resource value. <p/> This method ensures that it returns a   {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return a new instance of IResourceValue that contains the input value.
 * @param type the type of the resource
 * @param name the name of the attribute containing this value.
 * @param value the resource value, or reference to resolve
 * @return the resolved resource value or <code>null</code> if it failed to resolve it.
 */
private IResourceValue resolveValue(String type,String name,String value){
  if (value == null) {
    return null;
  }
  IResourceValue resValue=findResValue(value,false);
  if (resValue == null) {
    return new ResourceValue(type,name,value);
  }
  return resolveResValue(resValue);
}
Program: 21801
Project: 21801
Buggy source:
/** 
 * Returns the   {@link IResourceValue} referenced by the value of <var>value</var>.<p/> This method ensures that it returns a  {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return the input value.
 * @param value the value containing the reference to resolve.
 * @return a {@link IResourceValue} object or <code>null</code>
 */
IResourceValue resolveResValue(IResourceValue value){
  if (value == null) {
    return null;
  }
  if (value instanceof IStyleResourceValue) {
    return value;
  }
  IResourceValue resolvedValue=findResValue(value.getValue());
  if (resolvedValue == null) {
    return value;
  }
  return resolveResValue(resolvedValue);
}

Fixed version (ground truth):
/** 
 * Returns the   {@link IResourceValue} referenced by the value of <var>value</var>.<p/> This method ensures that it returns a  {@link IResourceValue} object that does notreference another resource. If the resource cannot be resolved, it returns <code>null</code>. <p/> If a value that does not need to be resolved is given, the method will return the input value.
 * @param value the value containing the reference to resolve.
 * @return a {@link IResourceValue} object or <code>null</code>
 */
IResourceValue resolveResValue(IResourceValue value){
  if (value == null) {
    return null;
  }
  if (value instanceof IStyleResourceValue) {
    return value;
  }
  IResourceValue resolvedValue=findResValue(value.getValue(),value.isFramework());
  if (resolvedValue == null) {
    return value;
  }
  return resolveResValue(resolvedValue);
}
Program: 21802
Project: 21802
Buggy source:
private int resolveResourceValue(String value,int defaultValue){
  IResourceValue resource=mContext.resolveResValue(mContext.findResValue(value));
  if (resource != null) {
    Integer id=null;
    if (mPlatformFile || resource.isFramework()) {
      id=Bridge.getResourceValue(resource.getType(),resource.getName());
    }
 else {
      id=mContext.getProjectCallback().getResourceValue(resource.getType(),resource.getName());
    }
    if (id != null) {
      return id;
    }
  }
  return defaultValue;
}

Fixed version (ground truth):
private int resolveResourceValue(String value,int defaultValue){
  IResourceValue resource=mContext.resolveResValue(mContext.findResValue(value,mPlatformFile));
  if (resource != null) {
    Integer id=null;
    if (mPlatformFile || resource.isFramework()) {
      id=Bridge.getResourceValue(resource.getType(),resource.getName());
    }
 else {
      id=mContext.getProjectCallback().getResourceValue(resource.getType(),resource.getName());
    }
    if (id != null) {
      return id;
    }
  }
  return defaultValue;
}
Program: 21805
Project: 21805
Buggy source:
private final void handlePauseActivity(IBinder token,boolean finished,boolean userLeaving,int configChanges){
  ActivityClientRecord r=mActivities.get(token);
  if (r != null) {
    if (userLeaving) {
      performUserLeavingActivity(r);
    }
    r.activity.mConfigChangeFlags|=configChanges;
    Bundle state=performPauseActivity(token,finished,true);
    try {
      ActivityManagerNative.getDefault().activityPaused(token,state);
    }
 catch (    RemoteException ex) {
    }
  }
}

Fixed version (ground truth):
private final void handlePauseActivity(IBinder token,boolean finished,boolean userLeaving,int configChanges){
  ActivityClientRecord r=mActivities.get(token);
  if (r != null) {
    if (userLeaving) {
      performUserLeavingActivity(r);
    }
    r.activity.mConfigChangeFlags|=configChanges;
    Bundle state=performPauseActivity(token,finished,true);
    QueuedWork.waitToFinish();
    try {
      ActivityManagerNative.getDefault().activityPaused(token,state);
    }
 catch (    RemoteException ex) {
    }
  }
}
Program: 21806
Project: 21806
Buggy source:
public void setAudioMode(){
  Context context=getContext();
  if (context == null)   return;
  AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  int mode=AudioManager.MODE_NORMAL;
switch (getState()) {
case RINGING:
    mode=AudioManager.MODE_RINGTONE;
  break;
case OFFHOOK:
Phone fgPhone=getFgPhone();
if (!(fgPhone instanceof SipPhone)) {
mode=AudioManager.MODE_IN_CALL;
}
break;
}
if (audioManager.getMode() != mode) audioManager.setMode(mode);
}

Fixed version (ground truth):
public void setAudioMode(){
  Context context=getContext();
  if (context == null)   return;
  AudioManager audioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
  int mode=AudioManager.MODE_NORMAL;
switch (getState()) {
case RINGING:
    mode=AudioManager.MODE_RINGTONE;
  break;
case OFFHOOK:
Phone fgPhone=getFgPhone();
if (hasActiveFgCall() && !(fgPhone instanceof SipPhone)) {
mode=AudioManager.MODE_IN_CALL;
}
break;
}
if (audioManager.getMode() != mode) audioManager.setMode(mode);
}
Program: 21808
Project: 21808
Buggy source:
/** 
 * {@inheritDoc}
 */
public void onClick(DialogInterface dialog,int which){
  if (which == POSITIVE_BUTTON) {
    IMountService mountService=IMountService.Stub.asInterface(ServiceManager.getService("String_Node_Str"));
    if (mountService != null) {
      try {
        mountService.formatVolume(Environment.getExternalStorageDirectory().toString());
      }
 catch (      RemoteException e) {
      }
    }
  }
  finish();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
public void onClick(DialogInterface dialog,int which){
  if (which == POSITIVE_BUTTON) {
    Intent intent=new Intent(ExternalStorageFormatter.FORMAT_ONLY);
    intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
    startService(intent);
  }
  finish();
}
Program: 21809
Project: 21809
Buggy source:
/** 
 * {@inheritDoc}
 */
public void onClick(DialogInterface dialog,int which){
  if (which == POSITIVE_BUTTON) {
    IMountService mountService=IMountService.Stub.asInterface(ServiceManager.getService("String_Node_Str"));
    if (mountService != null) {
      try {
        mountService.formatVolume(Environment.getExternalStorageDirectory().toString());
      }
 catch (      RemoteException e) {
      }
    }
  }
  finish();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
public void onClick(DialogInterface dialog,int which){
  if (which == POSITIVE_BUTTON) {
    Intent intent=new Intent(ExternalStorageFormatter.FORMAT_ONLY);
    intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
    startService(intent);
  }
  finish();
}
Program: 21816
Project: 21816
Buggy source:
private void doDrag(int deltaX,int deltaY){
  if ((deltaX | deltaY) != 0) {
    final int oldX=mScrollX;
    final int oldY=mScrollY;
    final int rangeX=computeMaxScrollX();
    final int rangeY=computeMaxScrollY();
    if (mEdgeGlowTop != null) {
      mOverscrollDeltaX=deltaX;
      mOverscrollDeltaY=deltaY;
    }
    overScrollBy(deltaX,deltaY,oldX,oldY,rangeX,rangeY,mOverscrollDistance,mOverscrollDistance,true);
  }
  if (!getSettings().getBuiltInZoomControls()) {
    boolean showPlusMinus=mMinZoomScale < mMaxZoomScale;
    if (mZoomControls != null && showPlusMinus) {
      if (mZoomControls.getVisibility() == View.VISIBLE) {
        mPrivateHandler.removeCallbacks(mZoomControlRunnable);
      }
 else {
        mZoomControls.show(showPlusMinus,false);
      }
      mPrivateHandler.postDelayed(mZoomControlRunnable,ZOOM_CONTROLS_TIMEOUT);
    }
  }
}

Fixed version (ground truth):
private void doDrag(int deltaX,int deltaY){
  if ((deltaX | deltaY) != 0) {
    final int oldX=mScrollX;
    final int oldY=mScrollY;
    final int rangeX=computeMaxScrollX();
    final int rangeY=computeMaxScrollY();
    if (mEdgeGlowTop != null) {
      mOverscrollDeltaX=deltaX;
      mOverscrollDeltaY=deltaY;
    }
    overScrollBy(deltaX,deltaY,oldX,oldY,rangeX,rangeY,mOverscrollDistance,mOverscrollDistance,true);
    if (mEdgeGlowTop != null && (!mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished() || !mEdgeGlowLeft.isFinished()|| !mEdgeGlowRight.isFinished())) {
      invalidate();
    }
  }
  if (!getSettings().getBuiltInZoomControls()) {
    boolean showPlusMinus=mMinZoomScale < mMaxZoomScale;
    if (mZoomControls != null && showPlusMinus) {
      if (mZoomControls.getVisibility() == View.VISIBLE) {
        mPrivateHandler.removeCallbacks(mZoomControlRunnable);
      }
 else {
        mZoomControls.show(showPlusMinus,false);
      }
      mPrivateHandler.postDelayed(mZoomControlRunnable,ZOOM_CONTROLS_TIMEOUT);
    }
  }
}
Program: 21817
Project: 21817
Buggy source:
private void doDrag(int deltaX,int deltaY){
  if ((deltaX | deltaY) != 0) {
    final int oldX=mScrollX;
    final int oldY=mScrollY;
    final int rangeX=computeMaxScrollX();
    final int rangeY=computeMaxScrollY();
    if (mEdgeGlowTop != null) {
      mOverscrollDeltaX=deltaX;
      mOverscrollDeltaY=deltaY;
    }
    overScrollBy(deltaX,deltaY,oldX,oldY,rangeX,rangeY,mOverscrollDistance,mOverscrollDistance,true);
  }
  if (!getSettings().getBuiltInZoomControls()) {
    boolean showPlusMinus=mMinZoomScale < mMaxZoomScale;
    if (mZoomControls != null && showPlusMinus) {
      if (mZoomControls.getVisibility() == View.VISIBLE) {
        mPrivateHandler.removeCallbacks(mZoomControlRunnable);
      }
 else {
        mZoomControls.show(showPlusMinus,false);
      }
      mPrivateHandler.postDelayed(mZoomControlRunnable,ZOOM_CONTROLS_TIMEOUT);
    }
  }
}

Fixed version (ground truth):
private void doDrag(int deltaX,int deltaY){
  if ((deltaX | deltaY) != 0) {
    final int oldX=mScrollX;
    final int oldY=mScrollY;
    final int rangeX=computeMaxScrollX();
    final int rangeY=computeMaxScrollY();
    if (mEdgeGlowTop != null) {
      mOverscrollDeltaX=deltaX;
      mOverscrollDeltaY=deltaY;
    }
    overScrollBy(deltaX,deltaY,oldX,oldY,rangeX,rangeY,mOverscrollDistance,mOverscrollDistance,true);
    if (mEdgeGlowTop != null && (!mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished() || !mEdgeGlowLeft.isFinished()|| !mEdgeGlowRight.isFinished())) {
      invalidate();
    }
  }
  if (!getSettings().getBuiltInZoomControls()) {
    boolean showPlusMinus=mMinZoomScale < mMaxZoomScale;
    if (mZoomControls != null && showPlusMinus) {
      if (mZoomControls.getVisibility() == View.VISIBLE) {
        mPrivateHandler.removeCallbacks(mZoomControlRunnable);
      }
 else {
        mZoomControls.show(showPlusMinus,false);
      }
      mPrivateHandler.postDelayed(mZoomControlRunnable,ZOOM_CONTROLS_TIMEOUT);
    }
  }
}
Program: 21819
Project: 21819
Buggy source:
private void prepareCursorControllers(){
  if (mCursorVisible && mLayout != null) {
    if (mInsertionPointCursorController == null) {
      mInsertionPointCursorController=new InsertionPointCursorController();
    }
  }
 else {
    mInsertionPointCursorController=null;
  }
  if (textCanBeSelected() && mLayout != null) {
    if (mSelectionModifierCursorController == null) {
      mSelectionModifierCursorController=new SelectionModifierCursorController();
    }
  }
 else {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}

Fixed version (ground truth):
private void prepareCursorControllers(){
  boolean windowSupportsHandles=false;
  ViewGroup.LayoutParams params=getRootView().getLayoutParams();
  if (params instanceof WindowManager.LayoutParams) {
    WindowManager.LayoutParams windowParams=(WindowManager.LayoutParams)params;
    windowSupportsHandles=windowParams.type < WindowManager.LayoutParams.FIRST_SUB_WINDOW || windowParams.type > WindowManager.LayoutParams.LAST_SUB_WINDOW;
  }
  if (windowSupportsHandles && mCursorVisible && mLayout != null) {
    if (mInsertionPointCursorController == null) {
      mInsertionPointCursorController=new InsertionPointCursorController();
    }
  }
 else {
    mInsertionPointCursorController=null;
  }
  if (windowSupportsHandles && textCanBeSelected() && mLayout != null) {
    if (mSelectionModifierCursorController == null) {
      mSelectionModifierCursorController=new SelectionModifierCursorController();
    }
  }
 else {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}
Program: 21822
Project: 21822
Buggy source:
private void prepareCursorControllers(){
  if (mCursorVisible && mLayout != null) {
    if (mInsertionPointCursorController == null) {
      mInsertionPointCursorController=new InsertionPointCursorController();
    }
  }
 else {
    mInsertionPointCursorController=null;
  }
  if (textCanBeSelected() && mLayout != null) {
    if (mSelectionModifierCursorController == null) {
      mSelectionModifierCursorController=new SelectionModifierCursorController();
    }
  }
 else {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}

Fixed version (ground truth):
private void prepareCursorControllers(){
  boolean windowSupportsHandles=false;
  ViewGroup.LayoutParams params=getRootView().getLayoutParams();
  if (params instanceof WindowManager.LayoutParams) {
    WindowManager.LayoutParams windowParams=(WindowManager.LayoutParams)params;
    windowSupportsHandles=windowParams.type < WindowManager.LayoutParams.FIRST_SUB_WINDOW || windowParams.type > WindowManager.LayoutParams.LAST_SUB_WINDOW;
  }
  if (windowSupportsHandles && mCursorVisible && mLayout != null) {
    if (mInsertionPointCursorController == null) {
      mInsertionPointCursorController=new InsertionPointCursorController();
    }
  }
 else {
    mInsertionPointCursorController=null;
  }
  if (windowSupportsHandles && textCanBeSelected() && mLayout != null) {
    if (mSelectionModifierCursorController == null) {
      mSelectionModifierCursorController=new SelectionModifierCursorController();
    }
  }
 else {
    stopTextSelectionMode();
    mSelectionModifierCursorController=null;
  }
}