Program: 111590
Project: 111590
Buggy source:
public void processNormalProtocol() throws Exception {
  viewer.checkRecordingStatus();
  rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,false);
  if (viewer.options.continuousUpdates) {
    rfb.tryEnableContinuousUpdates(0,0,rfb.framebufferWidth,rfb.framebufferHeight);
  }
  resetStats();
  boolean statsRestarted=false;
  while (true) {
    int msgType=rfb.readServerMessageType();
switch (msgType) {
case RfbProto.FramebufferUpdate:
      if (statNumUpdates == viewer.debugStatsExcludeUpdates && !statsRestarted) {
        resetStats();
        statsRestarted=true;
      }
 else       if (statNumUpdates == viewer.debugStatsMeasureUpdates && statsRestarted) {
        viewer.disconnect();
      }
    rfb.readFramebufferUpdate();
  statNumUpdates++;
boolean cursorPosReceived=false;
for (int i=0; i < rfb.updateNRects; i++) {
rfb.readFramebufferUpdateRectHdr();
statNumTotalRects++;
int rx=rfb.updateRectX, ry=rfb.updateRectY;
int rw=rfb.updateRectW, rh=rfb.updateRectH;
if (rfb.updateRectEncoding == rfb.EncodingLastRect) break;
if (rfb.updateRectEncoding == rfb.EncodingNewFBSize) {
  rfb.setFramebufferSize(rw,rh);
  updateFramebufferSize();
  break;
}
if (rfb.updateRectEncoding == rfb.EncodingXCursor || rfb.updateRectEncoding == rfb.EncodingRichCursor) {
  handleCursorShapeUpdate(rfb.updateRectEncoding,rx,ry,rw,rh);
  continue;
}
if (rfb.updateRectEncoding == rfb.EncodingPointerPos) {
  softCursorMove(rx,ry);
  cursorPosReceived=true;
  continue;
}
long numBytesReadBefore=rfb.getNumBytesRead();
rfb.startTiming();
switch (rfb.updateRectEncoding) {
case RfbProto.EncodingRaw:
  statNumRectsRaw++;
handleRawRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingCopyRect:
statNumRectsCopy++;
handleCopyRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingRRE:
handleRRERect(rx,ry,rw,rh);
break;
case RfbProto.EncodingCoRRE:
handleCoRRERect(rx,ry,rw,rh);
break;
case RfbProto.EncodingHextile:
statNumRectsHextile++;
handleHextileRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingZRLE:
statNumRectsZRLE++;
handleZRLERect(rx,ry,rw,rh);
break;
case RfbProto.EncodingZlib:
handleZlibRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingTight:
if (tightDecoder != null) {
statNumRectsTightJPEG=tightDecoder.getNumJPEGRects();
}
handleTightRect(rx,ry,rw,rh);
break;
default :
throw new Exception("String_Node_Str" + rfb.updateRectEncoding);
}
rfb.stopTiming();
statNumPixelRects++;
statNumBytesDecoded+=rw * rh * bytesPixel;
statNumBytesEncoded+=(int)(rfb.getNumBytesRead() - numBytesReadBefore);
}
boolean fullUpdateNeeded=false;
if (viewer.checkRecordingStatus()) fullUpdateNeeded=true;
if (viewer.deferUpdateRequests > 0 && rfb.available() == 0 && !cursorPosReceived) {
synchronized (rfb) {
try {
rfb.wait(viewer.deferUpdateRequests);
}
 catch (InterruptedException e) {
}
}
}
viewer.autoSelectEncodings();
if (viewer.options.eightBitColors != (bytesPixel == 1)) {
if (!rfb.continuousUpdatesAreActive()) {
setPixelFormat();
fullUpdateNeeded=true;
}
 else {
rfb.tryDisableContinuousUpdates();
break;
}
}
boolean enable=viewer.options.continuousUpdates;
if (enable != rfb.continuousUpdatesAreActive()) {
if (enable) {
rfb.tryEnableContinuousUpdates(0,0,rfb.framebufferWidth,rfb.framebufferHeight);
}
 else {
rfb.tryDisableContinuousUpdates();
}
}
if (fullUpdateNeeded) {
rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,false);
}
 else if (!rfb.continuousUpdatesAreActive()) {
rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,true);
}
break;
case RfbProto.SetColourMapEntries:
throw new Exception("String_Node_Str");
case RfbProto.Bell:
Toolkit.getDefaultToolkit().beep();
break;
case RfbProto.ServerCutText:
String s=rfb.readServerCutText();
viewer.clipboard.setCutText(s);
break;
case RfbProto.EndOfContinuousUpdates:
if (rfb.continuousUpdatesAreActive()) {
rfb.endOfContinuousUpdates();
boolean incremental=true;
if (viewer.options.eightBitColors != (bytesPixel == 1)) {
setPixelFormat();
incremental=false;
}
rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,incremental);
}
break;
default :
throw new Exception("String_Node_Str" + msgType);
}
}
}

