Program: 13145
Project: 13145
Buggy source:
private ConnectionFactory newWrappedInternalConnectionFactory(final ConnectionFactory connectionFactory){
  return new ConnectionFactory(){
    @Override public void close(){
      connectionFactory.close();
    }
    @Override public Connection getConnection() throws ResourceException {
      return new AbstractConnectionWrapper<Connection>(connectionFactory.getConnection()){
        @Override public ResourceResponse create(        Context context,        CreateRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.create(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> createAsync(        Context context,        CreateRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.createAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse read(        Context context,        ReadRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.read(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> readAsync(        Context context,        ReadRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.readAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse update(        Context context,        UpdateRequest request) throws ResourceException {
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.update(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> updateAsync(        Context context,        UpdateRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.updateAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse delete(        Context context,        DeleteRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.delete(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> deleteAsync(        Context context,        DeleteRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.deleteAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse patch(        Context context,        PatchRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.patch(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> patchAsync(        Context context,        PatchRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.patchAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ActionResponse action(        Context context,        ActionRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.action(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ActionResponse,ResourceException> actionAsync(        Context context,        ActionRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.actionAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public QueryResponse query(        Context context,        QueryRequest request,        QueryResourceHandler handler) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.query(context,request,handler);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<QueryResponse,ResourceException> queryAsync(        Context context,        QueryRequest request,        QueryResourceHandler handler){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.queryAsync(context,request,handler).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
      }
;
    }
    @Override public Promise<Connection,ResourceException> getConnectionAsync(){
      try {
        return newResultPromise(getConnection());
      }
 catch (      ResourceException e) {
        return e.asPromise();
      }
    }
    /** 
 * @param request the router request
 * @return an event name For monitoring purposes
 */
    private Name getRouterEventName(    Request request){
      RequestType requestType=request.getRequestType();
      String idContext;
      if (RequestType.QUERY.equals(requestType) || RequestType.ACTION.equals(requestType) || RequestType.CREATE.equals(requestType)) {
        idContext=request.getResourcePath();
      }
 else {
        idContext=request.getResourcePathObject().head(request.getResourcePathObject().size() - 1).toString();
      }
      String eventName=new StringBuilder(EVENT_ROUTER_PREFIX).append(idContext).append("String_Node_Str").append(requestType.toString().toLowerCase()).toString();
      return Name.get(eventName);
    }
  }
;
}

Fixed version (ground truth):
private ConnectionFactory newWrappedInternalConnectionFactory(final ConnectionFactory connectionFactory){
  return new ConnectionFactory(){
    @Override public void close(){
      connectionFactory.close();
    }
    @Override public Connection getConnection() throws ResourceException {
      return new AbstractConnectionWrapper<Connection>(connectionFactory.getConnection()){
        @Override public ResourceResponse create(        Context context,        CreateRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.create(context,copyOfCreateRequest(request));
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> createAsync(        Context context,        CreateRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.createAsync(context,copyOfCreateRequest(request)).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse read(        Context context,        ReadRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.read(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> readAsync(        Context context,        ReadRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.readAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse update(        Context context,        UpdateRequest request) throws ResourceException {
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.update(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> updateAsync(        Context context,        UpdateRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.updateAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse delete(        Context context,        DeleteRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.delete(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> deleteAsync(        Context context,        DeleteRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.deleteAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ResourceResponse patch(        Context context,        PatchRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.patch(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ResourceResponse,ResourceException> patchAsync(        Context context,        PatchRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.patchAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public ActionResponse action(        Context context,        ActionRequest request) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.action(context,request);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<ActionResponse,ResourceException> actionAsync(        Context context,        ActionRequest request){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.actionAsync(context,request).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
        @Override public QueryResponse query(        Context context,        QueryRequest request,        QueryResourceHandler handler) throws ResourceException {
          EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          try {
            return super.query(context,request,handler);
          }
  finally {
            measure.end();
          }
        }
        @Override public Promise<QueryResponse,ResourceException> queryAsync(        Context context,        QueryRequest request,        QueryResourceHandler handler){
          final EventEntry measure=Publisher.start(getRouterEventName(request),request,null);
          return super.queryAsync(context,request,handler).thenAlways(new Runnable(){
            @Override public void run(){
              measure.end();
            }
          }
);
        }
      }
;
    }
    @Override public Promise<Connection,ResourceException> getConnectionAsync(){
      try {
        return newResultPromise(getConnection());
      }
 catch (      ResourceException e) {
        return e.asPromise();
      }
    }
    /** 
 * @param request the router request
 * @return an event name For monitoring purposes
 */
    private Name getRouterEventName(    Request request){
      RequestType requestType=request.getRequestType();
      String idContext;
      if (RequestType.QUERY.equals(requestType) || RequestType.ACTION.equals(requestType) || RequestType.CREATE.equals(requestType)) {
        idContext=request.getResourcePath();
      }
 else {
        idContext=request.getResourcePathObject().head(request.getResourcePathObject().size() - 1).toString();
      }
      String eventName=new StringBuilder(EVENT_ROUTER_PREFIX).append(idContext).append("String_Node_Str").append(requestType.toString().toLowerCase()).toString();
      return Name.get(eventName);
    }
  }
;
}