Program: 43249
Project: 43249
Buggy source:
boolean adjustWallpaperWindowsLocked(){
  boolean changed=false;
  final int dw=mDisplay.getWidth();
  final int dh=mDisplay.getHeight();
  final ArrayList localmWindows=mWindows;
  int N=localmWindows.size();
  WindowState w=null;
  WindowState foundW=null;
  int foundI=0;
  int i=N;
  while (i > 0) {
    i--;
    w=(WindowState)localmWindows.get(i);
    if (w.mAppToken != null) {
      if (w.mAppToken.hidden && w.mAppToken.animation == null) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w);
        continue;
      }
      if (!w.mAppToken.appFullscreen) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w);
        continue;
      }
    }
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + w + "String_Node_Str"+ w.isReadyForDisplay()+ "String_Node_Str"+ w.mDrawPending+ "String_Node_Str"+ w.mCommitDrawPending);
    if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() && !w.mDrawPending && !w.mCommitDrawPending) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
      foundW=w;
      foundI=i;
      if (w == mWallpaperTarget && w.mAppToken != null && w.mAppToken.animation != null) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w + "String_Node_Str");
        continue;
      }
      break;
    }
  }
  if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
    if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return false;
    }
    if (foundW != null && foundW.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return false;
    }
  }
  if (mWallpaperTarget != foundW) {
    if (DEBUG_WALLPAPER) {
      Log.v(TAG,"String_Node_Str" + foundW + "String_Node_Str"+ mWallpaperTarget);
    }
    mLowerWallpaperTarget=null;
    mUpperWallpaperTarget=null;
    WindowState oldW=mWallpaperTarget;
    mWallpaperTarget=foundW;
    if (foundW != null && foundW.mAppToken != null && oldW != null && oldW.mAppToken != null) {
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str" + foundW.mAppToken.animation + "String_Node_Str"+ oldW.mAppToken.animation);
      }
      if (foundW.mAppToken.animation != null && oldW.mAppToken.animation != null) {
        int oldI=localmWindows.indexOf(oldW);
        if (DEBUG_WALLPAPER) {
          Log.v(TAG,"String_Node_Str" + foundI + "String_Node_Str"+ oldI);
        }
        if (oldI >= 0) {
          if (DEBUG_WALLPAPER) {
            Log.v(TAG,"String_Node_Str" + oldI + "String_Node_Str"+ oldW+ "String_Node_Str"+ foundI+ "String_Node_Str"+ foundW);
          }
          if (foundW.mAppToken.hiddenRequested) {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mWallpaperTarget=oldW;
          }
          if (foundI > oldI) {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=foundW;
            mLowerWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=oldW;
            mLowerWallpaperTarget=foundW;
          }
        }
      }
    }
  }
 else {
    if (mLowerWallpaperTarget == null || mLowerWallpaperTarget.mAppToken.animation == null || mUpperWallpaperTarget == null || mUpperWallpaperTarget.mAppToken.animation == null) {
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str");
      }
      mLowerWallpaperTarget=null;
      mUpperWallpaperTarget=null;
    }
  }
  boolean visible=foundW != null;
  if (visible) {
    visible=!foundW.mObscured;
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + visible);
    mWallpaperAnimLayerAdjustment=(mLowerWallpaperTarget == null && foundW.mAppToken != null) ? foundW.mAppToken.animLayerAdjustment : 0;
    while (foundI > 0) {
      WindowState wb=(WindowState)localmWindows.get(foundI - 1);
      if (wb.mAttachedWindow != foundW && (wb.mAttrs.type != TYPE_APPLICATION_STARTING || wb.mToken != foundW.mToken)) {
        break;
      }
      foundW=wb;
      foundI--;
    }
  }
  foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
  int curTokenIndex=mWallpaperTokens.size();
  while (curTokenIndex > 0) {
    curTokenIndex--;
    WindowToken token=mWallpaperTokens.get(curTokenIndex);
    int curWallpaperIndex=token.windows.size();
    while (curWallpaperIndex > 0) {
      curWallpaperIndex--;
      WindowState wallpaper=token.windows.get(curWallpaperIndex);
      if (visible) {
        updateWallpaperOffsetLocked(mWallpaperTarget,wallpaper,dw,dh);
      }
      if (wallpaper.mWallpaperVisible != visible) {
        wallpaper.mWallpaperVisible=visible;
        try {
          if (DEBUG_VISIBILITY || DEBUG_WALLPAPER)           Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ visible);
          wallpaper.mClient.dispatchAppVisibility(visible);
        }
 catch (        RemoteException e) {
        }
      }
      wallpaper.mAnimLayer=wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
      if (DEBUG_LAYERS || DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ wallpaper.mAnimLayer);
      if (wallpaper == foundW) {
        foundI--;
        foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
        continue;
      }
      int oldIndex=localmWindows.indexOf(wallpaper);
      if (oldIndex >= 0) {
        localmWindows.remove(oldIndex);
        if (oldIndex < foundI) {
          foundI--;
        }
      }
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ oldIndex+ "String_Node_Str"+ foundI);
      localmWindows.add(foundI,wallpaper);
      changed=true;
    }
  }
  return changed;
}

