nus-yam/ex-repair huggingface dataset:
Program: 170893
Project: 170893
Buggy source:
private void initView(View view){
  if (view == null) {
    return;
  }
  LinearLayoutManager layoutManager=new LinearLayoutManager(getContext());
  mAdapter=new ZhihuListAdapter(getContext(),mZhihuOnItemClickListener);
  RecyclerView recyclerView=view.findViewById(R.id.rv_zhihu_list);
  recyclerView.setAdapter(mAdapter);
  recyclerView.setLayoutManager(layoutManager);
  recyclerView.addOnScrollListener(new ZhihuOnScrollListener());
  mRefreshLayout=view.findViewById(R.id.srl_zhihu);
  mRefreshLayout.setOnRefreshListener(new ZhihuSwipeListener());
  mRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,android.R.color.holo_green_light,android.R.color.holo_orange_light,android.R.color.holo_red_light);
  mLoadMorebar=view.findViewById(R.id.bar_load_more_zhihu);
  mRLZhihuRoot=view.findViewById(R.id.rl_zhihu_root);
}

Fixed version (ground truth):
/** 
 * 初始化页面 UI
 * @param view Fragment 的 View
 */
private void initView(View view){
  if (view == null) {
    return;
  }
  LinearLayoutManager layoutManager=new LinearLayoutManager(getContext());
  mAdapter=new ZhihuListAdapter(getContext(),mZhihuOnItemClickListener);
  RecyclerView recyclerView=view.findViewById(R.id.rv_zhihu_list);
  recyclerView.setAdapter(mAdapter);
  recyclerView.setLayoutManager(layoutManager);
  recyclerView.addOnScrollListener(new ZhihuOnScrollListener());
  mRefreshLayout=view.findViewById(R.id.srl_zhihu);
  mRefreshLayout.setOnRefreshListener(new ZhihuSwipeListener());
  mRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,android.R.color.holo_green_light,android.R.color.holo_orange_light,android.R.color.holo_red_light);
  mLoadMorebar=view.findViewById(R.id.bar_load_more_zhihu);
  mRLZhihuRoot=view.findViewById(R.id.rl_zhihu_root);
}
Program: 170894
Project: 170894
Buggy source:
@Override public void onScrollStateChanged(RecyclerView recyclerView,int newState){
  LinearLayoutManager layoutManager=(LinearLayoutManager)recyclerView.getLayoutManager();
  int lastPosition=layoutManager.findLastCompletelyVisibleItemPosition();
  if (lastPosition == mAdapter.getItemCount() - 1) {
    mListViewModel.loadNextPageZhihu();
  }
}

Fixed version (ground truth):
@Override public void onScrollStateChanged(RecyclerView recyclerView,int newState){
  LinearLayoutManager layoutManager=(LinearLayoutManager)recyclerView.getLayoutManager();
  int lastPosition=layoutManager.findLastCompletelyVisibleItemPosition();
  if (lastPosition == mAdapter.getItemCount() - 1) {
    mListViewModel.loadNextPageZhihu(lastPosition);
  }
}
Program: 170895
Project: 170895
Buggy source:
public void refreshGrilsData(){
  mGirlPageIndex.setValue(1);
  mLoadHandler.startLoadGirls();
}

Fixed version (ground truth):
public void refreshGrilsData(){
  mGirlPageIndex.setValue(1);
}
Program: 170896
Project: 170896
Buggy source:
private MutableLiveData<Boolean> getLoadMoreState(){
  return mLoadMoreState;
}

Fixed version (ground truth):
public LiveData<Boolean> getLoadMoreState(){
  return mGirlsDataRepository.isLoadingGirlList();
}
Program: 170897
Project: 170897
Buggy source:
private GirlListViewModel(Application application,DataRepository girlsDataRepository){
  super(application);
  mGirlsDataRepository=girlsDataRepository;
  mLoadHandler=new LoadHandler(girlsDataRepository);
  mGirls=Transformations.switchMap(mGirlPageIndex,new Function<Integer,LiveData<List<Girl>>>(){
    @Override public LiveData<List<Girl>> apply(    Integer input){
      return mGirlsDataRepository.getGirlList(input);
    }
  }
);
}

Fixed version (ground truth):
private GirlListViewModel(Application application,DataRepository girlsDataRepository){
  super(application);
  mGirlsDataRepository=girlsDataRepository;
  mGirls=Transformations.switchMap(mGirlPageIndex,new Function<Integer,LiveData<List<Girl>>>(){
    @Override public LiveData<List<Girl>> apply(    Integer input){
      return mGirlsDataRepository.getGirlList(input);
    }
  }
);
}
Program: 170898
Project: 170898
Buggy source:
public void loadNextPageGirls(){
  if (!Util.isNetworkConnected(MyApplication.getInstance())) {
    return;
  }
  mGirlPageIndex.setValue((mGirlPageIndex.getValue() == null ? 1 : mGirlPageIndex.getValue() + 1));
  mLoadHandler.mLoadMoreState.setValue(true);
  mLoadHandler.startLoadGirls();
}

Fixed version (ground truth):
public void loadNextPageGirls(){
  if (!Util.isNetworkConnected(MyApplication.getInstance())) {
    return;
  }
  mGirlPageIndex.setValue((mGirlPageIndex.getValue() == null ? 1 : mGirlPageIndex.getValue() + 1));
}
Program: 170899
Project: 170899
Buggy source:
public void loadNextPageZhihu(){
  if (!Util.isNetworkConnected(MyApplication.getInstance())) {
    return;
  }
  mLoadHandler.startLoadGirls();
  mZhihuPageDate.setValue(String.valueOf(System.currentTimeMillis()));
}

Fixed version (ground truth):
/** 
 * 上拉加载更多时，获取 Zhihu 历史列表数据
 * @param positon 表示列表滑动到最后一项
 */
public void loadNextPageZhihu(int positon){
  if (!Util.isNetworkConnected(MyApplication.getInstance())) {
    return;
  }
  mZhihuPageDate.setValue(String.valueOf(positon));
}
Program: 170900
Project: 170900
Buggy source:
private ZhihuListViewModel(Application application,DataRepository dataRepository){
  super(application);
  mDataRepository=dataRepository;
  mLoadHandler=new LoadHandler(mDataRepository);
  mZhihuList=Transformations.switchMap(mZhihuPageDate,new Function<String,LiveData<List<ZhihuStory>>>(){
    @Override public LiveData<List<ZhihuStory>> apply(    String input){
      return mDataRepository.getZhihuList(input);
    }
  }
);
}

Fixed version (ground truth):
private ZhihuListViewModel(Application application,DataRepository dataRepository){
  super(application);
  mDataRepository=dataRepository;
  mZhihuList=Transformations.switchMap(mZhihuPageDate,new Function<String,LiveData<List<ZhihuStory>>>(){
    @Override public LiveData<List<ZhihuStory>> apply(    String input){
      return mDataRepository.getZhihuList(input);
    }
  }
);
}
Program: 170901
Project: 170901
Buggy source:
public LiveData<Boolean> isLoadingZhihuList(){
  return mLoadHandler.getLoadMoreState();
}

