Program: 24237
Project: 24237
Buggy source:
@Override public void messageReceived(ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  if (e.getMessage() instanceof HttpRequest) {
    HttpRequest request=(HttpRequest)e.getMessage();
    String URI=request.getUri();
    if (URI == null || URI.length() < 2 || URI.charAt(0) != '/') {
      sendInvalidRequestResponse(ctx,e,copiedBuffer(format("String_Node_Str",URI),UTF_8));
      return;
    }
    HttpMethod method=request.getMethod();
    if (method != HttpMethod.POST) {
      sendInvalidRequestResponse(ctx,e,copiedBuffer(format("String_Node_Str",method.toString()),UTF_8));
      return;
    }
    String messageType=URI.substring(1).toUpperCase();
    ControlMessage msg=null;
    char type=messageType.charAt(0);
switch (type) {
case 'P':
      if (messageType.equals("String_Node_Str")) {
        msg=new PrepareMessage();
      }
    break;
case 'S':
  if (messageType.equals("String_Node_Str")) {
    msg=new StartMessage();
  }
break;
case 'A':
if (messageType.equals("String_Node_Str")) {
msg=new AbortMessage();
}
break;
case 'R':
if (messageType.equals("String_Node_Str")) {
msg=new ResultRequestMessage();
}
break;
default :
sendInvalidRequestResponse(ctx,e,copiedBuffer(format("String_Node_Str",URI),UTF_8));
return;
}
String content=new String(request.getContent().array(),"String_Node_Str");
int startIndex=content.indexOf("String_Node_Str");
int beginIndex=startIndex + "String_Node_Str".length();
int endIndex=content.lastIndexOf("String_Node_Str");
if (startIndex == -1 || endIndex == -1 || beginIndex == endIndex) {
sendInvalidRequestResponse(ctx,e,copiedBuffer(format("String_Node_Str",content),UTF_8));
return;
}
String name=content.substring(beginIndex,endIndex);
msg.setName(name);
if (msg instanceof PrepareMessage) {
synchronized (this) {
if (currentState != State.INITIAL && currentState != State.FINISHED && currentState != State.ERROR) {
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
}
 else {
ClearCacheMessage clearCachedEntry=new ClearCacheMessage();
clearCachedEntry.setName(msg.getName());
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(),e.getFuture(),clearCachedEntry,e.getRemoteAddress()));
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
}
}
}
 else if (msg instanceof StartMessage) {
synchronized (this) {
if (currentState != State.PREPARED) {
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
}
 else {
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
}
}
}
 else if (msg instanceof ResultRequestMessage) {
synchronized (this) {
if (currentState != State.FINISHED && currentState != State.ERROR && currentState != State.STARTED) {
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
}
 else {
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(),e.getFuture(),msg,e.getRemoteAddress()));
}
}
}
 else if (msg instanceof AbortMessage) {
synchronized (this) {
switch (currentState) {
case INITIAL:
case ERROR:
case ABORTED:
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
break;
case FINISHED:
case PREPARED:
case STARTED:
default :
currentState=State.ABORTED;
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
break;
}
}
}
 else {
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
}
}
 else {
ctx.sendUpstream(e);
}
}

Fixed version (ground truth):
@Override public void messageReceived(ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  if (e.getMessage() instanceof HttpRequest) {
    HttpRequest request=(HttpRequest)e.getMessage();
    String content=new String(request.getContent().array(),"String_Node_Str");
    String name=getName(content);
    String URI=request.getUri();
    if (URI == null || URI.length() < 2 || URI.charAt(0) != '/') {
      sendBadRequestMessage(ctx,e,format("String_Node_Str",URI),name);
      return;
    }
    HttpMethod method=request.getMethod();
    if (method != HttpMethod.POST) {
      sendBadRequestMessage(ctx,e,format("String_Node_Str",method.toString()),name);
      return;
    }
    String messageType=URI.substring(1).toUpperCase();
    ControlMessage msg=null;
    char type=messageType.charAt(0);
switch (type) {
case 'P':
      if (messageType.equals("String_Node_Str")) {
        msg=new PrepareMessage();
      }
    break;
case 'S':
  if (messageType.equals("String_Node_Str")) {
    msg=new StartMessage();
  }
break;
case 'A':
if (messageType.equals("String_Node_Str")) {
msg=new AbortMessage();
}
break;
case 'R':
if (messageType.equals("String_Node_Str")) {
msg=new ResultRequestMessage();
}
break;
default :
break;
}
if (msg == null) {
sendBadRequestMessage(ctx,e,format("String_Node_Str",URI),getName(content));
return;
}
if (name.equals("String_Node_Str")) {
sendBadRequestMessage(ctx,e,format("String_Node_Str",content),name);
return;
}
msg.setName(name);
if (msg instanceof PrepareMessage) {
synchronized (this) {
if (currentState != State.INITIAL && currentState != State.FINISHED && currentState != State.ERROR) {
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
}
 else {
ClearCacheMessage clearCachedEntry=new ClearCacheMessage();
clearCachedEntry.setName(msg.getName());
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(),e.getFuture(),clearCachedEntry,e.getRemoteAddress()));
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
}
}
}
 else if (msg instanceof StartMessage) {
synchronized (this) {
if (currentState != State.PREPARED) {
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
}
 else {
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
}
}
}
 else if (msg instanceof ResultRequestMessage) {
synchronized (this) {
if (currentState != State.FINISHED && currentState != State.ERROR && currentState != State.STARTED) {
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
}
 else {
ctx.sendDownstream(new DownstreamMessageEvent(e.getChannel(),e.getFuture(),msg,e.getRemoteAddress()));
}
}
}
 else if (msg instanceof AbortMessage) {
synchronized (this) {
switch (currentState) {
case INITIAL:
case ERROR:
case ABORTED:
sendBadRequestMessage(ctx,e,"String_Node_Str",msg.getName());
break;
case FINISHED:
case PREPARED:
case STARTED:
default :
currentState=State.ABORTED;
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
break;
}
}
}
 else {
ctx.sendUpstream(new UpstreamMessageEvent(e.getChannel(),msg,e.getRemoteAddress()));
}
}
 else {
ctx.sendUpstream(e);
}
}