Reviewers: scottb, Lex,

Description:
If Java optimizers are not run to full completion (part of another
proposed patch),
a JPrimitiveType can sneak into one side of a binary operation and cause
a ClassCastException
trying to test for a String.


Please review this at http://gwt-code-reviews.appspot.com/897803/show

Affected files:
  M dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java


Index: dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java
===================================================================
--- dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java (revision 8829) +++ dev/core/src/com/google/gwt/dev/jjs/impl/EqualityNormalizer.java (working copy)
@@ -81,8 +81,8 @@
         return;
       }

-      StringStatus lhsStatus = getStringStatus((JReferenceType) lhsType);
-      StringStatus rhsStatus = getStringStatus((JReferenceType) rhsType);
+      StringStatus lhsStatus = getStringStatus(lhsType);
+      StringStatus rhsStatus = getStringStatus(rhsType);
int strat = COMPARISON_STRAT[lhsStatus.getIndex()][rhsStatus.getIndex()];

       switch (strat) {
@@ -141,17 +141,19 @@
       }
     }

-    private StringStatus getStringStatus(JReferenceType type) {
-      JClassType stringType = program.getTypeJavaLangString();
-      if (type == program.getTypeNull()) {
-        return StringStatus.NULL;
-      } else if (program.typeOracle.canTriviallyCast(type, stringType)) {
-        return StringStatus.STRING;
- } else if (program.typeOracle.canTheoreticallyCast(type, stringType)) {
-        return StringStatus.UNKNOWN;
-      } else {
-        return StringStatus.NOTSTRING;
-      }
+    private StringStatus getStringStatus(JType type) {
+      if (type instanceof JReferenceType) {
+        JReferenceType refType = (JReferenceType) type;
+        JClassType stringType = program.getTypeJavaLangString();
+        if (refType == program.getTypeNull()) {
+          return StringStatus.NULL;
+ } else if (program.typeOracle.canTriviallyCast(refType, stringType)) {
+          return StringStatus.STRING;
+ } else if (program.typeOracle.canTheoreticallyCast(refType, stringType)) {
+          return StringStatus.UNKNOWN;
+        }
+      }
+      return StringStatus.NOTSTRING;
     }

     private JExpression maskUndefined(JExpression lhs) {
@@ -222,5 +224,4 @@
     BreakupAssignOpsVisitor breaker = new BreakupAssignOpsVisitor();
     breaker.accept(program);
   }
-
 }


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to