Fixed version (ground truth):
/** 
 * 数据请求状态由 DataRepository 控制，包括下拉刷新和上拉加载更多
 * @return 是否在进行数据请求
 */
public LiveData<Boolean> isLoadingZhihuList(){
  return mDataRepository.isLoadingZhihuList();
}
Program: 170902
Project: 170902
Buggy source:
public LiveData<List<ZhihuStory>> getZhihuList(){
  return mZhihuList;
}

Fixed version (ground truth):
/** 
 * 获取 Zhihu 列表数据
 * @return Zhihu 列表数据
 */
public LiveData<List<ZhihuStory>> getZhihuList(){
  return mZhihuList;
}
Program: 170903
Project: 170903
Buggy source:
public void refreshZhihusData(){
  mLoadHandler.startLoadGirls();
  mZhihuPageDate.setValue("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * 下拉刷新，获取最新的 Zhihu 列表数据
 */
public void refreshZhihusData(){
  mZhihuPageDate.setValue("String_Node_Str");
}
Program: 170904
Project: 170904
Buggy source:
@Override public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
  super.onViewCreated(view,savedInstanceState);
  rv=view.findViewById(R.id.items);
  viewModel=ViewModelProviders.of(getActivity()).get(RosterViewModel.class);
  empty=view.findViewById(R.id.empty);
  empty.setVisibility(View.INVISIBLE);
}

Fixed version (ground truth):
@Override public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
  super.onViewCreated(view,savedInstanceState);
  rv=view.findViewById(R.id.items);
  empty=view.findViewById(R.id.empty);
  empty.setVisibility(View.INVISIBLE);
}
Program: 170905
Project: 170905
Buggy source:
@Override public void onViewCreated(View view,@Nullable Bundle state){
  super.onViewCreated(view,state);
  DisplayViewModelFactory factory=new DisplayViewModelFactory(state);
  displayViewModel=ViewModelProviders.of(this,factory).get(DisplayViewModel.class);
  layoutManager=new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
  getRecyclerView().setLayoutManager(layoutManager);
  snapperCarr.attachToRecyclerView(getRecyclerView());
  adapter=new PageAdapter();
  getRecyclerView().setAdapter(adapter);
  getRecyclerView().addOnScrollListener(new RecyclerView.OnScrollListener(){
    @Override public void onScrolled(    RecyclerView recyclerView,    int dx,    int dy){
      if (ignoreNextScroll) {
        ignoreNextScroll=false;
      }
 else {
        int position=getCurrentPosition();
        if (position >= 0) {
          displayViewModel.setCurrentModel(adapter.getItem(position));
        }
      }
    }
  }
);
  Toolbar tb=view.findViewById(R.id.toolbar);
  tb.inflateMenu(R.menu.actions_display);
  tb.setOnMenuItemClickListener(item -> (onOptionsItemSelected(item)));
  if (((Contract)getActivity()).shouldShowTitle()) {
    tb.setTitle(R.string.app_name);
  }
  startObserving();
}

Fixed version (ground truth):
@Override public void onViewCreated(View view,@Nullable Bundle state){
  super.onViewCreated(view,state);
  layoutManager=new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
  getRecyclerView().setLayoutManager(layoutManager);
  snapperCarr.attachToRecyclerView(getRecyclerView());
  adapter=new PageAdapter();
  getRecyclerView().setAdapter(adapter);
  getRecyclerView().addOnScrollListener(new RecyclerView.OnScrollListener(){
    @Override public void onScrolled(    RecyclerView recyclerView,    int dx,    int dy){
      if (ignoreNextScroll) {
        ignoreNextScroll=false;
      }
 else {
        int position=getCurrentPosition();
        if (position >= 0) {
          displayViewModel.setCurrentModel(adapter.getItem(position));
        }
      }
    }
  }
);
  Toolbar tb=view.findViewById(R.id.toolbar);
  tb.inflateMenu(R.menu.actions_display);
  tb.setOnMenuItemClickListener(item -> (onOptionsItemSelected(item)));
  if (((Contract)getActivity()).shouldShowTitle()) {
    tb.setTitle(R.string.app_name);
  }
  editMenu=tb.getMenu().findItem(R.id.edit);
  editMenu.setVisible(false);
}
Program: 170906
Project: 170906
Buggy source:
@Override void render(ViewState state){
  adapter.setState(state);
  if (!displayViewModel.hasCurrentModelId()) {
    String initialModelId=getInitialModelId();
    if (initialModelId != null) {
      displayViewModel.setCurrentModelId(initialModelId);
    }
  }
  updatePager(false);
}

Fixed version (ground truth):
@Override void render(ViewState state){
  if (adapter != null) {
    adapter.setState(state);
    if (!displayViewModel.hasCurrentModelId()) {
      String initialModelId=getInitialModelId();
      if (initialModelId != null) {
        displayViewModel.setCurrentModelId(initialModelId);
      }
    }
    editMenu.setVisible(state.filteredItems().size() > 0);
    updatePager(false);
  }
}
Program: 170907
Project: 170907
Buggy source:
private void render(ViewState viewState){
  String id=getModelId();
  if (id != null) {
    model=viewState.find(id);
  }
  if (model != null) {
    if (!hadSavedState) {
      binding.setModel(model);
    }
    deleteItem.setVisible(true);
  }
}

Fixed version (ground truth):
private void render(ViewState viewState){
  if (binding != null) {
    String id=getModelId();
    if (id != null) {
      model=viewState.find(id);
    }
    if (model != null) {
      if (!hadSavedState) {
        binding.setModel(model);
      }
      deleteItem.setVisible(true);
    }
  }
}
Program: 170908
Project: 170908
Buggy source:
@Override public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
  viewModel=ViewModelProviders.of(getActivity()).get(RosterViewModel.class);
  viewModel.stateStream().observe(this,this::render);
  Toolbar tb=view.findViewById(R.id.toolbar);
  tb.inflateMenu(R.menu.actions_edit);
  tb.setOnMenuItemClickListener(item -> (onOptionsItemSelected(item)));
  if (((Contract)getActivity()).shouldShowTitle()) {
    tb.setTitle(R.string.app_name);
  }
  deleteItem=tb.getMenu().findItem(R.id.delete);
}

