Reviewers: scottb,
Description:
Guard against invalid dispIds in JavaDispatchImpl
Also, rather than write an invalid dispId and wait for things to blow
up, throw
a HostedModeException if we hit a JSNI ref that shouldn't be there
Please review this at http://gwt-code-reviews.appspot.com/1172801/show
Affected files:
M dev/core/src/com/google/gwt/dev/shell/JavaDispatchImpl.java
M dev/core/src/com/google/gwt/dev/shell/Jsni.java
Index: dev/core/src/com/google/gwt/dev/shell/JavaDispatchImpl.java
===================================================================
--- dev/core/src/com/google/gwt/dev/shell/JavaDispatchImpl.java (revision
9312)
+++ dev/core/src/com/google/gwt/dev/shell/JavaDispatchImpl.java (working
copy)
@@ -61,6 +61,9 @@
* @return the field
*/
public Field getField(int dispId) {
+ if (dispId < 0) {
+ throw new RuntimeException("Field does not exist.");
+ }
Member member = getMember(dispId);
if (member instanceof SyntheticClassMember) {
@@ -82,6 +85,10 @@
* @throws IllegalArgumentException
*/
public Object getFieldValue(int dispId) {
+ if (dispId < 0) {
+ throw new RuntimeException("Field does not exist.");
+ }
+
Member member = getMember(dispId);
if (member instanceof SyntheticClassMember) {
@@ -103,6 +110,10 @@
* @return the method
*/
public MethodAdaptor getMethod(int dispId) {
+ if (dispId < 0) {
+ throw new RuntimeException("Method does not exist.");
+ }
+
Member m = getMember(dispId);
if (m instanceof Method) {
return new MethodAdaptor((Method) m);
Index: dev/core/src/com/google/gwt/dev/shell/Jsni.java
===================================================================
--- dev/core/src/com/google/gwt/dev/shell/Jsni.java (revision 9312)
+++ dev/core/src/com/google/gwt/dev/shell/Jsni.java (working copy)
@@ -106,13 +106,18 @@
Member member;
if (dispId < 0) {
- // We've already emitted a warning from getDispId; just fake the
jsni
member = null;
} else {
member =
dispatchInfo.getClassInfoByDispId(dispId).getMember(dispId);
}
-
- if (member == null || member instanceof Field
+
+ if (member == null) {
+ throw new HostedModeException(
+ "JSNI rewriter found reference to non-existent field in a
field reference or java method tear-off: "
+ + ident + " at " + x.getSourceInfo());
+ }
+
+ if (member instanceof Field
|| member instanceof SyntheticClassMember) {
if (q != null) {
accept(q);
@@ -176,18 +181,21 @@
member =
dispatchInfo.getClassInfoByDispId(dispId).getMember(dispId);
}
+ if (member == null) {
+ throw new HostedModeException(
+ "JSNI rewriter found reference to non-existent field in a
method invocation: "
+ + ref.getIdent() + " at " + ref.getSourceInfo());
+ }
+
/*
* Make sure the ident is a reference to a method or constructor
and
* not a reference to a field whose contents (e.g. a Function) we
* intend to immediately invoke.
*
* p.C::method()(); versus p.C::field();
- *
- * Also, if the reference was to a non-existent field, we'll go
ahead
- * and rewrite the call site as though -1 is a valid dispid.
+ *
*/
- if (member == null || member instanceof Method
- || member instanceof Constructor<?>) {
+ if (member instanceof Method || member instanceof
Constructor<?>) {
// Use a clone instead of modifying the original JSNI
// __gwt_makeJavaInvoke(paramCount)(obj, dispId, args)
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors