diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java index 90eec0b..66a6941 100644 --- a/src/org/joni/Config.java +++ b/src/org/joni/Config.java @@ -74,6 +74,11 @@ public interface Config extends org.jcodings.Config { int CHECK_STRING_THRESHOLD_LEN = ConfigSupport.getInt("joni.check_string_threshold_len", 7); int CHECK_BUFF_MAX_SIZE = ConfigSupport.getInt("joni.check_buff_max_size", 0x4000); + // Whether JOniException and its subclasses record a stack trace when thrown. + // Filling in the stack trace is expensive and the Java stack trace is rarely useful + // (e.g. for a regexp syntax error), so it is disabled by default. + boolean ENABLE_STACK_TRACE = ConfigSupport.getBoolean("org.joni.enableStackTrace", false); + PrintStream log = System.out; PrintStream err = System.err; diff --git a/src/org/joni/exception/JOniException.java b/src/org/joni/exception/JOniException.java index c2c5d47..3a34086 100644 --- a/src/org/joni/exception/JOniException.java +++ b/src/org/joni/exception/JOniException.java @@ -19,10 +19,24 @@ */ package org.joni.exception; +import org.joni.Config; + public class JOniException extends RuntimeException{ private static final long serialVersionUID = -6027192180014164667L; public JOniException(String message) { super(message); } + + // The stacktrace is not very useful and is very expensive, + // for example for Regexp#to_s on a Regexp like /(?i:a)|(?i:b)/, + // so it is omitted unless -Dorg.joni.enableStackTrace=true + @Override + public final Throwable fillInStackTrace() { + if (Config.ENABLE_STACK_TRACE) { + return super.fillInStackTrace(); + } else { + return this; + } + } }