Fixed version (ground truth):
@Override public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
  Toolbar tb=view.findViewById(R.id.toolbar);
  tb.inflateMenu(R.menu.actions_edit);
  tb.setOnMenuItemClickListener(item -> (onOptionsItemSelected(item)));
  if (((Contract)getActivity()).shouldShowTitle()) {
    tb.setTitle(R.string.app_name);
  }
  deleteItem=tb.getMenu().findItem(R.id.delete);
}
Program: 170909
Project: 170909
Buggy source:
@Override public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
  super.onViewCreated(view,savedInstanceState);
  getRecyclerView().setLayoutManager(new LinearLayoutManager(getActivity()));
  DividerItemDecoration decoration=new DividerItemDecoration(getActivity(),LinearLayoutManager.VERTICAL);
  getRecyclerView().addItemDecoration(decoration);
  adapter=new RosterListAdapter(this);
  getRecyclerView().setAdapter(adapter);
  Toolbar tb=view.findViewById(R.id.toolbar);
  tb.inflateMenu(R.menu.actions_roster);
  tb.setTitle(R.string.app_name);
  tb.setOnMenuItemClickListener(item -> (onOptionsItemSelected(item)));
  Menu menu=tb.getMenu();
  filter=menu.findItem(R.id.filter);
  filterAll=menu.findItem(R.id.all);
  filterCompleted=menu.findItem(R.id.completed);
  filterOutstanding=menu.findItem(R.id.outstanding);
  adapter.updateFilter();
  startObserving();
}

Fixed version (ground truth):
@Override public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
  super.onViewCreated(view,savedInstanceState);
  getRecyclerView().setLayoutManager(new LinearLayoutManager(getActivity()));
  DividerItemDecoration decoration=new DividerItemDecoration(getActivity(),LinearLayoutManager.VERTICAL);
  getRecyclerView().addItemDecoration(decoration);
  adapter=new RosterListAdapter(this);
  getRecyclerView().setAdapter(adapter);
  Toolbar tb=view.findViewById(R.id.toolbar);
  tb.inflateMenu(R.menu.actions_roster);
  tb.setTitle(R.string.app_name);
  tb.setOnMenuItemClickListener(item -> (onOptionsItemSelected(item)));
  Menu menu=tb.getMenu();
  filter=menu.findItem(R.id.filter);
  filterAll=menu.findItem(R.id.all);
  filterCompleted=menu.findItem(R.id.completed);
  filterOutstanding=menu.findItem(R.id.outstanding);
  adapter.updateFilter();
}
Program: 170910
Project: 170910
Buggy source:
@Override void render(ViewState state){
  if (state.cause() == null) {
    adapter.setState(state);
    if (state.isLoaded() && state.filteredItems().size() == 0) {
      getEmptyView().setVisibility(View.VISIBLE);
      if (state.items().size() > 0) {
        getEmptyView().setText(R.string.msg_empty_filter);
      }
 else {
        getEmptyView().setText(R.string.msg_empty);
      }
    }
 else {
      getEmptyView().setVisibility(View.GONE);
    }
    if (state.getSelectionCount() == 0 && snackbar != null && snackbar.isShown()) {
      snackbar.dismiss();
    }
  }
 else {
    Snackbar.make(getView(),R.string.msg_crash,Snackbar.LENGTH_LONG).show();
    Log.e(getClass().getSimpleName(),"String_Node_Str",state.cause());
  }
}

Fixed version (ground truth):
@Override void render(ViewState state){
  if (adapter != null) {
    if (state.cause() == null) {
      adapter.setState(state);
      if (state.isLoaded() && state.filteredItems().size() == 0) {
        getEmptyView().setVisibility(View.VISIBLE);
        if (state.items().size() > 0) {
          getEmptyView().setText(R.string.msg_empty_filter);
        }
 else {
          getEmptyView().setText(R.string.msg_empty);
        }
      }
 else {
        getEmptyView().setVisibility(View.GONE);
      }
      if (state.getSelectionCount() == 0 && snackbar != null && snackbar.isShown()) {
        snackbar.dismiss();
      }
    }
 else {
      Snackbar.make(getView(),R.string.msg_crash,Snackbar.LENGTH_LONG).show();
      Log.e(getClass().getSimpleName(),"String_Node_Str",state.cause());
    }
  }
}
Program: 170911
Project: 170911
Buggy source:
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  pager=findViewById(R.id.pager);
  layoutManager=new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
  pager.setLayoutManager(layoutManager);
  snapperCarr.attachToRecyclerView(pager);
  viewModel=ViewModelProviders.of(this).get(EditorViewModel.class);
  if (savedInstanceState != null) {
    viewModel.restoreInstanceState(savedInstanceState);
  }
  adapter=new PageAdapter(viewModel,getLayoutInflater());
  pager.setAdapter(adapter);
  pager.setHasFixedSize(true);
  tabs=findViewById(R.id.tabs);
  for (int i=0; i < adapter.getItemCount(); i++) {
    tabs.addTab(tabs.newTab().setText(adapter.getTabText(i)));
  }
  tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){
    @Override public void onTabSelected(    TabLayout.Tab tab){
      pager.smoothScrollToPosition(tab.getPosition());
    }
    @Override public void onTabUnselected(    TabLayout.Tab tab){
    }
    @Override public void onTabReselected(    TabLayout.Tab tab){
    }
  }
);
  pager.addOnScrollStateChangedListener(scrollState -> {
    if (scrollState == RecyclerView.SCROLL_STATE_IDLE) {
      int tab=getCurrentPosition();
      if (tab >= 0 && tab < tabs.getTabCount()) {
        tabs.getTabAt(tab).select();
      }
    }
  }
);
}

Fixed version (ground truth):
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  pager=findViewById(R.id.pager);
  layoutManager=new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
  pager.setLayoutManager(layoutManager);
  snapperCarr.attachToRecyclerView(pager);
  viewModel=ViewModelProviders.of(this).get(EditorViewModel.class);
  if (savedInstanceState != null) {
    viewModel.restoreInstanceState(savedInstanceState);
  }
  adapter=new PageAdapter(viewModel,getLayoutInflater());
  pager.setAdapter(adapter);
  pager.setHasFixedSize(true);
  tabs=findViewById(R.id.tabs);
  for (int i=0; i < adapter.getItemCount(); i++) {
    tabs.addTab(tabs.newTab().setText(adapter.getTabText(i)));
  }
  tabs.addOnTabSelectedListener(new TabLayoutLite.OnTabSelectedListener(){
    @Override public void onTabSelected(    TabLayoutLite.Tab tab){
      pager.smoothScrollToPosition(tab.getPosition());
    }
    @Override public void onTabUnselected(    TabLayoutLite.Tab tab){
    }
    @Override public void onTabReselected(    TabLayoutLite.Tab tab){
    }
  }
);
  pager.addOnScrollStateChangedListener(scrollState -> {
    if (scrollState == RecyclerView.SCROLL_STATE_IDLE) {
      int tab=getCurrentPosition();
      if (tab >= 0 && tab < tabs.getTabCount()) {
        tabs.getTabAt(tab).select();
      }
    }
  }
);
}
Program: 170912
Project: 170912
Buggy source:
private void swap(){
  int first=getCurrentPosition();
  int second;
  if (first >= adapter.getItemCount() - 1) {
    second=first;
    first--;
  }
 else {
    second=first + 1;
  }
  adapter.swap(first,second);
  TabLayout.Tab firstTab=tabs.getTabAt(first);
  TabLayout.Tab secondTab=tabs.getTabAt(second);
  CharSequence firstText=firstTab.getText();
  firstTab.setText(secondTab.getText());
  secondTab.setText(firstText);
}

