Add numeric group to InternalPreconditons
...for exceptions related to numeric operations.
Change-Id: I0961789a12f7e1ca9b41994e94759b013c50d8c0
Review-Link: https://gwt-review.googlesource.com/#/c/15310/
diff --git a/user/super/com/google/gwt/emul/Preconditions.gwt.xml b/user/super/com/google/gwt/emul/Preconditions.gwt.xml
index 8fc04df..d59aa10 100644
--- a/user/super/com/google/gwt/emul/Preconditions.gwt.xml
+++ b/user/super/com/google/gwt/emul/Preconditions.gwt.xml
@@ -17,9 +17,11 @@
<define-property name="jre.checks.bounds" values="AUTO,ENABLED,DISABLED" />
<define-property name="jre.checks.api" values="AUTO,ENABLED,DISABLED" />
+ <define-property name="jre.checks.numeric" values="AUTO,ENABLED,DISABLED" />
<define-property name="jre.checks.type" values="AUTO,ENABLED,DISABLED" />
<set-property name="jre.checks.bounds" value="AUTO" />
<set-property name="jre.checks.api" value="AUTO" />
+ <set-property name="jre.checks.numeric" value="AUTO" />
<set-property name="jre.checks.type" value="AUTO" />
<define-property name="jre.checks.checkLevel" values="NORMAL,OPTIMIZED,MINIMAL" />
diff --git a/user/super/com/google/gwt/emul/javaemul/internal/InternalPreconditions.java b/user/super/com/google/gwt/emul/javaemul/internal/InternalPreconditions.java
index f47a491..693d296 100644
--- a/user/super/com/google/gwt/emul/javaemul/internal/InternalPreconditions.java
+++ b/user/super/com/google/gwt/emul/javaemul/internal/InternalPreconditions.java
@@ -35,6 +35,8 @@
* │ │ │IllegalArgumentException │
* │ │ │ConcurrentModificationException│
* ├────────┼─────────────────────────────────────────────────────┼───────────────────────────────┤
+ * │NUMERIC │Checks related to numeric operations. │ArithmeticException │
+ * ├────────┼─────────────────────────────────────────────────────┼───────────────────────────────┤
* │TYPE │Checks related to java type system. │ClassCastException │
* │ │ │ArrayStoreException │
* ├────────┼─────────────────────────────────────────────────────┼───────────────────────────────┤
@@ -70,6 +72,7 @@
public final class InternalPreconditions {
private static final String CHECK_TYPE = getProperty("jre.checks.type");
+ private static final String CHECK_NUMERIC = getProperty("jre.checks.numeric");
private static final String CHECK_BOUNDS = getProperty("jre.checks.bounds");
private static final String CHECK_API = getProperty("jre.checks.api");
@@ -95,6 +98,8 @@
(CHECK_BOUNDS.equals("AUTO") && LEVEL_NORMAL_OR_HIGHER) || CHECK_BOUNDS.equals("ENABLED");
private static final boolean IS_API_CHECKED =
(CHECK_API.equals("AUTO") && LEVEL_NORMAL_OR_HIGHER) || CHECK_API.equals("ENABLED");
+ private static final boolean IS_NUMERIC_CHECKED =
+ (CHECK_NUMERIC.equals("AUTO") && LEVEL_NORMAL_OR_HIGHER) || CHECK_NUMERIC.equals("ENABLED");
private static final boolean IS_ASSERTED = getProperty("jre.checkedMode").equals("ENABLED");
@@ -179,6 +184,24 @@
}
}
+ public static void checkArithmetic(boolean expression) {
+ if (IS_NUMERIC_CHECKED) {
+ checkCriticalArithmetic(expression);
+ } else if (IS_ASSERTED) {
+ try {
+ checkCriticalArithmetic(expression);
+ } catch (Exception e) {
+ throw new AssertionError(e);
+ }
+ }
+ }
+
+ public static void checkCriticalArithmetic(boolean expression) {
+ if (!expression) {
+ throw new ArithmeticException();
+ }
+ }
+
/**
* Ensures the truth of an expression involving existence of an element.
*/