Program: 13246
Project: 13246
Buggy source:
/** 
 * This newBuilder and this method can not be scheduled. The call MUST go through the   {@code org.forgerock.openidm.provisioner}<p/> Invoked by the scheduler when the scheduler triggers. <p/> Synchronization object:   {@code "connectorData" : "syncToken" :"1305555929000", "nativeType" : "JAVA_TYPE_LONG" }, "synchronizationStatus" : { "errorStatus" : null, "lastKnownServer" : "localServer", "lastModDate" : "2011-05-16T14:47:58.587Z", "lastModNum" : 668, "lastPollDate" : "2011-05-16T14:47:52.875Z", "lastStartTime" : "2011-05-16T14:29:07.863Z", "progressMessage" : "SUCCEEDED" } }} <p/>  {@inheritDoc} Synchronise the changes from the end system for the given{@code objectType}. <p/> OpenIDM takes active role in the synchronization process by asking the end system to get all changed object. Not all systems are capable to fulfill this kind of request but if the end system is capable then the implementation sends each change to a new request on the router and when it is finished, it returns a new <b>stage</b> object. <p/> The   {@code previousStage} object is the previously returned value of thismethod.
 * @param previousStage The previously returned object. If null then it's the first execution.
 * @return The new updated stage object. This will be the{@code previousStage} at buildNext call.
 * @throws IllegalArgumentException if the value of  {@code connectorData} can not be converted to{@link SyncToken}.
 * @throws UnsupportedOperationException if the  {@link SyncApiOp} operation is not implemented inconnector.
 * @throws org.forgerock.json.fluent.JsonValueException if the  {@code previousStage} is not Map.
 * @see {@link ConnectorUtil#convertToSyncToken(org.forgerock.json.fluent.JsonValue)}or any exception happed inside the connector.
 */