Fixed version (ground truth):
private void swap(){
  int first=getCurrentPosition();
  int second;
  if (first >= adapter.getItemCount() - 1) {
    second=first;
    first--;
  }
 else {
    second=first + 1;
  }
  adapter.swap(first,second);
  TabLayoutLite.Tab firstTab=tabs.getTabAt(first);
  TabLayoutLite.Tab secondTab=tabs.getTabAt(second);
  CharSequence firstText=firstTab.getText();
  firstTab.setText(secondTab.getText());
  secondTab.setText(firstText);
}
Program: 170913
Project: 170913
Buggy source:
@Override public void onTabSelected(TabLayout.Tab tab){
  pager.smoothScrollToPosition(tab.getPosition());
}

Fixed version (ground truth):
@Override public void onTabSelected(TabLayoutLite.Tab tab){
  pager.smoothScrollToPosition(tab.getPosition());
}
Program: 170914
Project: 170914
Buggy source:
@Override public void onTabUnselected(TabLayout.Tab tab){
}

Fixed version (ground truth):
@Override public void onTabUnselected(TabLayoutLite.Tab tab){
}
Program: 170915
Project: 170915
Buggy source:
@Override public void onTabReselected(TabLayout.Tab tab){
}

Fixed version (ground truth):
@Override public void onTabReselected(TabLayoutLite.Tab tab){
}
Program: 170916
Project: 170916
Buggy source:
@Override public void writeToParcel(Parcel dest,int flags){
  dest.writeInt(labelLineSize);
  dest.writeInt(labelTextSize);
  dest.writeLong(gridLineColor);
  dest.writeInt(gridLineWidth);
  dest.writeInt(xLabelsNumber);
  dest.writeInt(yLabelsNumber);
}

Fixed version (ground truth):
@Override public void writeToParcel(Parcel dest,int flags){
  dest.writeInt(labelLineSize);
  dest.writeInt(labelTextSize);
  dest.writeInt(gridLineColor);
  dest.writeInt(gridLineWidth);
  dest.writeInt(xLabelsNumber);
  dest.writeInt(yLabelsNumber);
}
Program: 170917
Project: 170917
Buggy source:
/** 
 * Set that an operation blocking the user interface is currently performed
 */
@SuppressWarnings("String_Node_Str") public void setInOperation(AsyncTask owner,boolean inOperation,OnClickListener stopHandler){
  fragment.setInOperation(inOperation,stopHandler);
  formulaListView.setEnabled(!inOperation);
  palette.setEnabled(!inOperation);
  if (!inOperation && owner instanceof XmlLoaderTask) {
    XmlLoaderTask t=(XmlLoaderTask)owner;
    fragment.setXmlReadingResult(t.isMmtOpened());
    if (t.error != null) {
      isContentValid();
      Toast.makeText(getActivity(),t.error,Toast.LENGTH_LONG).show();
    }
 else     if (t.postAction == XmlLoaderTask.PostAction.CALCULATE) {
      calculate();
    }
 else     if (t.postAction == XmlLoaderTask.PostAction.INTERRUPT) {
    }
 else {
      isContentValid();
    }
    if (xmlLoaderTask != null) {
      ViewUtils.Debug(this,"String_Node_Str" + xmlLoaderTask.toString());
      xmlLoaderTask=null;
    }
    updatePalette();
  }
  if (taSession != null) {
    taSession.setInOperation(owner,inOperation);
  }
}

Fixed version (ground truth):
/** 
 * Set that an operation blocking the user interface is currently performed
 */
@SuppressWarnings("String_Node_Str") public void setInOperation(AsyncTask owner,boolean inOperation,OnClickListener stopHandler){
  fragment.setInOperation(inOperation,stopHandler);
  formulaListView.setEnabled(!inOperation);
  palette.setEnabled(!inOperation);
  if (!inOperation && owner instanceof XmlLoaderTask) {
    XmlLoaderTask t=(XmlLoaderTask)owner;
    fragment.setXmlReadingResult(t.isMmtOpened());
    if (t.error != null) {
      isContentValid();
      Toast.makeText(getActivity(),t.error,Toast.LENGTH_LONG).show();
    }
 else     if (t.postAction == XmlLoaderTask.PostAction.CALCULATE) {
      calculate();
    }
 else     if (t.postAction == XmlLoaderTask.PostAction.INTERRUPT) {
    }
 else {
      isContentValid();
    }
    if (xmlLoaderTask != null) {
      ViewUtils.Debug(this,"String_Node_Str" + xmlLoaderTask.toString());
      xmlLoaderTask=null;
    }
    formulaScrollView.setScaleDetectorActive(true);
    updatePalette();
  }
  if (taSession != null) {
    taSession.setInOperation(owner,inOperation);
  }
}
Program: 170918
Project: 170918
Buggy source:
/** 
 * Procedure calculates recursively the derivative value
 */
public CalculatedValue.ValueType getDerivativeValue(String var,CalculaterTask thread,CalculatedValue outValue) throws CancelException {
  if (isTerm()) {
    return term.getDerivativeValue(var,thread,outValue);
  }
  if (contentType == ContentType.ARGUMENT && parser.isArgumentInHolder(var)) {
    return outValue.setValue(parser.getSign());
  }
  return outValue.setValue(0.0);
}

Fixed version (ground truth):
/** 
 * Procedure calculates recursively the derivative value
 */
public CalculatedValue.ValueType getDerivativeValue(String var,CalculaterTask thread,CalculatedValue outValue) throws CancelException {
  if (isTerm()) {
    return term.getDerivativeValue(var,thread,outValue);
  }
  if (contentType == ContentType.ARGUMENT && parser.isArgumentInHolder(var)) {
    return outValue.setValue(parser.getSign());
  }
  return outValue.setValue(0.0,null);
}
Program: 170919
Project: 170919
Buggy source:
/** 
 * Re-implementation for methods for FormulaBase and FormulaTerm superclass's
 */
