- Assertions are now always on in user code in hosted mode
- Removed the automatic warning caused by throwing a Java exception into JavaScript; this is no longer needed because our exception propagation is much better than it used to be

- Cleaned up checkstyle in IDispatchImpl and CoverageTest

Issue: #1984
Review by: bobv (postmortem)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1886 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java b/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
index 4be6153..3690d82 100644
--- a/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
+++ b/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
@@ -242,6 +242,9 @@
     this.compiler = compiler;
     this.typeOracle = typeOracle;
 
+    // Assertions are always on in hosted mode.
+    setDefaultAssertionStatus(true);
+
     // SPECIAL MAGIC: Prevents the compile process from ever trying to compile
     // these guys from source, which is what we want, since they are special and
     // neither of them would compile correctly from source.
diff --git a/dev/core/src/com/google/gwt/dev/shell/ModuleSpace.java b/dev/core/src/com/google/gwt/dev/shell/ModuleSpace.java
index 3c4cb8d..a65ab18 100644
--- a/dev/core/src/com/google/gwt/dev/shell/ModuleSpace.java
+++ b/dev/core/src/com/google/gwt/dev/shell/ModuleSpace.java
@@ -32,8 +32,6 @@
 
   private static ThreadLocal<Throwable> sCaughtJavaExceptionObject = new ThreadLocal<Throwable>();
 
-  private static ThreadLocal<Throwable> sLastThrownJavaException = new ThreadLocal<Throwable>();
-
   private static ThreadLocal<Throwable> sThrownJavaExceptionObject = new ThreadLocal<Throwable>();
 
   /**
@@ -42,12 +40,6 @@
   private static ThreadLocal<TreeLogger> threadLocalLogger = new ThreadLocal<TreeLogger>();
 
   public static void setThrownJavaException(Throwable t) {
-    Throwable was = sLastThrownJavaException.get();
-    if (was != t) {
-      // avoid logging the same exception twice
-      getLogger().log(TreeLogger.WARN, "Exception thrown into JavaScript", t);
-      sLastThrownJavaException.set(t);
-    }
     sThrownJavaExceptionObject.set(t);
   }
 
@@ -138,9 +130,6 @@
     //
     clearJavaScriptHost();
 
-    // Clear out the exception field, it may be holding a user-space object
-    sLastThrownJavaException.set(null);
-
     // Clear out the class loader's cache
     host.getClassLoader().clear();
   }
@@ -400,6 +389,7 @@
     }
   }
 
+  @SuppressWarnings("unchecked")
   public Object rebindAndCreate(String requestedClassName)
       throws UnableToCompleteException {
     Throwable caught = null;
@@ -514,6 +504,7 @@
     throw thrown;
   }
 
+  @SuppressWarnings("unused")
   protected boolean isExceptionSame(Throwable original, int number,
       String name, String message) {
     // For most platforms, the null exception means we threw it.
diff --git a/dev/windows/src/com/google/gwt/dev/shell/ie/IDispatchImpl.java b/dev/windows/src/com/google/gwt/dev/shell/ie/IDispatchImpl.java
index a0dae86..09103b1 100644
--- a/dev/windows/src/com/google/gwt/dev/shell/ie/IDispatchImpl.java
+++ b/dev/windows/src/com/google/gwt/dev/shell/ie/IDispatchImpl.java
@@ -261,6 +261,7 @@
   }
 
   // CHECKSTYLE_OFF
+  @SuppressWarnings("unused")
   private final int GetIDsOfNames(int riid, int rgszNames, int cNames,
       int lcid, int rgDispId) {
 
@@ -288,6 +289,7 @@
     return COM.S_OK;
   }
 
+  @SuppressWarnings("unused")
   private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags,
       int pDispParams, int pVarResult, int pExcepInfo, int pArgErr) {
 
diff --git a/user/test/com/google/gwt/dev/jjs/test/CoverageTest.java b/user/test/com/google/gwt/dev/jjs/test/CoverageTest.java
index 7e14d64..a975fc4 100644
--- a/user/test/com/google/gwt/dev/jjs/test/CoverageTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/CoverageTest.java
@@ -22,6 +22,7 @@
  * possible in the Java to JavaScript compiler. This test is not at all intended
  * to execute correctly.
  */
