From 32994caee8e2d06dad9006c8a6e0931e03818403 Mon Sep 17 00:00:00 2001 From: Michajlo Matijkiw Date: Mon, 1 Aug 2016 15:43:25 +0000 Subject: Don't fill in stack trace for ReturnException This is used to implement return, it's not really an exceptional condition requiring a full trace. -- MOS_MIGRATED_REVID=128988641 --- .../devtools/build/lib/syntax/EvalException.java | 21 +++++++++++++++++++-- .../devtools/build/lib/syntax/ReturnStatement.java | 6 +++--- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalException.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalException.java index 2f7ca84564..97d695f91d 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/EvalException.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalException.java @@ -19,9 +19,7 @@ import com.google.common.base.Throwables; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.util.LoggingUtil; import com.google.devtools.build.lib.util.Preconditions; - import java.util.logging.Level; - import javax.annotation.Nullable; /** @@ -59,6 +57,25 @@ public class EvalException extends Exception { * @param dueToIncompleteAST if the error is caused by a previous error, such as parsing. */ public EvalException(Location location, String message, boolean dueToIncompleteAST) { + this(location, message, dueToIncompleteAST, true); + } + + /** + * Create an EvalException with the option to not fill in the java stack trace. An optimization + * for ReturnException, and potentially others, which aren't exceptional enough to include a + * stack trace. + * + * @param location the location where evaluation/execution failed. + * @param message the error message. + * @param dueToIncompleteAST if the error is caused by a previous error, such as parsing. + * @param fillInJavaStackTrace whether or not to fill in the java stack trace for this exception + */ + EvalException( + Location location, + String message, + boolean dueToIncompleteAST, + boolean fillInJavaStackTrace) { + super(null, null, /*enableSuppression=*/ true, fillInJavaStackTrace); this.location = location; this.message = Preconditions.checkNotNull(message); this.dueToIncompleteAST = dueToIncompleteAST; diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java index fa1aac406f..d3dac8198c 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ReturnStatement.java @@ -18,7 +18,6 @@ import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.syntax.compiler.DebugInfo; import com.google.devtools.build.lib.syntax.compiler.LoopLabels; import com.google.devtools.build.lib.syntax.compiler.VariableScope; - import net.bytebuddy.implementation.bytecode.ByteCodeAppender; import net.bytebuddy.implementation.bytecode.member.MethodReturn; @@ -30,11 +29,12 @@ public class ReturnStatement extends Statement { /** * Exception sent by the return statement, to be caught by the function body. */ - public class ReturnException extends EvalException { + public static class ReturnException extends EvalException { Object value; public ReturnException(Location location, Object value) { - super(location, "Return statements must be inside a function"); + super(location, "Return statements must be inside a function", + /*dueToIncompleteAST=*/ false, /*fillInJavaStackTrace=*/ false); this.value = value; } -- cgit v1.2.3