Program: 111523
Project: 111523
Buggy source:
public void writeKeyEvent(KeyEvent ev){
  int keysym=0, keycode, key, location;
  if (shuttingDown)   return;
  boolean down=(ev.getID() == KeyEvent.KEY_PRESSED);
  keycode=ev.getKeyCode();
  key=ev.getKeyChar();
  location=ev.getKeyLocation();
  String fmt=ev.paramString().replaceAll("String_Node_Str","String_Node_Str");
  vlog.debug(String.format(fmt.replaceAll("String_Node_Str","String_Node_Str")));
  if (!ev.isActionKey()) {
    if (keycode >= KeyEvent.VK_0 && keycode <= KeyEvent.VK_9 && location == KeyEvent.KEY_LOCATION_NUMPAD)     keysym=Keysyms.KP_0 + keycode - KeyEvent.VK_0;
switch (keycode) {
case KeyEvent.VK_BACK_SPACE:
      keysym=Keysyms.BackSpace;
    break;
case KeyEvent.VK_TAB:
  keysym=Keysyms.Tab;
break;
case KeyEvent.VK_ENTER:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Enter;
 else keysym=Keysyms.Return;
break;
case KeyEvent.VK_ESCAPE:
keysym=Keysyms.Escape;
break;
case KeyEvent.VK_NUMPAD0:
keysym=Keysyms.KP_0;
break;
case KeyEvent.VK_NUMPAD1:
keysym=Keysyms.KP_1;
break;
case KeyEvent.VK_NUMPAD2:
keysym=Keysyms.KP_2;
break;
case KeyEvent.VK_NUMPAD3:
keysym=Keysyms.KP_3;
break;
case KeyEvent.VK_NUMPAD4:
keysym=Keysyms.KP_4;
break;
case KeyEvent.VK_NUMPAD5:
keysym=Keysyms.KP_5;
break;
case KeyEvent.VK_NUMPAD6:
keysym=Keysyms.KP_6;
break;
case KeyEvent.VK_NUMPAD7:
keysym=Keysyms.KP_7;
break;
case KeyEvent.VK_NUMPAD8:
keysym=Keysyms.KP_8;
break;
case KeyEvent.VK_NUMPAD9:
keysym=Keysyms.KP_9;
break;
case KeyEvent.VK_DECIMAL:
keysym=Keysyms.KP_Decimal;
break;
case KeyEvent.VK_ADD:
keysym=Keysyms.KP_Add;
break;
case KeyEvent.VK_SUBTRACT:
keysym=Keysyms.KP_Subtract;
break;
case KeyEvent.VK_MULTIPLY:
keysym=Keysyms.KP_Multiply;
break;
case KeyEvent.VK_DIVIDE:
keysym=Keysyms.KP_Divide;
break;
case KeyEvent.VK_DELETE:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Delete;
 else keysym=Keysyms.Delete;
break;
case KeyEvent.VK_CLEAR:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Begin;
 else keysym=Keysyms.Clear;
break;
case KeyEvent.VK_CONTROL:
if (ev.isAltGraphDown()) return;
if (down) modifiers|=Event.CTRL_MASK;
 else modifiers&=~Event.CTRL_MASK;
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Control_R;
 else keysym=Keysyms.Control_L;
break;
case KeyEvent.VK_ALT:
if (ev.isAltGraphDown()) return;
if (down) modifiers|=Event.ALT_MASK;
 else modifiers&=~Event.ALT_MASK;
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Alt_R;
 else keysym=Keysyms.Alt_L;
break;
case KeyEvent.VK_SHIFT:
if (down) modifiers|=Event.SHIFT_MASK;
 else modifiers&=~Event.SHIFT_MASK;
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Shift_R;
 else keysym=Keysyms.Shift_L;
break;
case KeyEvent.VK_META:
if (down) modifiers|=Event.META_MASK;
 else modifiers&=~Event.META_MASK;
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Meta_R;
 else keysym=Keysyms.Meta_L;
break;
default :
if (ev.isControlDown()) {
if ((key >= 1 && key <= 26 && !ev.isShiftDown()) || (key >= 27 && key <= 29 && ev.isShiftDown())) key+=96;
 else if (key < 32) key+=64;
 else if (key == KeyEvent.CHAR_UNDEFINED && keycode >= 0 && keycode <= 127) key=keycode;
}
keysym=UnicodeToKeysym.translate(key);
if (keysym == -1) return;
}
}
 else {
switch (keycode) {
case KeyEvent.VK_HOME:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Home;
 else keysym=Keysyms.Home;
break;
case KeyEvent.VK_END:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_End;
 else keysym=Keysyms.End;
break;
case KeyEvent.VK_PAGE_UP:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Page_Up;
 else keysym=Keysyms.Page_Up;
break;
case KeyEvent.VK_PAGE_DOWN:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Page_Down;
 else keysym=Keysyms.Page_Down;
break;
case KeyEvent.VK_UP:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Up;
 else keysym=Keysyms.Up;
break;
case KeyEvent.VK_DOWN:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Down;
 else keysym=Keysyms.Down;
break;
case KeyEvent.VK_LEFT:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Left;
 else keysym=Keysyms.Left;
break;
case KeyEvent.VK_RIGHT:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Right;
 else keysym=Keysyms.Right;
break;
case KeyEvent.VK_F1:
keysym=Keysyms.F1;
break;
case KeyEvent.VK_F2:
keysym=Keysyms.F2;
break;
case KeyEvent.VK_F3:
keysym=Keysyms.F3;
break;
case KeyEvent.VK_F4:
keysym=Keysyms.F4;
break;
case KeyEvent.VK_F5:
keysym=Keysyms.F5;
break;
case KeyEvent.VK_F6:
keysym=Keysyms.F6;
break;
case KeyEvent.VK_F7:
keysym=Keysyms.F7;
break;
case KeyEvent.VK_F8:
keysym=Keysyms.F8;
break;
case KeyEvent.VK_F9:
keysym=Keysyms.F9;
break;
case KeyEvent.VK_F10:
keysym=Keysyms.F10;
break;
case KeyEvent.VK_F11:
keysym=Keysyms.F11;
break;
case KeyEvent.VK_F12:
keysym=Keysyms.F12;
break;
case KeyEvent.VK_F13:
keysym=Keysyms.F13;
break;
case KeyEvent.VK_PRINTSCREEN:
keysym=Keysyms.Print;
break;
case KeyEvent.VK_PAUSE:
if (ev.isControlDown()) keysym=Keysyms.Break;
 else keysym=Keysyms.Pause;
break;
case KeyEvent.VK_INSERT:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Insert;
 else keysym=Keysyms.Insert;
break;
case KeyEvent.VK_KP_DOWN:
keysym=Keysyms.KP_Down;
break;
case KeyEvent.VK_KP_LEFT:
keysym=Keysyms.KP_Left;
break;
case KeyEvent.VK_KP_RIGHT:
keysym=Keysyms.KP_Right;
break;
case KeyEvent.VK_KP_UP:
keysym=Keysyms.KP_Up;
break;
case KeyEvent.VK_NUM_LOCK:
keysym=Keysyms.Num_Lock;
break;
case KeyEvent.VK_WINDOWS:
keysym=Keysyms.Super_L;
break;
case KeyEvent.VK_CONTEXT_MENU:
keysym=Keysyms.Menu;
break;
case KeyEvent.VK_SCROLL_LOCK:
keysym=Keysyms.Scroll_Lock;
break;
case KeyEvent.VK_CAPS_LOCK:
keysym=Keysyms.Caps_Lock;
break;
case KeyEvent.VK_BEGIN:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Begin;
 else keysym=Keysyms.Begin;
break;
default :
return;
}
}
writeKeyEvent(keysym,down);
}

