[Fix] Always use \n in ExceptionHelper.formatException()

This commit is contained in:
Robert von Burg 2019-09-04 12:36:44 +02:00
parent f190532cb1
commit a81808d821
1 changed files with 17 additions and 4 deletions

View File

@ -15,9 +15,14 @@
*/
package li.strolch.utils.helper;
import static li.strolch.utils.helper.XmlHelper.PROP_LINE_SEPARATOR;
import static li.strolch.utils.helper.XmlHelper.UNIX_LINE_SEP;
import java.io.PrintWriter;
import java.io.StringWriter;
import li.strolch.utils.RemoveCRFilterWriter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@ -74,10 +79,18 @@ public class ExceptionHelper {
* @return a string representation of the given {@link Throwable}'s stack trace
*/
public static String formatException(Throwable t) {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
t.printStackTrace(writer);
return stringWriter.toString();
String ls = System.getProperty(PROP_LINE_SEPARATOR);
if (!ls.equals(UNIX_LINE_SEP))
System.setProperty(PROP_LINE_SEPARATOR, UNIX_LINE_SEP);
try {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(new RemoveCRFilterWriter(stringWriter));
t.printStackTrace(writer);
return stringWriter.toString();
} finally {
if (!ls.equals(UNIX_LINE_SEP))
System.setProperty(PROP_LINE_SEPARATOR, ls);
}
}
/**