@Override public CalculatedValue.ValueType getValue(CalculaterTask thread,CalculatedValue outValue) throws CancelException {
  if (termType != null) {
    leftTerm.getValue(thread,leftTermValue);
    rightTerm.getValue(thread,rightTermValue);
switch (getComparatorType()) {
case EQUAL:
      return outValue.setValue((leftTermValue.getReal() == rightTermValue.getReal()) ? 1 : -1);
case NOT_EQUAL:
    return outValue.setValue((leftTermValue.getReal() != rightTermValue.getReal()) ? 1 : -1);
case LESS:
  return outValue.setValue((leftTermValue.getReal() < rightTermValue.getReal()) ? 1 : -1);
case LESS_EQUAL:
return outValue.setValue((leftTermValue.getReal() <= rightTermValue.getReal()) ? 1 : -1);
case GREATER:
return outValue.setValue((leftTermValue.getReal() > rightTermValue.getReal()) ? 1 : -1);
case GREATER_EQUAL:
return outValue.setValue((leftTermValue.getReal() >= rightTermValue.getReal()) ? 1 : -1);
case COMPARATOR_AND:
return outValue.setValue((leftTermValue.getReal() > 0 && rightTermValue.getReal() > 0) ? 1 : -1);
case COMPARATOR_OR:
return outValue.setValue((leftTermValue.getReal() > 0 || rightTermValue.getReal() > 0) ? 1 : -1);
}
}
return outValue.invalidate(CalculatedValue.ErrorType.TERM_NOT_READY);
}

Fixed version (ground truth):
/** 
 * Re-implementation for methods for FormulaBase and FormulaTerm superclass's
 */
@Override public CalculatedValue.ValueType getValue(CalculaterTask thread,CalculatedValue outValue) throws CancelException {
  if (termType != null) {
    leftTerm.getValue(thread,leftTermValue);
    rightTerm.getValue(thread,rightTermValue);
switch (getComparatorType()) {
case EQUAL:
      return outValue.setValue((leftTermValue.getReal() == rightTermValue.getReal()) ? 1 : 0);
case NOT_EQUAL:
    return outValue.setValue((leftTermValue.getReal() != rightTermValue.getReal()) ? 1 : 0);
case LESS:
  return outValue.setValue((leftTermValue.getReal() < rightTermValue.getReal()) ? 1 : 0);
case LESS_EQUAL:
return outValue.setValue((leftTermValue.getReal() <= rightTermValue.getReal()) ? 1 : 0);
case GREATER:
return outValue.setValue((leftTermValue.getReal() > rightTermValue.getReal()) ? 1 : 0);
case GREATER_EQUAL:
return outValue.setValue((leftTermValue.getReal() >= rightTermValue.getReal()) ? 1 : 0);
case COMPARATOR_AND:
return outValue.setValue((leftTermValue.getReal() > 0 && rightTermValue.getReal() > 0) ? 1 : 0);
case COMPARATOR_OR:
return outValue.setValue((leftTermValue.getReal() > 0 || rightTermValue.getReal() > 0) ? 1 : 0);
}
}
return outValue.invalidate(CalculatedValue.ErrorType.TERM_NOT_READY);
}
Program: 170920
Project: 170920
Buggy source:
@Override protected CustomEditText initializeTerm(CustomEditText v,LinearLayout l){
  if (v.getText() != null) {
    final String val=v.getText().toString();
    if (termType == FunctionType.FUNCTION_INDEX && val.equals(getContext().getResources().getString(R.string.formula_arg_term_key))) {
      final TermField t=addTerm(getFormulaRoot(),l,-1,v,this,getArgumentDepth());
      t.bracketsType=TermField.BracketsType.NEVER;
    }
 else     if (termType != FunctionType.FUNCTION_INDEX && val.equals(getContext().getResources().getString(R.string.formula_arg_term_key))) {
      final TermField t=addTerm(getFormulaRoot(),l,-1,v,this,0);
      t.bracketsType=TermField.BracketsType.NEVER;
    }
  }
  return v;
}

Fixed version (ground truth):
@Override protected CustomEditText initializeTerm(CustomEditText v,LinearLayout l){
  if (v.getText() != null) {
    final String val=v.getText().toString();
    if (termType == FunctionType.FUNCTION_INDEX && val.equals(getContext().getResources().getString(R.string.formula_arg_term_key))) {
      final TermField t=addTerm(getFormulaRoot(),l,-1,v,this,getArgumentDepth());
      t.bracketsType=TermField.BracketsType.NEVER;
    }
 else     if (termType != FunctionType.FUNCTION_INDEX && val.equals(getContext().getResources().getString(R.string.formula_arg_term_key))) {
      final TermField t=addTerm(getFormulaRoot(),l,-1,v,this,0);
      t.bracketsType=TermField.BracketsType.NEVER;
      if (termType == FunctionType.IDENTITY) {
        t.getEditText().setComparatorEnabled(true);
      }
    }
  }
  return v;
}
Program: 170921
Project: 170921
Buggy source:
@Override public void updateTextSize(){
  super.updateTextSize();
  final int hsp=getFormulaList().getDimen().get(ScaledDimensions.Type.HOR_SYMBOL_PADDING);
  if (functionTerm != null) {
    if (termType == FunctionType.SQRT_LAYOUT || termType == FunctionType.NTHRT_LAYOUT) {
      functionTerm.setWidth(getFormulaList().getDimen().get(ScaledDimensions.Type.SMALL_SYMBOL_SIZE));
      functionTerm.setPadding(0,0,0,0);
    }
 else     if (termType == FunctionType.CONJUGATE_LAYOUT) {
      functionTerm.setPadding(hsp,0,hsp,0);
    }
 else {
      functionTerm.setPadding(0,0,hsp,0);
    }
  }
  if (termType == FunctionType.NTHRT_LAYOUT) {
    View nthrtPoverLayout=layout.findViewById(R.id.nthrt_power_layout);
    if (nthrtPoverLayout != null) {
      nthrtPoverLayout.setPadding(hsp,0,hsp,0);
    }
  }
}

Fixed version (ground truth):
@Override public void updateTextSize(){
  super.updateTextSize();
  final int hsp=getFormulaList().getDimen().get(ScaledDimensions.Type.HOR_SYMBOL_PADDING);
  if (functionTerm != null) {
    if (termType == FunctionType.SQRT_LAYOUT || termType == FunctionType.NTHRT_LAYOUT) {
      functionTerm.setWidth(getFormulaList().getDimen().get(ScaledDimensions.Type.SMALL_SYMBOL_SIZE));
      functionTerm.setPadding(0,0,0,0);
    }
 else     if (termType == FunctionType.CONJUGATE_LAYOUT) {
      functionTerm.setPadding(hsp,0,hsp,0);
    }
 else     if (getFunctionLabel().isEmpty()) {
      functionTerm.setPadding(0,0,hsp,0);
    }
  }
  if (termType == FunctionType.NTHRT_LAYOUT) {
    View nthrtPoverLayout=layout.findViewById(R.id.nthrt_power_layout);
    if (nthrtPoverLayout != null) {
      nthrtPoverLayout.setPadding(hsp,0,hsp,0);
    }
  }
}
Program: 170922
Project: 170922
Buggy source:
public void updateTextSize(ScaledDimensions dimen,int termDepth){
  strokeWidth=dimen.get(ScaledDimensions.Type.STROKE_WIDTH);
  if (symbolType == SymbolType.SUMMATION || symbolType == SymbolType.PRODUCT || symbolType == SymbolType.INTEGRAL) {
    setTextSize(TypedValue.COMPLEX_UNIT_PX,dimen.getTextSize(ScaledDimensions.Type.BIG_SYMBOL_SIZE,termDepth));
  }
 else {
    setTextSize(TypedValue.COMPLEX_UNIT_PX,dimen.getTextSize(termDepth));
  }
  setText(getText(),AppCompatTextView.BufferType.SPANNABLE);
  if (symbolType != null) {
switch (symbolType) {
case EMPTY:
      break;
case HOR_LINE:
    setPadding(0,0,0,0);
  setHeight(strokeWidth * 5);
break;
case LEFT_BRACKET:
case LEFT_SQR_BRACKET:
case RIGHT_BRACKET:
case RIGHT_SQR_BRACKET:
final int p1=dimen.get(ScaledDimensions.Type.HOR_BRAKET_PADDING);
setPadding(p1,0,p1,0);
break;
case SLASH:
setPadding(0,0,0,0);
break;
case INTEGRAL:
final int p2=dimen.get(ScaledDimensions.Type.HOR_SYMBOL_PADDING);
setWidth(20 * strokeWidth);
setHeight(60 * strokeWidth);
setPadding(p2,0,p2,0);
default :
final int p3=dimen.get(ScaledDimensions.Type.HOR_SYMBOL_PADDING);
setPadding(p3,0,p3,0);
break;
}
}
}