Fixed version (ground truth):
boolean adjustWallpaperWindowsLocked(){
  boolean changed=false;
  final int dw=mDisplay.getWidth();
  final int dh=mDisplay.getHeight();
  final ArrayList localmWindows=mWindows;
  int N=localmWindows.size();
  WindowState w=null;
  WindowState foundW=null;
  int foundI=0;
  int i=N;
  while (i > 0) {
    i--;
    w=(WindowState)localmWindows.get(i);
    if (w.mAppToken != null) {
      if (w.mAppToken.hidden && w.mAppToken.animation == null) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w);
        continue;
      }
      if (!w.mAppToken.appFullscreen) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w);
        continue;
      }
    }
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + w + "String_Node_Str"+ w.isReadyForDisplay()+ "String_Node_Str"+ w.mDrawPending+ "String_Node_Str"+ w.mCommitDrawPending);
    if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() && (mWallpaperTarget == w || (!w.mDrawPending && !w.mCommitDrawPending))) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
      foundW=w;
      foundI=i;
      if (w == mWallpaperTarget && w.mAppToken != null && w.mAppToken.animation != null) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w + "String_Node_Str");
        continue;
      }
      break;
    }
  }
  if (mNextAppTransition != WindowManagerPolicy.TRANSIT_NONE) {
    if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return false;
    }
    if (foundW != null && foundW.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return false;
    }
  }
  if (mWallpaperTarget != foundW) {
    if (DEBUG_WALLPAPER) {
      Log.v(TAG,"String_Node_Str" + foundW + "String_Node_Str"+ mWallpaperTarget);
    }
    mLowerWallpaperTarget=null;
    mUpperWallpaperTarget=null;
    WindowState oldW=mWallpaperTarget;
    mWallpaperTarget=foundW;
    if (foundW != null && foundW.mAppToken != null && oldW != null && oldW.mAppToken != null) {
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str" + foundW.mAppToken.animation + "String_Node_Str"+ oldW.mAppToken.animation);
      }
      if (foundW.mAppToken.animation != null && oldW.mAppToken.animation != null) {
        int oldI=localmWindows.indexOf(oldW);
        if (DEBUG_WALLPAPER) {
          Log.v(TAG,"String_Node_Str" + foundI + "String_Node_Str"+ oldI);
        }
        if (oldI >= 0) {
          if (DEBUG_WALLPAPER) {
            Log.v(TAG,"String_Node_Str" + oldI + "String_Node_Str"+ oldW+ "String_Node_Str"+ foundI+ "String_Node_Str"+ foundW);
          }
          if (foundW.mAppToken.hiddenRequested) {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mWallpaperTarget=oldW;
          }
          if (foundI > oldI) {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=foundW;
            mLowerWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=oldW;
            mLowerWallpaperTarget=foundW;
          }
        }
      }
    }
  }
 else {
    if (mLowerWallpaperTarget == null || mLowerWallpaperTarget.mAppToken.animation == null || mUpperWallpaperTarget == null || mUpperWallpaperTarget.mAppToken.animation == null) {
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str");
      }
      mLowerWallpaperTarget=null;
      mUpperWallpaperTarget=null;
    }
  }
  boolean visible=foundW != null;
  if (visible) {
    visible=!foundW.mObscured;
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + visible);
    mWallpaperAnimLayerAdjustment=(mLowerWallpaperTarget == null && foundW.mAppToken != null) ? foundW.mAppToken.animLayerAdjustment : 0;
    while (foundI > 0) {
      WindowState wb=(WindowState)localmWindows.get(foundI - 1);
      if (wb.mAttachedWindow != foundW && (wb.mAttrs.type != TYPE_APPLICATION_STARTING || wb.mToken != foundW.mToken)) {
        break;
      }
      foundW=wb;
      foundI--;
    }
  }
  foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
  int curTokenIndex=mWallpaperTokens.size();
  while (curTokenIndex > 0) {
    curTokenIndex--;
    WindowToken token=mWallpaperTokens.get(curTokenIndex);
    int curWallpaperIndex=token.windows.size();
    while (curWallpaperIndex > 0) {
      curWallpaperIndex--;
      WindowState wallpaper=token.windows.get(curWallpaperIndex);
      if (visible) {
        updateWallpaperOffsetLocked(mWallpaperTarget,wallpaper,dw,dh);
      }
      if (wallpaper.mWallpaperVisible != visible) {
        wallpaper.mWallpaperVisible=visible;
        try {
          if (DEBUG_VISIBILITY || DEBUG_WALLPAPER)           Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ visible);
          wallpaper.mClient.dispatchAppVisibility(visible);
        }
 catch (        RemoteException e) {
        }
      }
      wallpaper.mAnimLayer=wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
      if (DEBUG_LAYERS || DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ wallpaper.mAnimLayer);
      if (wallpaper == foundW) {
        foundI--;
        foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
        continue;
      }
      int oldIndex=localmWindows.indexOf(wallpaper);
      if (oldIndex >= 0) {
        localmWindows.remove(oldIndex);
        if (oldIndex < foundI) {
          foundI--;
        }
      }
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ oldIndex+ "String_Node_Str"+ foundI);
      localmWindows.add(foundI,wallpaper);
      changed=true;
    }
  }
  return changed;
}