Fixed version (ground truth):
public void processNormalProtocol() throws Exception {
  viewer.checkRecordingStatus();
  rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,false);
  if (viewer.options.continuousUpdates) {
    rfb.tryEnableContinuousUpdates(0,0,rfb.framebufferWidth,rfb.framebufferHeight);
  }
  resetStats();
  boolean statsRestarted=false;
  while (true) {
    int msgType=rfb.readServerMessageType();
switch (msgType) {
case RfbProto.FramebufferUpdate:
      if (statNumUpdates == viewer.debugStatsExcludeUpdates && !statsRestarted) {
        resetStats();
        statsRestarted=true;
      }
 else       if (statNumUpdates == viewer.debugStatsMeasureUpdates && statsRestarted) {
        viewer.disconnect();
      }
    rfb.readFramebufferUpdate();
  statNumUpdates++;
boolean cursorPosReceived=false;
for (int i=0; i < rfb.updateNRects; i++) {
rfb.readFramebufferUpdateRectHdr();
statNumTotalRects++;
int rx=rfb.updateRectX, ry=rfb.updateRectY;
int rw=rfb.updateRectW, rh=rfb.updateRectH;
if (rfb.updateRectEncoding == rfb.EncodingLastRect) break;
if (rfb.updateRectEncoding == rfb.EncodingNewFBSize) {
  rfb.setFramebufferSize(rw,rh);
  updateFramebufferSize();
  break;
}
if (rfb.updateRectEncoding == rfb.EncodingXCursor || rfb.updateRectEncoding == rfb.EncodingRichCursor) {
  handleCursorShapeUpdate(rfb.updateRectEncoding,rx,ry,rw,rh);
  continue;
}
if (rfb.updateRectEncoding == rfb.EncodingPointerPos) {
  softCursorMove(rx,ry);
  cursorPosReceived=true;
  continue;
}
long numBytesReadBefore=rfb.getNumBytesRead();
rfb.startTiming();
switch (rfb.updateRectEncoding) {
case RfbProto.EncodingRaw:
  statNumRectsRaw++;
handleRawRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingCopyRect:
statNumRectsCopy++;
handleCopyRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingRRE:
handleRRERect(rx,ry,rw,rh);
break;
case RfbProto.EncodingCoRRE:
handleCoRRERect(rx,ry,rw,rh);
break;
case RfbProto.EncodingHextile:
statNumRectsHextile++;
handleHextileRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingZRLE:
statNumRectsZRLE++;
handleZRLERect(rx,ry,rw,rh);
break;
case RfbProto.EncodingZlib:
handleZlibRect(rx,ry,rw,rh);
break;
case RfbProto.EncodingTight:
if (tightDecoder != null) {
statNumRectsTightJPEG=tightDecoder.getNumJPEGRects();
}
statNumRectsTight++;
handleTightRect(rx,ry,rw,rh);
break;
default :
throw new Exception("String_Node_Str" + rfb.updateRectEncoding);
}
rfb.stopTiming();
statNumPixelRects++;
statNumBytesDecoded+=rw * rh * bytesPixel;
statNumBytesEncoded+=(int)(rfb.getNumBytesRead() - numBytesReadBefore);
}
boolean fullUpdateNeeded=false;
if (viewer.checkRecordingStatus()) fullUpdateNeeded=true;
if (viewer.deferUpdateRequests > 0 && rfb.available() == 0 && !cursorPosReceived) {
synchronized (rfb) {
try {
rfb.wait(viewer.deferUpdateRequests);
}
 catch (InterruptedException e) {
}
}
}
viewer.autoSelectEncodings();
if (viewer.options.eightBitColors != (bytesPixel == 1)) {
if (!rfb.continuousUpdatesAreActive()) {
setPixelFormat();
fullUpdateNeeded=true;
}
 else {
rfb.tryDisableContinuousUpdates();
break;
}
}
boolean enable=viewer.options.continuousUpdates;
if (enable != rfb.continuousUpdatesAreActive()) {
if (enable) {
rfb.tryEnableContinuousUpdates(0,0,rfb.framebufferWidth,rfb.framebufferHeight);
}
 else {
rfb.tryDisableContinuousUpdates();
}
}
if (fullUpdateNeeded) {
rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,false);
}
 else if (!rfb.continuousUpdatesAreActive()) {
rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,true);
}
break;
case RfbProto.SetColourMapEntries:
throw new Exception("String_Node_Str");
case RfbProto.Bell:
Toolkit.getDefaultToolkit().beep();
break;
case RfbProto.ServerCutText:
String s=rfb.readServerCutText();
viewer.clipboard.setCutText(s);
break;
case RfbProto.EndOfContinuousUpdates:
if (rfb.continuousUpdatesAreActive()) {
rfb.endOfContinuousUpdates();
boolean incremental=true;
if (viewer.options.eightBitColors != (bytesPixel == 1)) {
setPixelFormat();
incremental=false;
}
rfb.writeFramebufferUpdateRequest(0,0,rfb.framebufferWidth,rfb.framebufferHeight,incremental);
}
break;
default :
throw new Exception("String_Node_Str" + msgType);
}
}
}