Program: 48088
Project: 48088
Buggy source:
/** 
 * Activates the client according to the received TCToken.
 * @param request The activation request containing the TCToken.
 * @return The response containing the result of the activation process.
 * @throws InvalidRedirectUrlException Thrown in case no redirect URL could be determined.
 * @throws SecurityViolationException
 * @throws NonGuiException
 */
public TCTokenResponse handleActivate(TCTokenRequest request) throws InvalidRedirectUrlException, SecurityViolationException, NonGuiException {
  TCToken token=request.getTCToken();
  if (logger.isDebugEnabled()) {
    try {
      WSMarshaller m=WSMarshallerFactory.createInstance();
      logger.debug("String_Node_Str",m.doc2str(m.marshal(token)));
    }
 catch (    TransformerException|WSMarshallerException ex) {
    }
  }
  final DynamicContext dynCtx=DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
  boolean performChecks=isPerformTR03112Checks(request);
  if (!performChecks) {
    logger.warn("String_Node_Str");
  }
  boolean isObjectActivation=request.getTCTokenURL() == null;
  if (isObjectActivation) {
    logger.warn("String_Node_Str");
  }
  dynCtx.put(TR03112Keys.TCTOKEN_CHECKS,performChecks);
  dynCtx.put(TR03112Keys.OBJECT_ACTIVATION,isObjectActivation);
  dynCtx.put(TR03112Keys.TCTOKEN_SERVER_CERTIFICATES,request.getCertificates());
  ConnectionHandleType connectionHandle=null;
  TCTokenResponse response=new TCTokenResponse();
  response.setTCToken(token);
  byte[] requestedContextHandle=request.getContextHandle();
  String ifdName=request.getIFDName();
  BigInteger requestedSlotIndex=request.getSlotIndex();
  if (requestedContextHandle == null || ifdName == null || requestedSlotIndex == null) {
    connectionHandle=getFirstHandle(request.getCardType());
  }
 else {
    ConnectionHandleType requestedHandle=new ConnectionHandleType();
    requestedHandle.setContextHandle(requestedContextHandle);
    requestedHandle.setIFDName(ifdName);
    requestedHandle.setSlotIndex(requestedSlotIndex);
    Set<CardStateEntry> matchingHandles=cardStates.getMatchingEntries(requestedHandle);
    if (!matchingHandles.isEmpty()) {
      connectionHandle=matchingHandles.toArray(new CardStateEntry[]{})[0].handleCopy();
    }
  }
  if (connectionHandle == null) {
    String msg=lang.translationForKey("String_Node_Str");
    logger.error(msg);
    response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.CANCELLATION_BY_USER,msg));
    response=determineRefreshURL(request,response);
    response.finishResponse(true);
    return response;
  }
  try {
    response=processBinding(request,connectionHandle);
    response=determineRefreshURL(request,response);
    response.finishResponse(isObjectActivation);
    return response;
  }
 catch (  DispatcherException w) {
    logger.error(w.getMessage(),w);
    response.setResultCode(BindingResultCode.INTERNAL_ERROR);
    response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR,w.getMessage()));
    showErrorMessage(w.getMessage());
    throw new NonGuiException(response,w.getMessage(),w);
  }
catch (  PAOSException w) {
    logger.error(w.getMessage(),w);
    Throwable innerException=w.getCause();
    if (innerException == null) {
      innerException=w;
    }
 else     if (innerException instanceof ExecutionException) {
      innerException=innerException.getCause();
    }
    String errorMsg=innerException.getLocalizedMessage();
switch (errorMsg) {
case "String_Node_Str":
      errorMsg=langTr03112.translationForKey(NO_RESPONSE_FROM_SERVER);
    break;
case ECardConstants.Minor.App.INT_ERROR + "String_Node_Str":
  errorMsg=langTr03112.translationForKey(UNKNOWN_ECARD_ERROR);
break;
}
showErrorMessage(errorMsg);
if (innerException instanceof WSException) {
response.setResult(((WSException)innerException).getResult());
}
 else {
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM,w.getMessage()));
}
try {
response=determineRefreshURL(request,response);
response.finishResponse(true);
}
 catch (InvalidRedirectUrlException ex) {
logger.error(ex.getMessage(),ex);
response.setResultCode(BindingResultCode.INTERNAL_ERROR);
throw new NonGuiException(response,ex.getMessage(),ex);
}
catch (SecurityViolationException ex) {
String msg2="String_Node_Str" + "String_Node_Str";
logger.error(msg2,ex);
response.setResultCode(BindingResultCode.REDIRECT);
response.addAuxResultData(AuxDataKeys.REDIRECT_LOCATION,ex.getBindingResult().getAuxResultData().get(AuxDataKeys.REDIRECT_LOCATION));
}
return response;
}
}