Fixed version (ground truth):
public void updateTextSize(ScaledDimensions dimen,int termDepth){
  strokeWidth=dimen.get(ScaledDimensions.Type.STROKE_WIDTH);
  if (symbolType == SymbolType.SUMMATION || symbolType == SymbolType.PRODUCT || symbolType == SymbolType.INTEGRAL) {
    setTextSize(TypedValue.COMPLEX_UNIT_PX,dimen.getTextSize(ScaledDimensions.Type.BIG_SYMBOL_SIZE,termDepth));
  }
 else {
    setTextSize(TypedValue.COMPLEX_UNIT_PX,dimen.getTextSize(termDepth));
  }
  setText(getText(),AppCompatTextView.BufferType.SPANNABLE);
  if (symbolType != null) {
switch (symbolType) {
case EMPTY:
      break;
case HOR_LINE:
    setPadding(0,0,0,0);
  setHeight(strokeWidth * 5);
break;
case LEFT_BRACKET:
case LEFT_SQR_BRACKET:
case RIGHT_BRACKET:
case RIGHT_SQR_BRACKET:
final int p1=dimen.get(ScaledDimensions.Type.HOR_BRAKET_PADDING);
setPadding(p1,0,p1,0);
break;
case SLASH:
setPadding(0,0,0,0);
break;
case INTEGRAL:
final int p2=dimen.get(ScaledDimensions.Type.HOR_SYMBOL_PADDING);
setWidth(20 * strokeWidth);
setHeight(60 * strokeWidth);
setPadding(p2,0,p2,0);
case TEXT:
final int p3=dimen.get(ScaledDimensions.Type.HOR_TEXT_PADDING);
setPadding(p3,0,p3,0);
break;
default :
final int p4=dimen.get(ScaledDimensions.Type.HOR_SYMBOL_PADDING);
setPadding(p4,0,p4,0);
break;
}
}
}
Program: 170923
Project: 170923
Buggy source:
/** 
 * FormulaTermInterval-specific methods
 */
private Pair<Unit,Integer> compareUnits(TermField[] terms){
  Unit unit=terms[0].getParser().getUnit();
  int compatibleNumber=0;
  for (  TermField t : terms) {
    if (unit != null && unit.isCompatible(t.getParser().getUnit())) {
      compatibleNumber++;
    }
    if (unit == null) {
      unit=t.getParser().getUnit();
    }
  }
  return new Pair<>(unit == null ? null : unit.getStandardUnit(),compatibleNumber);
}

Fixed version (ground truth):
/** 
 * FormulaTermInterval-specific methods
 */
private Pair<Unit,Integer> compareUnits(TermField[] terms){
  Unit unit=terms[0].getParser().getUnit();
  int compatibleNumber=0;
  for (  TermField t : terms) {
    final Unit tp=t.getParser().getUnit();
    if (unit != null && tp != null && unit.isCompatible(tp)) {
      compatibleNumber++;
    }
    if (unit == null) {
      unit=tp;
    }
  }
  return new Pair<>(unit == null ? null : unit.getStandardUnit(),compatibleNumber);
}
Program: 170924
Project: 170924
Buggy source:
@Override public CalculatedValue.ValueType getValue(CalculaterTask thread,CalculatedValue outValue) throws CancelException {
  if (termType != null && terms.size() > 0) {
    ensureArgValSize();
    for (int i=0; i < terms.size(); i++) {
      terms.get(i).getValue(thread,argVal[i]);
    }
    final CalculatedValue a0=argVal[0];
switch (getFunctionType()) {
case SIN:
      return outValue.sin(a0);
case CSC:
    return outValue.csc(a0);
case ASIN:
  return outValue.asin(a0);
case ACSC:
{
  outValue.divide(CalculatedValue.ONE,a0);
  return outValue.asin(outValue);
}
case COS:
return outValue.cos(a0);
case SEC:
return outValue.sec(a0);
case ACOS:
return outValue.acos(a0);
case ASEC:
{
outValue.divide(CalculatedValue.ONE,a0);
return outValue.acos(outValue);
}
case TAN:
return outValue.tan(a0);
case COT:
return outValue.cot(a0);
case ATAN:
return outValue.atan(a0);
case ATAN2:
{
final CalculatedValue a1=argVal[1];
if (a0.isComplex() || a1.isComplex()) {
return outValue.invalidate(CalculatedValue.ErrorType.PASSED_COMPLEX);
}
return outValue.setValue(FastMath.atan2(a0.getReal(),a1.getReal()));
}
case ACOT:
{
outValue.divide(CalculatedValue.ONE,a0);
return outValue.atan(outValue);
}
}
}
return outValue.invalidate(CalculatedValue.ErrorType.TERM_NOT_READY);
}