public JsonValue liveSynchronize(final String objectType,final JsonValue previousStage) throws ResourceException {
  if (!serviceAvailable) {
    return previousStage;
  }
  JsonValue stage=previousStage != null ? previousStage.copy() : new JsonValue(new LinkedHashMap<String,Object>());
  JsonValue connectorData=stage.get("String_Node_Str");
  SyncToken token=null;
  if (!connectorData.isNull()) {
    if (connectorData.isMap()) {
      token=ConnectorUtil.convertToSyncToken(connectorData);
    }
 else {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  stage.remove("String_Node_Str");
  try {
    final OperationHelper helper=operationHelperBuilder.build(objectType,stage,cryptoService);
    if (helper.isOperationPermitted(SyncApiOp.class)) {
      ConnectorFacade connector=getConnectorFacade();
      SyncApiOp operation=(SyncApiOp)connector.getOperation(SyncApiOp.class);
      if (null == operation) {
        throw new UnsupportedOperationException(SyncApiOp.class.getCanonicalName());
      }
      if (null == token) {
        token=operation.getLatestSyncToken(helper.getObjectClass());
        logger.debug("String_Node_Str",token);
      }
 else {
        final SyncToken[] lastToken=new SyncToken[]{token};
        final String[] failedRecord=new String[1];
        OperationOptionsBuilder operationOptionsBuilder=helper.getOperationOptionsBuilder(SyncApiOp.class,null,previousStage);
        try {
          logger.debug("String_Node_Str",new Object[]{helper.getObjectClass().getObjectClassValue(),token});
          SyncToken syncToken=operation.sync(helper.getObjectClass(),token,new SyncResultsHandler(){
            /** 
 * Called to handle a delta in the stream. The Connector framework will call this method multiple times, once for each result. Although this method is callback, the framework will invoke it synchronously. Thus, the framework guarantees that once an application's call to  {@link org.identityconnectors.framework.api.operations.SyncApiOp#sync(org.identityconnectors.framework.common.objects.ObjectClass,org.identityconnectors.framework.common.objects.SyncToken,org.identityconnectors.framework.common.objects.SyncResultsHandler,org.identityconnectors.framework.common.objects.OperationOptions)} SyncApiOp#sync() returns,the framework will no longer call this method to handle results from that <code>sync()</code> operation.
 * @param syncDelta The change
 * @return True iff the application wants to continue processing more results.
 * @throws RuntimeException If the application encounters an exception. This willstop iteration and the exception will propagate to the application.
 */
            @SuppressWarnings("String_Node_Str") public boolean handle(            SyncDelta syncDelta){
              try {
                final String resourceId=syncDelta.getUid().getUidValue();
                final String resourceContainer=getSource(objectType);
                final JsonValue content=new JsonValue(new LinkedHashMap<String,Object>(2));
switch (syncDelta.getDeltaType()) {
case CREATE:
{
                    JsonValue deltaObject=helper.build(syncDelta.getObject());
                    content.put("String_Node_Str",null);
                    content.put("String_Node_Str",deltaObject.getObject());
                    ActionRequest onCreateRequest=Requests.newActionRequest("String_Node_Str","String_Node_Str").setAdditionalParameter("String_Node_Str",resourceContainer).setAdditionalParameter("String_Node_Str",resourceId).setContent(content);
                    connectionFactory.getConnection().action(routerContext,onCreateRequest);
                    activityLogger.log(routerContext,RequestType.ACTION,"String_Node_Str",onCreateRequest.getResourceName(),deltaObject,deltaObject,Status.SUCCESS);
                    break;
                  }
case UPDATE:
case CREATE_OR_UPDATE:
{
                  JsonValue deltaObject=helper.build(syncDelta.getObject());
                  content.put("String_Node_Str",null);
                  content.put("String_Node_Str",deltaObject.getObject());
                  if (null != syncDelta.getPreviousUid()) {
                    deltaObject.put("String_Node_Str",syncDelta.getPreviousUid().getUidValue());
                  }
                  ActionRequest onUpdateRequest=Requests.newActionRequest("String_Node_Str","String_Node_Str").setAdditionalParameter("String_Node_Str",resourceContainer).setAdditionalParameter("String_Node_Str",resourceId).setContent(content);
                  connectionFactory.getConnection().action(routerContext,onUpdateRequest);
                  activityLogger.log(routerContext,RequestType.ACTION,"String_Node_Str",onUpdateRequest.getResourceName(),deltaObject,deltaObject,Status.SUCCESS);
                  break;
                }
case DELETE:
              content.put("String_Node_Str",null);
            ActionRequest onDeleteRequest=Requests.newActionRequest("String_Node_Str","String_Node_Str").setAdditionalParameter("String_Node_Str",resourceContainer).setAdditionalParameter("String_Node_Str",resourceId).setContent(content);
          connectionFactory.getConnection().action(routerContext,onDeleteRequest);
        activityLogger.log(routerContext,RequestType.ACTION,"String_Node_Str",onDeleteRequest.getResourceName(),null,null,Status.SUCCESS);
      break;
  }
}
 catch (Exception e) {
  failedRecord[0]=SerializerUtil.serializeXmlObject(syncDelta,true);
  if (logger.isDebugEnabled()) {
    logger.error("String_Node_Str",syncDelta.getUid(),syncFailureHandler,e);
  }
  Map<String,Object> syncFailure=new HashMap<String,Object>(6);
  syncFailure.put("String_Node_Str",syncDelta.getToken().getValue());
  syncFailure.put("String_Node_Str",systemIdentifier.getName());
  syncFailure.put("String_Node_Str",objectType);
  syncFailure.put("String_Node_Str",syncDelta.getUid().getUidValue());
  syncFailure.put("String_Node_Str",failedRecord[0]);
  syncFailureHandler.invoke(syncFailure,e);
}
lastToken[0]=syncDelta.getToken();
return true;
}
}
,operationOptionsBuilder.build());
if (syncToken != null) {
lastToken[0]=syncToken;
}
}
 catch (Throwable t) {
Map<String,Object> lastException=new LinkedHashMap<String,Object>(2);
lastException.put("String_Node_Str",t.getMessage());
if (null != failedRecord[0]) {
lastException.put("String_Node_Str",failedRecord[0]);
}
stage.put("String_Node_Str",lastException);
if (logger.isDebugEnabled()) {
logger.error("String_Node_Str",new Object[]{objectType,systemIdentifier.getName()},t);
}
}
 finally {
token=lastToken[0];
logger.debug("String_Node_Str",token);
}
}
if (null != token) {
stage.put("String_Node_Str",ConnectorUtil.convertFromSyncToken(token));
}
}
}
 catch (ResourceException e) {
logger.debug("String_Node_Str",e);
throw new RuntimeException(e);
}
catch (UnsupportedOperationException e) {
logger.debug("String_Node_Str",e);
throw new NotFoundException("String_Node_Str" + e.getMessage(),e);
}
catch (Exception e) {
logger.debug("String_Node_Str",e);
throw new InternalServerErrorException("String_Node_Str" + e.getMessage(),e);
}
return stage;
}

Fixed version (ground truth):
/** 
 * This newBuilder and this method can not be scheduled. The call MUST go through the   {@code org.forgerock.openidm.provisioner}<p/> Invoked by the scheduler when the scheduler triggers. <p/> Synchronization object:   {@code "connectorData" : "syncToken" :"1305555929000", "nativeType" : "JAVA_TYPE_LONG" }, "synchronizationStatus" : { "errorStatus" : null, "lastKnownServer" : "localServer", "lastModDate" : "2011-05-16T14:47:58.587Z", "lastModNum" : 668, "lastPollDate" : "2011-05-16T14:47:52.875Z", "lastStartTime" : "2011-05-16T14:29:07.863Z", "progressMessage" : "SUCCEEDED" } }} <p/>  {@inheritDoc} Synchronise the changes from the end system for the given{@code objectType}. <p/> OpenIDM takes active role in the synchronization process by asking the end system to get all changed object. Not all systems are capable to fulfill this kind of request but if the end system is capable then the implementation sends each change to a new request on the router and when it is finished, it returns a new <b>stage</b> object. <p/> The   {@code previousStage} object is the previously returned value of thismethod.
 * @param previousStage The previously returned object. If null then it's the first execution.
 * @return The new updated stage object. This will be the{@code previousStage} at buildNext call.
 * @throws IllegalArgumentException if the value of  {@code connectorData} can not be converted to{@link SyncToken}.
 * @throws UnsupportedOperationException if the  {@link SyncApiOp} operation is not implemented inconnector.
 * @throws org.forgerock.json.fluent.JsonValueException if the  {@code previousStage} is not Map.
 * @see {@link ConnectorUtil#convertToSyncToken(org.forgerock.json.fluent.JsonValue)}or any exception happed inside the connector.
 */
public JsonValue liveSynchronize(final String objectType,final JsonValue previousStage) throws ResourceException {
  if (!serviceAvailable) {
    return previousStage;
  }
  JsonValue stage=previousStage != null ? previousStage.copy() : new JsonValue(new LinkedHashMap<String,Object>());
  JsonValue connectorData=stage.get("String_Node_Str");
  SyncToken token=null;
  if (!connectorData.isNull()) {
    if (connectorData.isMap()) {
      token=ConnectorUtil.convertToSyncToken(connectorData);
    }
 else {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  stage.remove("String_Node_Str");
  try {
    final OperationHelper helper=operationHelperBuilder.build(objectType,stage,cryptoService);
    if (helper.isOperationPermitted(SyncApiOp.class)) {
      ConnectorFacade connector=getConnectorFacade();
      SyncApiOp operation=(SyncApiOp)connector.getOperation(SyncApiOp.class);
      if (null == operation) {
        throw new UnsupportedOperationException(SyncApiOp.class.getCanonicalName());
      }
      if (null == token) {
        token=operation.getLatestSyncToken(helper.getObjectClass());
        logger.debug("String_Node_Str",token);
      }
 else {
        final SyncToken[] lastToken=new SyncToken[]{token};
        final String[] failedRecord=new String[1];
        OperationOptionsBuilder operationOptionsBuilder=helper.getOperationOptionsBuilder(SyncApiOp.class,null,previousStage);
        try {
          logger.debug("String_Node_Str",new Object[]{helper.getObjectClass().getObjectClassValue(),token});
          SyncToken syncToken=operation.sync(helper.getObjectClass(),token,new SyncResultsHandler(){
            /** 
 * Called to handle a delta in the stream. The Connector framework will call this method multiple times, once for each result. Although this method is callback, the framework will invoke it synchronously. Thus, the framework guarantees that once an application's call to  {@link org.identityconnectors.framework.api.operations.SyncApiOp#sync(org.identityconnectors.framework.common.objects.ObjectClass,org.identityconnectors.framework.common.objects.SyncToken,org.identityconnectors.framework.common.objects.SyncResultsHandler,org.identityconnectors.framework.common.objects.OperationOptions)} SyncApiOp#sync() returns,the framework will no longer call this method to handle results from that <code>sync()</code> operation.
 * @param syncDelta The change
 * @return True iff the application wants to continue processing more results.
 * @throws RuntimeException If the application encounters an exception. This willstop iteration and the exception will propagate to the application.
 */
            @SuppressWarnings("String_Node_Str") public boolean handle(            SyncDelta syncDelta){
              try {
                final String resourceId=syncDelta.getUid().getUidValue();
                final String resourceContainer=getSource(objectType);
                final JsonValue content=new JsonValue(new LinkedHashMap<String,Object>(2));
switch (syncDelta.getDeltaType()) {
case CREATE:
{
                    JsonValue deltaObject=helper.build(syncDelta.getObject());
                    content.put("String_Node_Str",null);
                    content.put("String_Node_Str",deltaObject.getObject());
                    ActionRequest onCreateRequest=Requests.newActionRequest("String_Node_Str","String_Node_Str").setAdditionalParameter("String_Node_Str",resourceContainer).setAdditionalParameter("String_Node_Str",resourceId).setContent(content);
                    connectionFactory.getConnection().action(routerContext,onCreateRequest);
                    activityLogger.log(routerContext,RequestType.ACTION,"String_Node_Str",onCreateRequest.getResourceName(),deltaObject,deltaObject,Status.SUCCESS);
                    break;
                  }
case UPDATE:
case CREATE_OR_UPDATE:
{
                  JsonValue deltaObject=helper.build(syncDelta.getObject());
                  content.put("String_Node_Str",null);
                  content.put("String_Node_Str",deltaObject.getObject());
                  if (null != syncDelta.getPreviousUid()) {
                    deltaObject.put("String_Node_Str",syncDelta.getPreviousUid().getUidValue());
                  }
                  ActionRequest onUpdateRequest=Requests.newActionRequest("String_Node_Str","String_Node_Str").setAdditionalParameter("String_Node_Str",resourceContainer).setAdditionalParameter("String_Node_Str",resourceId).setContent(content);
                  connectionFactory.getConnection().action(routerContext,onUpdateRequest);
                  activityLogger.log(routerContext,RequestType.ACTION,"String_Node_Str",onUpdateRequest.getResourceName(),deltaObject,deltaObject,Status.SUCCESS);
                  break;
                }
case DELETE:
              content.put("String_Node_Str",null);
            ActionRequest onDeleteRequest=Requests.newActionRequest("String_Node_Str","String_Node_Str").setAdditionalParameter("String_Node_Str",resourceContainer).setAdditionalParameter("String_Node_Str",resourceId).setContent(content);
          connectionFactory.getConnection().action(routerContext,onDeleteRequest);
        activityLogger.log(routerContext,RequestType.ACTION,"String_Node_Str",onDeleteRequest.getResourceName(),null,null,Status.SUCCESS);
      break;
  }
}
 catch (Exception e) {
  failedRecord[0]=SerializerUtil.serializeXmlObject(syncDelta,true);
  if (logger.isDebugEnabled()) {
    logger.error("String_Node_Str",syncDelta.getUid(),syncFailureHandler,e);
  }
  Map<String,Object> syncFailure=new HashMap<String,Object>(6);
  syncFailure.put("String_Node_Str",syncDelta.getToken().getValue());
  syncFailure.put("String_Node_Str",systemIdentifier.getName());
  syncFailure.put("String_Node_Str",objectType);
  syncFailure.put("String_Node_Str",syncDelta.getUid().getUidValue());
  syncFailure.put("String_Node_Str",failedRecord[0]);
  syncFailureHandler.invoke(syncFailure,e);
}
lastToken[0]=syncDelta.getToken();
return true;
}
}
,operationOptionsBuilder.build());
if (syncToken != null) {
lastToken[0]=syncToken;
}
}
 catch (Throwable t) {
Map<String,Object> lastException=new LinkedHashMap<String,Object>(2);
lastException.put("String_Node_Str",t.getMessage());
if (null != failedRecord[0]) {
lastException.put("String_Node_Str",failedRecord[0]);
}
stage.put("String_Node_Str",lastException);
if (logger.isDebugEnabled()) {
logger.error("String_Node_Str",new Object[]{objectType,systemIdentifier.getName()},t);
}
}
 finally {
token=lastToken[0];
logger.debug("String_Node_Str",token);
}
}
if (null != token) {
stage.put("String_Node_Str",ConnectorUtil.convertFromSyncToken(token));
}
}
}
 catch (ResourceException e) {
logger.debug("String_Node_Str",e);
throw new RuntimeException(e);
}
catch (UnsupportedOperationException e) {
logger.debug("String_Node_Str",e);
throw new NotFoundException("String_Node_Str",e).setDetail(new JsonValue(e.getMessage()));
}
catch (Exception e) {
logger.debug("String_Node_Str",e);
throw new InternalServerErrorException("String_Node_Str" + e.getMessage(),e);
}
return stage;
}