Program: 80562
Project: 80562
Buggy source:
static void updateAppWidget(Context context,AppWidgetManager appWidgetManager,int appWidgetId,Bundle options){
  Tools.HangarLog("String_Node_Str");
  prefs=new PrefsGet(context.getSharedPreferences("String_Node_Str",Context.MODE_PRIVATE));
  SharedPreferences mPrefs=prefs.prefsGet();
  int rowLayout=R.layout.apps_widget_row;
  int itemLayout=R.layout.apps_widget_item;
  int itemHeight=ICON_MEDIUM_HEIGHT;
  int itemWidth=ICON_MEDIUM_WIDTH;
  int iconSize=Integer.parseInt(mPrefs.getString(Settings.ICON_SIZE_PREFERENCE,Integer.toString(Settings.ICON_SIZE_DEFAULT)));
  int mGravity=Integer.parseInt(mPrefs.getString(Settings.ALIGNMENT_PREFERENCE,Integer.toString(Settings.ALIGNMENT_DEFAULT)));
switch (iconSize) {
case SMALL_ICONS:
    rowLayout=R.layout.apps_widget_row_small;
  itemHeight=ICON_SMALL_HEIGHT;
itemWidth=ICON_SMALL_WIDTH;
break;
case LARGE_ICONS:
rowLayout=R.layout.apps_widget_row_large;
itemHeight=ICON_LARGE_HEIGHT;
itemWidth=ICON_LARGE_WIDTH;
break;
}
boolean appsNoByWidgetSize=mPrefs.getBoolean(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE,Settings.APPS_BY_WIDGET_SIZE_DEFAULT);
int appsNoH;
int appsNoW;
boolean autoHeight=true;
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH));
appsNoH=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT),itemHeight);
appsNoW=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH),itemWidth);
Tools.HangarLog("String_Node_Str" + appsNoH + "String_Node_Str"+ appsNoW);
if (appsNoH == 0) {
appsNoH=1;
autoHeight=false;
}
if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
float widgetHeight=options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
appsNoH=findDimensions((int)widgetHeight,itemHeight);
int origWidgetHeight=appsNoH;
if (iconSize > SMALL_ICONS) {
if (iconSize == LARGE_ICONS) {
appsNoH=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT),itemHeight);
if (appsNoH == 0 && widgetHeight > 0) {
Tools.HangarLog("String_Node_Str");
rowLayout=R.layout.apps_widget_row;
itemWidth=ICON_MEDIUM_WIDTH;
}
}
if (itemWidth == ICON_MEDIUM_WIDTH) {
appsNoH=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT),ICON_MEDIUM_HEIGHT);
if (appsNoH == 0 && widgetHeight > 0) {
Tools.HangarLog("String_Node_Str");
rowLayout=R.layout.apps_widget_row_small;
itemWidth=ICON_SMALL_WIDTH;
mGravity=Settings.ALIGNMENT_DEFAULT;
}
}
}
if (origWidgetHeight == 0) {
appsNoH=1;
autoHeight=false;
}
appsNoW=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH),itemWidth);
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoW);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE,Integer.toString(Settings.APPS_WIDGET_APPSNO_LS_DEFAULT)));
}
Tools.HangarLog("String_Node_Str");
}
 else {
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoH);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_PREFERENCE,Integer.toString(Settings.APPS_WIDGET_APPSNO_DEFAULT)));
}
}
int getBackgroundColor=mPrefs.getInt(Settings.BACKGROUND_COLOR_PREFERENCE,Settings.BACKGROUND_COLOR_DEFAULT);
RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.apps_widget);
views.setInt(R.id.viewCont,"String_Node_Str",mGravity);
if (db == null) {
db=new TasksDataSource(context);
db.open();
}
int gridSize=(appsNoH * appsNoW);
int numOfIcons=(appsNoH * appsNoW > Settings.TASKLIST_QUEUE_SIZE) ? Settings.TASKLIST_QUEUE_SIZE : (appsNoH * appsNoW);
if (autoHeight && !appsNoByWidgetSize) {
numOfIcons=appsNoW;
}
int queueSize=(Math.ceil(numOfIcons * 1.2f)) < Settings.APPLIST_QUEUE_SIZE ? Settings.APPLIST_QUEUE_SIZE : (int)Math.ceil(numOfIcons * 1.2f);
String taskPackage=context.getPackageName();
boolean weightedRecents=mPrefs.getBoolean(Settings.WEIGHTED_RECENTS_PREFERENCE,Settings.WEIGHTED_RECENTS_DEFAULT);
ArrayList<Tools.TaskInfo> appList=Tools.buildTaskList(context,db,queueSize,weightedRecents,true);
boolean ignorePinned=mPrefs.getBoolean(Settings.IGNORE_PINNED_PREFERENCE,Settings.IGNORE_PINNED_DEFAULT);
if (!ignorePinned) {
ArrayList<Tools.TaskInfo> pinnedList=Tools.buildPinnedList(mContext,db);
appList=new Tools().getPinnedTasks(context,pinnedList,appList,numOfIcons);
}
int imageButtonLayout=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
int imageContLayout=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
AppDrawer appDrawer=new AppDrawer(taskPackage);
appDrawer.createRow(rowLayout,R.id.viewRow);
appDrawer.setImageLayouts(imageButtonLayout,imageContLayout);
appDrawer.setPrefs(mPrefs);
appDrawer.setContext(mContext);
appDrawer.setRowBackgroundColor(getBackgroundColor);
appDrawer.setCount(numOfIcons,Settings.TASKLIST_QUEUE_SIZE,true);
if (autoHeight && !appsNoByWidgetSize) {
appsNoW=(int)Math.ceil((double)appsNoW / appsNoH);
Tools.HangarLog("String_Node_Str" + appsNoW);
}
int filledConts=0;
int filledRows=1;
Tools.HangarLog("String_Node_Str" + appsNoW + "String_Node_Str"+ appList.size()+ "String_Node_Str"+ numOfIcons);
views.removeAllViews(R.id.viewCont);
for (int i=0; i <= gridSize; i++) {
if (filledConts == appsNoW || i == gridSize) {
Tools.HangarLog("String_Node_Str" + i + "String_Node_Str"+ filledConts);
views.addView(R.id.viewCont,appDrawer.getRow());
if (i >= numOfIcons && !appsNoByWidgetSize) break;
boolean lineBreak=(appsNoByWidgetSize && appList.size() > i) || (!appsNoByWidgetSize && numOfIcons > i);
if (filledRows < appsNoH && filledConts < numOfIcons && lineBreak) {
appDrawer.createRow(rowLayout,R.id.viewRow);
appDrawer.setRowBackgroundColor(getBackgroundColor);
filledConts=0;
filledRows++;
}
 else {
break;
}
}
Tools.TaskInfo newItemTask;
if (i >= appList.size()) {
newItemTask=new Tools.TaskInfo(null);
}
 else {
newItemTask=appList.get(i);
}
boolean newItem=appDrawer.newItem(newItemTask,itemLayout);
if (!newItem) {
numOfIcons++;
continue;
}
filledConts+=1;
if (i >= numOfIcons || i >= appList.size()) {
appDrawer.setItemVisibility(View.INVISIBLE);
appDrawer.addItem();
continue;
}
appDrawer.addItem();
}
appWidgetManager.updateAppWidget(appWidgetId,views);
}

