@@ -122,26 +122,26 @@ public String toString() {
122122 * Prints a stack trace for {@code throwable} if the system property
123123 * {@code "jdk.internal.vm.TranslatedException.debug"} is true.
124124 */
125- private static void debugPrintStackTrace (Throwable throwable ) {
126- if (Boolean . getBoolean ( "jdk.internal.vm.TranslatedException. debug" ) ) {
125+ private static void debugPrintStackTrace (Throwable throwable , boolean debug ) {
126+ if (debug ) {
127127 System .err .print ("DEBUG: " );
128128 throwable .printStackTrace ();
129129 }
130130 }
131131
132- private static Throwable initCause (Throwable throwable , Throwable cause ) {
132+ private static Throwable initCause (Throwable throwable , Throwable cause , boolean debug ) {
133133 if (cause != null ) {
134134 try {
135135 throwable .initCause (cause );
136136 } catch (IllegalStateException e ) {
137137 // Cause could not be set or overwritten.
138- debugPrintStackTrace (e );
138+ debugPrintStackTrace (e , debug );
139139 }
140140 }
141141 return throwable ;
142142 }
143143
144- private static Throwable create (String className , String message , Throwable cause ) {
144+ private static Throwable create (String className , String message , Throwable cause , boolean debug ) {
145145 // Try create with reflection first.
146146 try {
147147 Class <?> cls = Class .forName (className );
@@ -157,13 +157,13 @@ private static Throwable create(String className, String message, Throwable caus
157157 }
158158 if (message == null ) {
159159 Constructor <?> cons = cls .getConstructor ();
160- return initCause ((Throwable ) cons .newInstance (), cause );
160+ return initCause ((Throwable ) cons .newInstance (), cause , debug );
161161 }
162162 Constructor <?> cons = cls .getDeclaredConstructor (String .class );
163- return initCause ((Throwable ) cons .newInstance (message ), cause );
163+ return initCause ((Throwable ) cons .newInstance (message ), cause , debug );
164164 } catch (Throwable translationFailure ) {
165- debugPrintStackTrace (translationFailure );
166- return initCause (new TranslatedException (message , className ), cause );
165+ debugPrintStackTrace (translationFailure , debug );
166+ return initCause (new TranslatedException (message , className ), cause , debug );
167167 }
168168 }
169169
@@ -253,7 +253,7 @@ private static StackTraceElement[] getMyStackTrace() {
253253 * @param encodedThrowable an encoded exception in the format specified by
254254 * {@link #encodeThrowable}
255255 */
256- static Throwable decodeThrowable (byte [] encodedThrowable ) {
256+ static Throwable decodeThrowable (byte [] encodedThrowable , boolean debug ) {
257257 ByteArrayInputStream bais = new ByteArrayInputStream (encodedThrowable );
258258 try (DataInputStream dis = new DataInputStream (new GZIPInputStream (bais ))) {
259259 Throwable cause = null ;
@@ -262,7 +262,7 @@ static Throwable decodeThrowable(byte[] encodedThrowable) {
262262 while (dis .available () != 0 ) {
263263 String exceptionClassName = dis .readUTF ();
264264 String exceptionMessage = emptyAsNull (dis .readUTF ());
265- throwable = create (exceptionClassName , exceptionMessage , cause );
265+ throwable = create (exceptionClassName , exceptionMessage , cause , debug );
266266 int stackTraceDepth = dis .readInt ();
267267 StackTraceElement [] stackTrace = new StackTraceElement [stackTraceDepth + myStack .length ];
268268 int stackTraceIndex = 0 ;
@@ -310,7 +310,7 @@ static Throwable decodeThrowable(byte[] encodedThrowable) {
310310 }
311311 return throwable ;
312312 } catch (Throwable translationFailure ) {
313- debugPrintStackTrace (translationFailure );
313+ debugPrintStackTrace (translationFailure , debug );
314314 return new TranslatedException ("Error decoding exception: " + encodedThrowable ,
315315 translationFailure .getClass ().getName ());
316316 }
0 commit comments