+@SuppressWarnings("hiding")
 public class CoverageTest extends CoverageBase {
 
   /**
@@ -70,6 +71,7 @@
       };
 
       class NamedLocal extends Inner {
+        @SuppressWarnings("unused")
         public void foo() {
           CoverageTest.this.getNext();
           Inner.this.bar();
@@ -80,6 +82,7 @@
         // JDT bug? This works in 5.0 but not in 1.4
         // TODO: will javac compile it?
         class NamedLocalSub extends NamedLocal {
+          @SuppressWarnings("unused")
           public void foo() {
             Inner.this.bar();
             NamedLocal.this.foo();
@@ -151,8 +154,7 @@
     private void testAssertStatement() {
       // AssertStatement
 
-      // Only test asserts if they're enabled
-      if (! CoverageTest.class.desiredAssertionStatus()) {
+      if (!CoverageTest.class.desiredAssertionStatus()) {
         return;
       }
 
@@ -270,18 +272,28 @@
         ++x;
         inner : while (z) {
           ++i;
-          if (i == 1)
+          if (i == 1) {
             continue;
-          if (i == 2)
+          }
+          if (i == 2) {
+            continue inner;
+          }
+          if (i == 3) {
             continue outer;
-          if (i == 3)
+          }
+          if (i == 4) {
             break;
-          if (i == 4)
+          }
+          if (i == 5) {
+            break inner;
+          }
+          if (i == 6) {
             break outer;
+          }
         }
       }
-      assertEquals(4, i);
-      assertEquals(3, x);
+      assertEquals(6, i);
+      assertEquals(4, x);
     }
 
     private void testCaseSwitchStatement() {
@@ -302,6 +314,7 @@
       assertEquals(15, i);
     }
 
+    @SuppressWarnings("cast")
     private void testCastExpression() {
       // CastExpression
       o = (Super) o;
@@ -361,9 +374,9 @@
       // DoStatement
       i = 3;
       z = false;
-      do
+      do {
         i += j;
-      while (z);
+      } while (z);
       assertEquals(5, i);
     }
 
@@ -392,8 +405,9 @@
     private void testForStatement() {
       // ForStatement
       i = 0;
-      for (int q = 0, v = 4; q < v; ++q)
+      for (int q = 0, v = 4; q < v; ++q) {
         i += q;
+      }
       assertEquals(6, i);
       for (i = 0; i < 4; ++i) {
       }
@@ -403,16 +417,19 @@
     private void testIfStatement() {
       // IfStatement
       z = false;
-      if (z)
+      if (z) {
         fail();
-      if (z)
+      }
+      if (z) {
         fail();
-      else
+      } else {
         assertFalse(z);
-      if (!z)
+      }
+      if (!z) {
         assertFalse(z);
-      else
+      } else {
         fail();
+      }
     }
 
     private void testInstanceOfExpression() {
@@ -484,7 +501,6 @@
 
     private void testQualifiedNameReference() {
       // QualifiedNameReference
-      // TODO: fields????
       CoverageTest m = new CoverageTest();
       ia = new int[2];
       assertEquals("1", 2, ia.length);
@@ -561,8 +577,9 @@
     private void testReturnStatement() {
       // ReturnStatement
       assertEquals("foo", doReturnFoo());
-      if (true)
+      if (true) {
         return;
+      }
       fail();
     }
 
@@ -613,9 +630,6 @@
     private void testWhileStatement() {
       // WhileStatement
       z = false;
-      while (z)
-        fail();
-
       while (z) {
         fail();
       }
@@ -735,8 +749,9 @@
   }
 
   private static String doReturnFoo() {
-    if (true)
+    if (true) {
       return "foo";
+    }
     fail();
     return "bar";
   }
diff --git a/user/test/com/google/gwt/dev/jjs/test/HostedTest.java b/user/test/com/google/gwt/dev/jjs/test/HostedTest.java
index 7472d5e..bac67d4 100644
--- a/user/test/com/google/gwt/dev/jjs/test/HostedTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/HostedTest.java
@@ -194,6 +194,12 @@
     assertEquals(Integer.MIN_VALUE, passThroughInt(Integer.MIN_VALUE));
   }
 
+  public void testAssertionsAlwaysOn() {
+    if (!GWT.isScript()) {
+      assertTrue(HostedTest.class.desiredAssertionStatus());
+    }
+  }
+  
   /*
    * Test that returning JavaScript boxed primitives works as expected. Note
    * that Boolean and Number cannot be supported properly in web mode, so we do
@@ -558,9 +564,12 @@
   private native void jsniL()/*-{}-*/;
 
   // test that JS can pass a series of arguments to a varargs function
-  private native String[] varargsFromJS1() /*-{
-    return this.@com.google.gwt.dev.jjs.test.HostedTest::varargsPassthrough([Ljava/lang/String;)("foo", "bar");
-  }-*/;
+  // TODO: not sure if we want to support this
+  // private native String[] varargsFromJS1() /*-{
+  // return
+  // this.@com.google.gwt.dev.jjs.test.HostedTest::varargsPassthrough([Ljava/lang/String;)("foo",
+  // "bar");
+  // }-*/;
 
   // test that JS can pass a Java-created array to a varargs function
   private native String[] varargsFromJS2(String[] arr) /*-{