Fixed version (ground truth):
@Override public CalculatedValue.ValueType getValue(CalculaterTask thread,CalculatedValue outValue) throws CancelException {
  if (termType != null && terms.size() > 0) {
    ensureArgValSize();
    for (int i=0; i < terms.size(); i++) {
      terms.get(i).getValue(thread,argVal[i]);
    }
    final CalculatedValue a0=argVal[0];
switch (getFunctionType()) {
case SIN:
      return outValue.sin(a0);
case CSC:
    return outValue.csc(a0);
case ASIN:
  return outValue.asin(a0);
case ACSC:
{
  outValue.divide(CalculatedValue.ONE,a0);
  return outValue.asin(outValue);
}
case COS:
return outValue.cos(a0);
case SEC:
return outValue.sec(a0);
case ACOS:
return outValue.acos(a0);
case ASEC:
{
outValue.divide(CalculatedValue.ONE,a0);
return outValue.acos(outValue);
}
case TAN:
return outValue.tan(a0);
case COT:
return outValue.cot(a0);
case ATAN:
return outValue.atan(a0);
case ATAN2:
{
final CalculatedValue a1=argVal[1];
if (a0.isComplex() || a1.isComplex()) {
return outValue.invalidate(CalculatedValue.ErrorType.PASSED_COMPLEX);
}
return outValue.setValue(FastMath.atan2(a0.getReal(),a1.getReal()));
}
case ACOT:
{
outValue.atan(a0);
tmpVal.setValue(FastMath.PI / 2.0f);
return outValue.subtract(tmpVal,outValue);
}
}
}
return outValue.invalidate(CalculatedValue.ErrorType.TERM_NOT_READY);
}
Program: 170925
Project: 170925
Buggy source:
protected boolean isRemainingTermOnDelete(){
  return terms.size() <= 1;
}

Fixed version (ground truth):
protected boolean isRemainingTermOnDelete(){
  return terms.size() <= 1 || !isNewTermEnabled();
}
Program: 170926
Project: 170926
Buggy source:
@Override public boolean isNewTermEnabled(){
  return getFunctionType().isLink();
}

Fixed version (ground truth):
/** 
 * Implementation for methods for FormulaChangeIf interface
 */
@Override public boolean isNewTermEnabled(){
  return getFunctionType().isLink();
}
Program: 170927
Project: 170927
Buggy source:
public DialogPaletteSettings(Context context,PaletteSettingsChangeIf changeIf,List<String> visibleGroups){
  super(context,R.layout.dialog_palette_settings,R.string.dialog_palette_settings_title);
  this.changeIf=changeIf;
  this.groups=FormulaTerm.collectPaletteGroups();
  final LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  paletteView=getRootLayout().findViewById(R.id.dialog_palette_view);
{
    inflater.inflate(R.layout.dialog_palette_settings_item,paletteView);
    final LinearLayout itemLayout=(LinearLayout)paletteView.getChildAt(paletteView.getChildCount() - 1);
    final LinearLayout buttonLayout=itemLayout.findViewById(R.id.dialog_palette_settings_buttons);
    FormulaBase.addToPalette(context,buttonLayout);
    prepareGroup(context,itemLayout,FormulaBase.class.getSimpleName(),visibleGroups);
  }
  for (  TermTypeIf.GroupType g : groups) {
    inflater.inflate(R.layout.dialog_palette_settings_item,paletteView);
    final LinearLayout itemLayout=(LinearLayout)paletteView.getChildAt(paletteView.getChildCount() - 1);
    final LinearLayout buttonLayout=itemLayout.findViewById(R.id.dialog_palette_settings_buttons);
    FormulaTerm.addToPalette(context,buttonLayout,g);
    prepareGroup(context,itemLayout,g.toString(),visibleGroups);
  }
}

Fixed version (ground truth):
public DialogPaletteSettings(Context context,PaletteSettingsChangeIf changeIf,List<String> visibleGroups){
  super(context,R.layout.dialog_palette_settings,R.string.dialog_palette_settings_title);
  this.changeIf=changeIf;
  this.groups=FormulaTerm.collectPaletteGroups();
  final LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  paletteView=getRootLayout().findViewById(R.id.dialog_palette_view);
{
    inflater.inflate(R.layout.dialog_palette_settings_item,paletteView);
    final LinearLayout itemLayout=(LinearLayout)paletteView.getChildAt(paletteView.getChildCount() - 1);
    final LinearLayout buttonLayout=itemLayout.findViewById(R.id.dialog_palette_settings_buttons);
    final List<PaletteButton> termButtons=new ArrayList<>();
    FormulaBase.addToPalette(context,termButtons);
    for (    PaletteButton b : termButtons) {
      buttonLayout.addView(b);
    }
    prepareGroup(context,itemLayout,FormulaBase.class.getSimpleName(),visibleGroups);
  }
  for (  TermTypeIf.GroupType g : groups) {
    inflater.inflate(R.layout.dialog_palette_settings_item,paletteView);
    final LinearLayout itemLayout=(LinearLayout)paletteView.getChildAt(paletteView.getChildCount() - 1);
    final LinearLayout buttonLayout=itemLayout.findViewById(R.id.dialog_palette_settings_buttons);
    final List<PaletteButton> termButtons=new ArrayList<>();
    FormulaTerm.addToPalette(context,termButtons,true,g);
    for (    PaletteButton b : termButtons) {
      buttonLayout.addView(b);
    }
    prepareGroup(context,itemLayout,g.toString(),visibleGroups);
  }
}
Program: 170928
Project: 170928
Buggy source:
public static void addToPalette(Context context,LinearLayout paletteLayout){
  for (int i=0; i < BaseType.values().length; i++) {
    final BaseType t=BaseType.values()[i];
    if (t.getImageId() != Palette.NO_BUTTON) {
      if (t == BaseType.TERM) {
        PaletteButton p=new PaletteButton(context,R.string.formula_term_separator,t.getImageId(),t.getDescriptionId(),t.toString());
        p.setCategories(new PaletteButton.Category[]{PaletteButton.Category.NEW_TERM,PaletteButton.Category.CONVERSION});
        paletteLayout.addView(p);
      }
 else {
        PaletteButton p=new PaletteButton(context,Palette.NO_BUTTON,t.getImageId(),t.getDescriptionId(),t.toString());
        paletteLayout.addView(p);
      }
    }
  }
}

Fixed version (ground truth):
public static void addToPalette(Context context,List<PaletteButton> paletteLayout){
  for (int i=0; i < BaseType.values().length; i++) {
    final BaseType t=BaseType.values()[i];
    if (t.getImageId() != Palette.NO_BUTTON) {
      if (t == BaseType.TERM) {
        PaletteButton p=new PaletteButton(context,FormulaBase.class.getSimpleName(),t.toString(),t.getImageId(),t.getDescriptionId(),R.string.formula_term_separator);
        p.setCategories(new PaletteButton.Category[]{PaletteButton.Category.NEW_TERM,PaletteButton.Category.CONVERSION});
        paletteLayout.add(p);
      }
 else {
        PaletteButton p=new PaletteButton(context,FormulaBase.class.getSimpleName(),t.toString(),t.getImageId(),t.getDescriptionId(),Palette.NO_BUTTON);
        paletteLayout.add(p);
      }
    }
  }
}
Program: 170929
Project: 170929
Buggy source:
private static <T extends TermTypeIf>void addToPalette(Context context,T[] buttons,LinearLayout paletteLayout,PaletteButton.Category[] categories){
  for (  final TermTypeIf b : buttons) {
    if (b.getImageId() != Palette.NO_BUTTON) {
      PaletteButton p=new PaletteButton(context,b.getShortCutId(),b.getImageId(),b.getDescriptionId(),b.getLowerCaseName());
      paletteLayout.addView(p);
      p.setCategories(categories);
    }
  }
}

