Source:
<code>protected void handleException(Throwable exception, StompFrame command) throws IOException { if (command == null) { LOG.warn("Exception occurred while processing a command: {}", exception.toString()); } else { if (exception instanceof JMSException) { JMSException jmsException = (JMSException) exception; if (jmsException.getLinkedException() != null) { LOG.warn("Exception occurred for client ({}) processing: -> ({})", connectionInfo.getClientId(), connectionInfo.getClientIp(), safeGetAction(command), exception.toString(), jmsException.getLinkedException().toString()); } else { LOG.warn("Exception occurred for client ({}) processing: -> {}", connectionInfo.getClientId(), connectionInfo.getClientIp(), safeGetAction(command), exception.toString()); } } else { LOG.warn("Exception occurred for client ({}) processing: -> {}", connectionInfo.getClientId(), connectionInfo.getClientIp(), safeGetAction(command), exception.toString()); } } if (LOG.isDebugEnabled()) { LOG.debug("Exception detail", exception); } if (command != null && LOG.isTraceEnabled()) { LOG.trace("Command that caused the error: {}", command); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter stream = new PrintWriter(new OutputStreamWriter(baos, "UTF-8")); <START> exception.printStackTrace(stream); <END> stream.close(); HashMap<String, String> headers = new HashMap<>(); headers.put(Stomp.Headers.Error.MESSAGE, exception.getMessage()); headers.put(Stomp.Headers.CONTENT_TYPE, "text/plain"); if (command != null) { final String receiptId = command.getHeaders().get(Stomp.Headers.RECEIPT_REQUESTED); if (receiptId != null) { headers.put(Stomp.Headers.Response.RECEIPT_ID, receiptId); } } StompFrame errorMessage = new StompFrame(Stomp.Responses.ERROR, headers, baos.toByteArray()); sendToStomp(errorMessage); }</code><technical_language>keeping original code writing SecurityException stream</technical_language>

Target:
protected void handleException(Throwable exception, StompFrame command) throws IOException { if (command == null) { LOG.warn("Exception occurred while processing a command: {}", exception.toString()); } else { if (exception instanceof JMSException) { JMSException jmsException = (JMSException) exception; if (jmsException.getLinkedException() != null) { LOG.warn("Exception occurred for client ({}) processing: -> ({})", connectionInfo.getClientId(), connectionInfo.getClientIp(), safeGetAction(command), exception.toString(), jmsException.getLinkedException().toString()); } else { LOG.warn("Exception occurred for client ({}) processing: -> {}", connectionInfo.getClientId(), connectionInfo.getClientIp(), safeGetAction(command), exception.toString()); } } else { LOG.warn("Exception occurred for client ({}) processing: -> {}", connectionInfo.getClientId(), connectionInfo.getClientIp(), safeGetAction(command), exception.toString()); } } if (LOG.isDebugEnabled()) { LOG.debug("Exception detail", exception); } if (command != null && LOG.isTraceEnabled()) { LOG.trace("Command that caused the error: {}", command); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter stream = new PrintWriter(new OutputStreamWriter(baos, "UTF-8")); if (exception instanceof SecurityException || exception.getCause() instanceof SecurityException) { stream.write(exception.getLocalizedMessage()); } else { exception.printStackTrace(stream); } stream.close(); HashMap<String, String> headers = new HashMap<>(); headers.put(Stomp.Headers.Error.MESSAGE, exception.getMessage()); headers.put(Stomp.Headers.CONTENT_TYPE, "text/plain"); if (command != null) { final String receiptId = command.getHeaders().get(Stomp.Headers.RECEIPT_REQUESTED); if (receiptId != null) { headers.put(Stomp.Headers.Response.RECEIPT_ID, receiptId); } } StompFrame errorMessage = new StompFrame(Stomp.Responses.ERROR, headers, baos.toByteArray()); sendToStomp(errorMessage); }