0

我有一个非常奇怪的错误,只发生在 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 是按类名(字符串)创建实例...(名称 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;
        }

    }

}

在此处输入图像描述

4

2 回答 2

0

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

有编译器参数

-XdisableCastChecking

和 VM 参数

-Xmx512m -Xss16M

于 2013-05-05T10:13:08.573 回答
-1

我认为这是延迟绑定的问题。它非常依赖于浏览器。据我所知,如果您想编写任何依赖于浏览器或依赖于语言环境的代码,例如 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 页面:

编码基础 - 延迟绑定

于 2013-05-03T16:59:36.480 回答