仅在编译模式+ Chrome / Safari中使用延迟绑定的ClassCastException - Firefox可以正常工作

时间:2013-05-03 15:19:08

标签: java gwt

我有一个非常奇怪的错误,只发生在chrome和safari中。

调用GWT.Create(foo.class)时出现UmbrellaException; (延期装订)

有人有任何想法吗?

我发现java脚本使用以下javascript抛出一个伞状异常:

function entry_0(jsFunction){
  return function(){
    try {
      return entry0(jsFunction, this, arguments);
    }
     catch (e) {
      throw e;
Uncaught com.google.web.bindery.event.shared.UmbrellaException: Exception caught: Exception caught: null
    }
  }
  ;
}

在gwt中关于特定的java代码

IAmsPresenterFactory factory = (IAmsPresenterFactory) GWT.create(IReflectiveAmsFactory.class);

其中IReflectiveAmsFactory是按类名(字符串)创建实例的...(class for name gwt

public class IReflectiveAmsFactory implements IAmsFactoryWrapper {

}

public interface IAmsPresenterFactory {
    IDynamicAmsPresenter newInstance(String className, AmsClientFactory clientfactory, String id);
}

    <generate-with class="ch.zhaw.ams.server.ams.AmsPresenterGenerator">
        <when-type-assignable class="ch.zhaw.ams.client.ams.IAmsFactoryWrapper" />
    </generate-with>

完整的代码段:

Request<IModuleBaseProxy> req = clientfactory.getRequestFactory().moduleRequest().findModuleBase(modtoken);
req.fire(new Receiver<IModuleBaseProxy>() {

@Override
public void onSuccess(IModuleBaseProxy response) {
    System.out.println("found");
    if (response != null) {
        ---> HERE
        IAmsPresenterFactory factory = (IAmsPresenterFactory) GWT
        ---> ERROR                          .create(IReflectiveAmsFactory.class);
        String clazz = response.getConfigSite();
        AmsClientFactory apcf = null;
        if (clientfactory == null) {
            apcf = new AmsClientFactory();
        } else {
            apcf = clientfactory;
        }
        IDynamicAmsPresenter p = factory.newInstance(clazz, apcf, modtoken);

        HasWidgets content = view.getContent();
        // ContentPresenter contentPresenter = new
        // ContentPresenter(apcf, p, new
        // ContentView(modtoken));
        p.go(content);
    }
}
});

我的发电机舱:

import java.io.PrintWriter;    
import com.google.gwt.core.ext.Generator;
import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;

public class AmsPresenterGenerator extends Generator {

    @Override
    public String generate(TreeLogger logger, GeneratorContext context, String typeName)
            throws UnableToCompleteException {

        logger.log(TreeLogger.INFO, "Generating source for " + typeName, null);
        TypeOracle typeOracle = context.getTypeOracle();
        JClassType clazz = typeOracle.findType(typeName);

        if (clazz == null) {
            logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
            throw new UnableToCompleteException();

        }

        try {
            logger.log(TreeLogger.INFO, "Generating source for " + clazz.getQualifiedSourceName(), null);
            JClassType reflectableType = typeOracle.getType("ch.zhaw.ams.client.ams.IDynamicAmsPresenter");

            SourceWriter sourceWriter = getSourceWriter(clazz, context, logger);

            if (sourceWriter != null) {
                sourceWriter.println("public " + reflectableType.getQualifiedSourceName()
                        + " newInstance(String className, AmsClientFactory clientfactory, String id) {");

                JClassType[] types = typeOracle.getTypes();

                int count = 0;
                for (int i = 0; i < types.length; i++) {
                    // System.out.println(""+types[i].getName());
                    if (types[i].isInterface() == null && types[i].isAssignableTo(reflectableType)) {
                        System.out.println("Done:" + types[i].getName());
                        if (count == 0) {
                            sourceWriter.println("   if(\"" + types[i].getQualifiedSourceName()
                                    + "\".equals(className)) {" + " return new " + types[i].getQualifiedSourceName()
                                    + "(clientfactory, id);" + "}");

                        } else {

                            sourceWriter.println("   else if(\"" + types[i].getQualifiedSourceName()
                                    + "\".equals(className)) {" + " return new " + types[i].getQualifiedSourceName()
                                    + "(clientfactory, id);" + "}");

                        }

                        count++;

                    }

                }

                sourceWriter.println("return null;");
                sourceWriter.println("}");
                sourceWriter.commit(logger);
                logger.log(TreeLogger.INFO, "Done Generating source for " + clazz.getName(), null);

                return clazz.getQualifiedSourceName() + "Wrapper";

            }

        } catch (NotFoundException e) {

            e.printStackTrace();

        }

        return null;

    }

    public SourceWriter getSourceWriter(JClassType classType, GeneratorContext context, TreeLogger logger) {

        String packageName = classType.getPackage().getName();
        String simpleName = classType.getSimpleSourceName() + "Wrapper";
        ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);

        composer.addImplementedInterface("ch.zhaw.ams.client.ams.IAmsPresenterFactory");
        PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);

        if (printWriter == null) {
            return null;
        } else {
            SourceWriter sw = composer.createSourceWriter(context, printWriter);
            return sw;
        }

    }

}

enter image description here

2 个答案:

答案 0 :(得分:0)

我解决了升级到GWT 2.5.1的问题

有编译器参数

-XdisableCastChecking

和VM参数

-Xmx512m -Xss16M

答案 1 :(得分:-1)

我认为这是Deferred Binding的问题。它非常依赖于浏览器。据我所知,如果您想编写任何依赖浏览器或依赖于语言环境的代码(如GUI更改),则必须创建它的实例而不是使用不同的延迟绑定。

正如你所说它在firefox中有效,因为它可以用firefox编译并在编译时生成firefox版本的代码。并且在运行时引导期间由特定的firefox加载,而不是为其他客户端加载。

Deferred binding is a feature of the GWT compiler that works by generating many versions of code at compile time, only one of which needs to be loaded by a particular client during bootstrapping at runtime.

Mostly internationalized applications or GWT RPC calls you will be using deferred binding

有关更多信息,请查看延迟绑定的GWT页面:

Coding Basics - Deferred Binding