Fixed version (ground truth):
public void writeKeyEvent(KeyEvent ev){
  int keysym=0, keycode, key, location, locationShift;
  if (shuttingDown)   return;
  boolean down=(ev.getID() == KeyEvent.KEY_PRESSED);
  keycode=ev.getKeyCode();
  if (keycode == KeyEvent.VK_UNDEFINED)   return;
  key=ev.getKeyChar();
  location=ev.getKeyLocation();
  if (location == KeyEvent.KEY_LOCATION_RIGHT)   locationShift=KEY_LOC_SHIFT_R;
 else   locationShift=KEY_LOC_SHIFT_L;
  if (!ev.isActionKey()) {
    if (keycode >= KeyEvent.VK_0 && keycode <= KeyEvent.VK_9 && location == KeyEvent.KEY_LOCATION_NUMPAD)     keysym=Keysyms.KP_0 + keycode - KeyEvent.VK_0;
switch (keycode) {
case KeyEvent.VK_BACK_SPACE:
      keysym=Keysyms.BackSpace;
    break;
case KeyEvent.VK_TAB:
  keysym=Keysyms.Tab;
break;
case KeyEvent.VK_ENTER:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Enter;
 else keysym=Keysyms.Return;
break;
case KeyEvent.VK_ESCAPE:
keysym=Keysyms.Escape;
break;
case KeyEvent.VK_NUMPAD0:
keysym=Keysyms.KP_0;
break;
case KeyEvent.VK_NUMPAD1:
keysym=Keysyms.KP_1;
break;
case KeyEvent.VK_NUMPAD2:
keysym=Keysyms.KP_2;
break;
case KeyEvent.VK_NUMPAD3:
keysym=Keysyms.KP_3;
break;
case KeyEvent.VK_NUMPAD4:
keysym=Keysyms.KP_4;
break;
case KeyEvent.VK_NUMPAD5:
keysym=Keysyms.KP_5;
break;
case KeyEvent.VK_NUMPAD6:
keysym=Keysyms.KP_6;
break;
case KeyEvent.VK_NUMPAD7:
keysym=Keysyms.KP_7;
break;
case KeyEvent.VK_NUMPAD8:
keysym=Keysyms.KP_8;
break;
case KeyEvent.VK_NUMPAD9:
keysym=Keysyms.KP_9;
break;
case KeyEvent.VK_DECIMAL:
keysym=Keysyms.KP_Decimal;
break;
case KeyEvent.VK_ADD:
keysym=Keysyms.KP_Add;
break;
case KeyEvent.VK_SUBTRACT:
keysym=Keysyms.KP_Subtract;
break;
case KeyEvent.VK_MULTIPLY:
keysym=Keysyms.KP_Multiply;
break;
case KeyEvent.VK_DIVIDE:
keysym=Keysyms.KP_Divide;
break;
case KeyEvent.VK_DELETE:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Delete;
 else keysym=Keysyms.Delete;
break;
case KeyEvent.VK_CLEAR:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Begin;
 else keysym=Keysyms.Clear;
break;
case KeyEvent.VK_CONTROL:
if (down) modifiers|=(Event.CTRL_MASK << locationShift);
 else modifiers&=~(Event.CTRL_MASK << locationShift);
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Control_R;
 else keysym=Keysyms.Control_L;
break;
case KeyEvent.VK_ALT:
if (down) modifiers|=(Event.ALT_MASK << locationShift);
 else modifiers&=~(Event.ALT_MASK << locationShift);
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Alt_R;
 else keysym=Keysyms.Alt_L;
break;
case KeyEvent.VK_SHIFT:
if (down) modifiers|=(Event.SHIFT_MASK << locationShift);
 else modifiers&=~(Event.SHIFT_MASK << locationShift);
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Shift_R;
 else keysym=Keysyms.Shift_L;
break;
case KeyEvent.VK_META:
if (down) modifiers|=(Event.META_MASK << locationShift);
 else modifiers&=~(Event.META_MASK << locationShift);
if (location == KeyEvent.KEY_LOCATION_RIGHT) keysym=Keysyms.Meta_R;
 else keysym=Keysyms.Meta_L;
break;
default :
if (ev.isControlDown()) {
if ((key >= 1 && key <= 26 && !ev.isShiftDown()) || (key >= 27 && key <= 29 && ev.isShiftDown())) key+=96;
 else if (key < 32) key+=64;
 else if (key == KeyEvent.CHAR_UNDEFINED && keycode >= 0 && keycode <= 127) key=keycode;
}
keysym=UnicodeToKeysym.translate(key);
if (keysym == -1) return;
}
}
 else {
switch (keycode) {
case KeyEvent.VK_HOME:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Home;
 else keysym=Keysyms.Home;
break;
case KeyEvent.VK_END:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_End;
 else keysym=Keysyms.End;
break;
case KeyEvent.VK_PAGE_UP:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Page_Up;
 else keysym=Keysyms.Page_Up;
break;
case KeyEvent.VK_PAGE_DOWN:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Page_Down;
 else keysym=Keysyms.Page_Down;
break;
case KeyEvent.VK_UP:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Up;
 else keysym=Keysyms.Up;
break;
case KeyEvent.VK_DOWN:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Down;
 else keysym=Keysyms.Down;
break;
case KeyEvent.VK_LEFT:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Left;
 else keysym=Keysyms.Left;
break;
case KeyEvent.VK_RIGHT:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Right;
 else keysym=Keysyms.Right;
break;
case KeyEvent.VK_BEGIN:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Begin;
 else keysym=Keysyms.Begin;
break;
case KeyEvent.VK_KP_LEFT:
keysym=Keysyms.KP_Left;
break;
case KeyEvent.VK_KP_UP:
keysym=Keysyms.KP_Up;
break;
case KeyEvent.VK_KP_RIGHT:
keysym=Keysyms.KP_Right;
break;
case KeyEvent.VK_KP_DOWN:
keysym=Keysyms.KP_Down;
break;
case KeyEvent.VK_F1:
keysym=Keysyms.F1;
break;
case KeyEvent.VK_F2:
keysym=Keysyms.F2;
break;
case KeyEvent.VK_F3:
keysym=Keysyms.F3;
break;
case KeyEvent.VK_F4:
keysym=Keysyms.F4;
break;
case KeyEvent.VK_F5:
keysym=Keysyms.F5;
break;
case KeyEvent.VK_F6:
keysym=Keysyms.F6;
break;
case KeyEvent.VK_F7:
keysym=Keysyms.F7;
break;
case KeyEvent.VK_F8:
keysym=Keysyms.F8;
break;
case KeyEvent.VK_F9:
keysym=Keysyms.F9;
break;
case KeyEvent.VK_F10:
keysym=Keysyms.F10;
break;
case KeyEvent.VK_F11:
keysym=Keysyms.F11;
break;
case KeyEvent.VK_F12:
keysym=Keysyms.F12;
break;
case KeyEvent.VK_F13:
keysym=Keysyms.F13;
break;
case KeyEvent.VK_F14:
keysym=Keysyms.F14;
break;
case KeyEvent.VK_F15:
keysym=Keysyms.F15;
break;
case KeyEvent.VK_F16:
keysym=Keysyms.F16;
break;
case KeyEvent.VK_F17:
keysym=Keysyms.F17;
break;
case KeyEvent.VK_F18:
keysym=Keysyms.F18;
break;
case KeyEvent.VK_F19:
keysym=Keysyms.F19;
break;
case KeyEvent.VK_F20:
keysym=Keysyms.F20;
break;
case KeyEvent.VK_F21:
keysym=Keysyms.F21;
break;
case KeyEvent.VK_F22:
keysym=Keysyms.F22;
break;
case KeyEvent.VK_F23:
keysym=Keysyms.F23;
break;
case KeyEvent.VK_F24:
keysym=Keysyms.F24;
break;
case KeyEvent.VK_PRINTSCREEN:
keysym=Keysyms.Print;
break;
case KeyEvent.VK_SCROLL_LOCK:
keysym=Keysyms.Scroll_Lock;
break;
case KeyEvent.VK_CAPS_LOCK:
keysym=Keysyms.Caps_Lock;
break;
case KeyEvent.VK_NUM_LOCK:
keysym=Keysyms.Num_Lock;
break;
case KeyEvent.VK_PAUSE:
if (ev.isControlDown()) keysym=Keysyms.Break;
 else keysym=Keysyms.Pause;
break;
case KeyEvent.VK_INSERT:
if (location == KeyEvent.KEY_LOCATION_NUMPAD) keysym=Keysyms.KP_Insert;
 else keysym=Keysyms.Insert;
break;
case KeyEvent.VK_KANJI:
keysym=Keysyms.Kanji;
break;
case KeyEvent.VK_KATAKANA:
keysym=Keysyms.Katakana;
break;
case KeyEvent.VK_HIRAGANA:
keysym=Keysyms.Hiragana;
break;
case KeyEvent.VK_PREVIOUS_CANDIDATE:
keysym=Keysyms.PreviousCandidate;
break;
case KeyEvent.VK_CODE_INPUT:
keysym=Keysyms.Codeinput;
break;
case KeyEvent.VK_JAPANESE_ROMAN:
keysym=Keysyms.Romaji;
break;
case KeyEvent.VK_KANA_LOCK:
keysym=Keysyms.Kana_Lock;
break;
case KeyEvent.VK_AGAIN:
keysym=Keysyms.Redo;
break;
case KeyEvent.VK_UNDO:
keysym=Keysyms.Undo;
break;
case KeyEvent.VK_FIND:
keysym=Keysyms.Find;
break;
case KeyEvent.VK_STOP:
keysym=Keysyms.Cancel;
break;
case KeyEvent.VK_HELP:
keysym=Keysyms.Help;
break;
case KeyEvent.VK_WINDOWS:
if (down) modifiers|=SUPER_MASK;
 else modifiers&=~SUPER_MASK;
keysym=Keysyms.Super_L;
break;
case KeyEvent.VK_CONTEXT_MENU:
keysym=Keysyms.Menu;
break;
default :
return;
}
}
if (keysym > 0) {
String fmt=ev.paramString().replaceAll("String_Node_Str","String_Node_Str");
vlog.debug(String.format(fmt.replaceAll("String_Node_Str","String_Node_Str")));
writeKeyEvent(keysym,down);
}
}