Fixed version (ground truth):
/** 
 * Activates the client according to the received TCToken.
 * @param request The activation request containing the TCToken.
 * @return The response containing the result of the activation process.
 * @throws InvalidRedirectUrlException Thrown in case no redirect URL could be determined.
 * @throws SecurityViolationException
 * @throws NonGuiException
 */
public TCTokenResponse handleActivate(TCTokenRequest request) throws InvalidRedirectUrlException, SecurityViolationException, NonGuiException {
  TCToken token=request.getTCToken();
  if (logger.isDebugEnabled()) {
    try {
      WSMarshaller m=WSMarshallerFactory.createInstance();
      logger.debug("String_Node_Str",m.doc2str(m.marshal(token)));
    }
 catch (    TransformerException|WSMarshallerException ex) {
    }
  }
  final DynamicContext dynCtx=DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
  boolean performChecks=isPerformTR03112Checks(request);
  if (!performChecks) {
    logger.warn("String_Node_Str");
  }
  boolean isObjectActivation=request.getTCTokenURL() == null;
  if (isObjectActivation) {
    logger.warn("String_Node_Str");
  }
  dynCtx.put(TR03112Keys.TCTOKEN_CHECKS,performChecks);
  dynCtx.put(TR03112Keys.OBJECT_ACTIVATION,isObjectActivation);
  dynCtx.put(TR03112Keys.TCTOKEN_SERVER_CERTIFICATES,request.getCertificates());
  ConnectionHandleType connectionHandle=null;
  TCTokenResponse response=new TCTokenResponse();
  response.setTCToken(token);
  byte[] requestedContextHandle=request.getContextHandle();
  String ifdName=request.getIFDName();
  BigInteger requestedSlotIndex=request.getSlotIndex();
  if (requestedContextHandle == null || ifdName == null || requestedSlotIndex == null) {
    connectionHandle=getFirstHandle(request.getCardType());
  }
 else {
    ConnectionHandleType requestedHandle=new ConnectionHandleType();
    requestedHandle.setContextHandle(requestedContextHandle);
    requestedHandle.setIFDName(ifdName);
    requestedHandle.setSlotIndex(requestedSlotIndex);
    Set<CardStateEntry> matchingHandles=cardStates.getMatchingEntries(requestedHandle);
    if (!matchingHandles.isEmpty()) {
      connectionHandle=matchingHandles.toArray(new CardStateEntry[]{})[0].handleCopy();
    }
  }
  if (connectionHandle == null) {
    String msg=lang.translationForKey("String_Node_Str");
    logger.error(msg);
    response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.CANCELLATION_BY_USER,msg));
    response=determineRefreshURL(request,response);
    response.finishResponse(true);
    return response;
  }
  try {
    response=processBinding(request,connectionHandle);
    response=determineRefreshURL(request,response);
    response.finishResponse(isObjectActivation);
    return response;
  }
 catch (  DispatcherException w) {
    logger.error(w.getMessage(),w);
    response.setResultCode(BindingResultCode.INTERNAL_ERROR);
    response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR,w.getMessage()));
    showErrorMessage(w.getMessage());
    throw new NonGuiException(response,w.getMessage(),w);
  }
catch (  PAOSException w) {
    logger.error(w.getMessage(),w);
    Throwable innerException=w.getCause();
    if (innerException == null) {
      innerException=w;
    }
 else     if (innerException instanceof ExecutionException) {
      innerException=innerException.getCause();
    }
    String errorMsg=innerException.getLocalizedMessage();
switch (errorMsg) {
case "String_Node_Str":
      errorMsg=langTr03112.translationForKey(NO_RESPONSE_FROM_SERVER);
    break;
case ECardConstants.Minor.App.INT_ERROR + "String_Node_Str":
  errorMsg=langTr03112.translationForKey(UNKNOWN_ECARD_ERROR);
break;
}
if (innerException instanceof WSException) {
errorMsg=langTr03112.translationForKey(ERROR_WHILE_AUTHENTICATION);
response.setResult(WSHelper.makeResultError(((WSException)innerException).getResultMinor(),errorMsg));
}
 else if (innerException instanceof PAOSConnectionException) {
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.COMMUNICATION_ERROR,w.getLocalizedMessage()));
}
 else {
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM,w.getLocalizedMessage()));
}
showErrorMessage(errorMsg);
try {
response=determineRefreshURL(request,response);
response.finishResponse(true);
}
 catch (InvalidRedirectUrlException ex) {
logger.error(ex.getMessage(),ex);
response.setResultCode(BindingResultCode.INTERNAL_ERROR);
throw new NonGuiException(response,ex.getMessage(),ex);
}
catch (SecurityViolationException ex) {
String msg2="String_Node_Str" + "String_Node_Str";
logger.error(msg2,ex);
response.setResultCode(BindingResultCode.REDIRECT);
response.addAuxResultData(AuxDataKeys.REDIRECT_LOCATION,ex.getBindingResult().getAuxResultData().get(AuxDataKeys.REDIRECT_LOCATION));
}
return response;
}
}