Fixed version (ground truth):
private static <T extends TermTypeIf>void addToPalette(Context context,T[] buttons,List<PaletteButton> paletteLayout,boolean ensureImageId,PaletteButton.Category[] categories){
  for (  final TermTypeIf b : buttons) {
    if (ensureImageId && b.getImageId() == Palette.NO_BUTTON) {
      continue;
    }
    PaletteButton p=new PaletteButton(context,b);
    p.setCategories(categories);
    paletteLayout.add(p);
  }
}
Program: 170930
Project: 170930
Buggy source:
private void addButtonsToPalette(){
  paletteBlock.clear();
  for (int i=paletteLayout.getChildCount() - 1; i > 0; i--) {
    if (paletteLayout.getChildAt(i) instanceof PaletteButton) {
      paletteLayout.removeViewAt(i);
    }
  }
  if (visibleGroups.contains(FormulaBase.class.getSimpleName())) {
    FormulaBase.addToPalette(context,paletteLayout);
  }
  for (  TermTypeIf.GroupType g : FormulaTerm.collectPaletteGroups()) {
    if (visibleGroups.contains(g.toString())) {
      FormulaTerm.addToPalette(context,paletteLayout,g);
    }
  }
  for (int i=0; i < Category.values().length; i++) {
    paletteBlock.add(new ArrayList<PaletteButton>());
  }
  for (int i=0; i < paletteLayout.getChildCount(); i++) {
    View b=paletteLayout.getChildAt(i);
    if (b instanceof PaletteButton) {
      final PaletteButton pb=(PaletteButton)b;
      if (pb.getCategories() != null) {
        for (        Category cat : pb.getCategories()) {
          paletteBlock.get(cat.ordinal()).add(pb);
        }
      }
      pb.setOnLongClickListener(this);
      pb.setOnClickListener(this);
    }
  }
}

Fixed version (ground truth):
private void addButtonsToPalette(){
  termButtons.clear();
  paletteBlock.clear();
  for (int i=paletteLayout.getChildCount() - 1; i > 0; i--) {
    if (paletteLayout.getChildAt(i) instanceof PaletteButton) {
      paletteLayout.removeViewAt(i);
    }
  }
  FormulaBase.addToPalette(context,termButtons);
  for (  TermTypeIf.GroupType g : FormulaTerm.collectPaletteGroups()) {
    FormulaTerm.addToPalette(context,termButtons,false,g);
  }
  for (int i=0; i < Category.values().length; i++) {
    paletteBlock.add(new ArrayList<PaletteButton>());
  }
  for (  PaletteButton pb : termButtons) {
    if (pb.getCategories() != null) {
      for (      Category cat : pb.getCategories()) {
        paletteBlock.get(cat.ordinal()).add(pb);
      }
    }
    if (pb.hasImage() && visibleGroups.contains(pb.getGroup())) {
      pb.setOnLongClickListener(this);
      pb.setOnClickListener(this);
      paletteLayout.addView(pb);
    }
  }
}
Program: 170931
Project: 170931
Buggy source:
@Override public void onTextChanged(String s,boolean isManualInput){
  if (s == null || listChangeIf == null) {
    lastHiddenInput=null;
    return;
  }
  if (lastHiddenInput != null && lastHiddenInput.equals(s)) {
    return;
  }
  lastHiddenInput=s;
  if (ClipboardManager.isFormulaObject(s)) {
    hiddenInput.setTextWatcher(false);
    listChangeIf.onPalettePressed(s);
    return;
  }
  final String termSep=context.getResources().getString(R.string.formula_term_separator);
  final String code=(termSep.equals(s)) ? FormulaBase.BaseType.TERM.toString() : FormulaTerm.getOperatorCode(context,s,true);
  if (code == null) {
    return;
  }
  if (UserFunctions.FunctionType.FUNCTION_LINK.toString().equalsIgnoreCase(code)) {
    hiddenInput.setTextWatcher(false);
    listChangeIf.onPalettePressed(s);
    return;
  }
  for (int i=0; i < paletteLayout.getChildCount(); i++) {
    if (paletteLayout.getChildAt(i) instanceof PaletteButton) {
      PaletteButton b=(PaletteButton)paletteLayout.getChildAt(i);
      if (b.isEnabled() && b.getCode() != null && b.getCode().equalsIgnoreCase(code)) {
        hiddenInput.setTextWatcher(false);
        listChangeIf.onPalettePressed(b.getCode());
        break;
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onTextChanged(String s,boolean isManualInput){
  if (s == null || listChangeIf == null) {
    lastHiddenInput=null;
    return;
  }
  if (lastHiddenInput != null && lastHiddenInput.equals(s)) {
    return;
  }
  lastHiddenInput=s;
  if (ClipboardManager.isFormulaObject(s)) {
    hiddenInput.setTextWatcher(false);
    listChangeIf.onPalettePressed(s);
    return;
  }
  final String termSep=context.getResources().getString(R.string.formula_term_separator);
  final TermTypeIf term=FormulaTerm.getTermTypeIf(context,null,s,true);
  final String code=(termSep.equals(s)) ? FormulaBase.BaseType.TERM.toString() : ((term != null) ? term.getLowerCaseName() : null);
  if (code == null) {
    return;
  }
  if (UserFunctions.FunctionType.FUNCTION_LINK.toString().equalsIgnoreCase(code)) {
    hiddenInput.setTextWatcher(false);
    listChangeIf.onPalettePressed(s);
    return;
  }
  for (  PaletteButton b : termButtons) {
    if (b.isEnabled() && b.getCode() != null && b.getCode().equalsIgnoreCase(code)) {
      hiddenInput.setTextWatcher(false);
      listChangeIf.onPalettePressed(b.getCode());
      break;
    }
  }
}
Program: 170932
Project: 170932
Buggy source:
/** 
 * Procedure sets the background color for all buttons depending on enabled status
 */
private void updateButtonsColor(){
  for (int i=0; i < paletteLayout.getChildCount(); i++) {
    if (!(paletteLayout.getChildAt(i) instanceof PaletteButton)) {
      continue;
    }
    PaletteButton b=(PaletteButton)paletteLayout.getChildAt(i);
    final boolean isEnabled=b.isEnabled() && paletteLayout.isEnabled();
    ViewUtils.setImageButtonColorAttr(context,b,isEnabled ? R.attr.colorMicroMathIcon : R.attr.colorPrimaryDark);
  }
}

Fixed version (ground truth):
/** 
 * Procedure sets the background color for all buttons depending on enabled status
 */
private void updateButtonsColor(){
  for (  PaletteButton b : termButtons) {
    final boolean isEnabled=b.isEnabled() && paletteLayout.isEnabled();
    ViewUtils.setImageButtonColorAttr(context,b,isEnabled ? R.attr.colorMicroMathIcon : R.attr.colorPrimaryDark);
  }
}