Fixed version (ground truth):
static void updateAppWidget(Context context,AppWidgetManager appWidgetManager,int appWidgetId,Bundle options){
  Tools.HangarLog("String_Node_Str");
  prefs=new PrefsGet(context.getSharedPreferences("String_Node_Str",Context.MODE_PRIVATE));
  SharedPreferences mPrefs=prefs.prefsGet();
  int rowLayout=R.layout.apps_widget_row;
  int itemLayout=R.layout.apps_widget_item;
  int itemHeight=ICON_MEDIUM_HEIGHT;
  int itemWidth=ICON_MEDIUM_WIDTH;
  int iconSize=Integer.parseInt(mPrefs.getString(Settings.ICON_SIZE_PREFERENCE,Integer.toString(Settings.ICON_SIZE_DEFAULT)));
  int mGravity=Integer.parseInt(mPrefs.getString(Settings.ALIGNMENT_PREFERENCE,Integer.toString(Settings.ALIGNMENT_DEFAULT)));
switch (iconSize) {
case SMALL_ICONS:
    rowLayout=R.layout.apps_widget_row_small;
  itemHeight=ICON_SMALL_HEIGHT;
itemWidth=ICON_SMALL_WIDTH;
break;
case LARGE_ICONS:
rowLayout=R.layout.apps_widget_row_large;
itemHeight=ICON_LARGE_HEIGHT;
itemWidth=ICON_LARGE_WIDTH;
break;
}
boolean appsNoByWidgetSize=mPrefs.getBoolean(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE,Settings.APPS_BY_WIDGET_SIZE_DEFAULT);
int appsNoH;
int appsNoW;
boolean autoHeight=true;
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
Tools.HangarLog("String_Node_Str" + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH));
appsNoH=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT),itemHeight);
appsNoW=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH),itemWidth);
Tools.HangarLog("String_Node_Str" + appsNoH + "String_Node_Str"+ appsNoW);
if (appsNoH == 0) {
appsNoH=1;
autoHeight=false;
}
if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
float widgetHeight=options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
appsNoH=findDimensions((int)widgetHeight,itemHeight);
int origWidgetHeight=appsNoH;
if (iconSize > SMALL_ICONS) {
if (iconSize == LARGE_ICONS) {
appsNoH=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT),itemHeight);
if (appsNoH == 0 && widgetHeight > 0) {
Tools.HangarLog("String_Node_Str");
rowLayout=R.layout.apps_widget_row;
itemWidth=ICON_MEDIUM_WIDTH;
}
}
if (itemWidth == ICON_MEDIUM_WIDTH) {
appsNoH=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT),ICON_MEDIUM_HEIGHT);
if (appsNoH == 0 && widgetHeight > 0) {
Tools.HangarLog("String_Node_Str");
rowLayout=R.layout.apps_widget_row_small;
itemWidth=ICON_SMALL_WIDTH;
mGravity=Settings.ALIGNMENT_DEFAULT;
}
}
}
if (origWidgetHeight == 0) {
appsNoH=1;
autoHeight=false;
}
appsNoW=findDimensions(options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH),itemWidth);
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoW);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE,Integer.toString(Settings.APPS_WIDGET_APPSNO_LS_DEFAULT)));
}
Tools.HangarLog("String_Node_Str");
}
 else {
if (appsNoByWidgetSize && appsNoW > 0) {
Tools.HangarLog("String_Node_Str" + appsNoH);
}
 else {
appsNoW=Integer.parseInt(mPrefs.getString(Settings.STATS_WIDGET_APPSNO_PREFERENCE,Integer.toString(Settings.APPS_WIDGET_APPSNO_DEFAULT)));
}
}
int getBackgroundColor=mPrefs.getInt(Settings.BACKGROUND_COLOR_PREFERENCE,Settings.BACKGROUND_COLOR_DEFAULT);
RemoteViews views=new RemoteViews(context.getPackageName(),R.layout.apps_widget);
views.setInt(R.id.viewCont,"String_Node_Str",mGravity);
TasksDataSource db=new TasksDataSource(context);
db.open();
int gridSize=(appsNoH * appsNoW);
int numOfIcons=(appsNoH * appsNoW > Settings.TASKLIST_QUEUE_SIZE) ? Settings.TASKLIST_QUEUE_SIZE : (appsNoH * appsNoW);
if (autoHeight && !appsNoByWidgetSize) {
numOfIcons=appsNoW;
}
int queueSize=(Math.ceil(numOfIcons * 1.2f)) < Settings.APPLIST_QUEUE_SIZE ? Settings.APPLIST_QUEUE_SIZE : (int)Math.ceil(numOfIcons * 1.2f);
String taskPackage=context.getPackageName();
boolean weightedRecents=mPrefs.getBoolean(Settings.WEIGHTED_RECENTS_PREFERENCE,Settings.WEIGHTED_RECENTS_DEFAULT);
ArrayList<Tools.TaskInfo> appList=Tools.buildTaskList(context,db,queueSize,weightedRecents,true);
boolean ignorePinned=mPrefs.getBoolean(Settings.IGNORE_PINNED_PREFERENCE,Settings.IGNORE_PINNED_DEFAULT);
if (!ignorePinned) {
ArrayList<Tools.TaskInfo> pinnedList=Tools.buildPinnedList(mContext,db);
appList=new Tools().getPinnedTasks(context,pinnedList,appList,numOfIcons);
}
int imageButtonLayout=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
int imageContLayout=context.getResources().getIdentifier("String_Node_Str","String_Node_Str",taskPackage);
AppDrawer appDrawer=new AppDrawer(taskPackage);
appDrawer.createRow(rowLayout,R.id.viewRow);
appDrawer.setImageLayouts(imageButtonLayout,imageContLayout);
appDrawer.setPrefs(mPrefs);
appDrawer.setContext(mContext);
appDrawer.setRowBackgroundColor(getBackgroundColor);
appDrawer.setCount(numOfIcons,Settings.TASKLIST_QUEUE_SIZE,true);
if (autoHeight && !appsNoByWidgetSize) {
appsNoW=(int)Math.ceil((double)appsNoW / appsNoH);
Tools.HangarLog("String_Node_Str" + appsNoW);
}
int filledConts=0;
int filledRows=1;
Tools.HangarLog("String_Node_Str" + appsNoW + "String_Node_Str"+ appList.size()+ "String_Node_Str"+ numOfIcons);
views.removeAllViews(R.id.viewCont);
for (int i=0; i <= gridSize; i++) {
if (filledConts == appsNoW || i == gridSize) {
Tools.HangarLog("String_Node_Str" + i + "String_Node_Str"+ filledConts);
views.addView(R.id.viewCont,appDrawer.getRow());
if (i >= numOfIcons && !appsNoByWidgetSize) break;
boolean lineBreak=(appsNoByWidgetSize && appList.size() > i) || (!appsNoByWidgetSize && numOfIcons > i);
if (filledRows < appsNoH && filledConts < numOfIcons && lineBreak) {
appDrawer.createRow(rowLayout,R.id.viewRow);
appDrawer.setRowBackgroundColor(getBackgroundColor);
filledConts=0;
filledRows++;
}
 else {
break;
}
}
Tools.TaskInfo newItemTask;
if (i >= appList.size()) {
newItemTask=new Tools.TaskInfo(null);
}
 else {
newItemTask=appList.get(i);
}
boolean newItem=appDrawer.newItem(newItemTask,itemLayout);
if (!newItem) {
numOfIcons++;
continue;
}
filledConts+=1;
if (i >= numOfIcons || i >= appList.size()) {
appDrawer.setItemVisibility(View.INVISIBLE);
appDrawer.addItem();
continue;
}
appDrawer.addItem();
}
appWidgetManager.updateAppWidget(appWidgetId,views);
db.close();
}