GWT RequestFactory 抛出 java.lang.UnsupportedOperationException: <Proxy 接口类>,来自 ValueCodex.getTy



在我们的应用程序中,我们需要在GWT客户端和服务器之间共享域代码。因此,我们为GWT代理和服务器端实体使用了通用接口。@thomas broyer曾在这里描述过这种方法:https://stackoverflow.com/a/15852887/187241

异常堆栈跟踪:

    ERROR com.google.web.bindery.requestfactory.server.SimpleRequestProcessor - Error while processing request 
    java.lang.UnsupportedOperationException: se.homework.hwbs.domain.shared.model.IAppointment
        at com.google.web.bindery.autobean.shared.ValueCodex.getTypeOrDie(ValueCodex.java:388)
        at com.google.web.bindery.autobean.shared.ValueCodex.decode(ValueCodex.java:312)
        at com.google.web.bindery.requestfactory.shared.impl.EntityCodex.decode(EntityCodex.java:107)
        at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor$3.visitReferenceProperty(SimpleRequestProcessor.java:633)
        at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:370)
        at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:162)
        at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:97)
        at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.processOperationMessages(SimpleRequestProcessor.java:623)

共享代码:

    public interface IAppointment {
        IPlace getPlace();
    }
    public interface AppointmentProxy extends EntityProxy, IAppointment {
        @Override
        PlaceProxy getPlace();
    }
    public interface PlaceProxy extends EntityProxy, IPlace {
        @Override
        Long getId();
    }
    public interface IPlace extends IDatabaseEntity {
        @Override
        Long getId();
    }
    public interface IDatabaseEntity {
        public Long getId();
    }

如果我们正确理解GWT代码,那么问题的原因来自ProxyAutoBean:

    for (Method method : beanType.getMethods()) {
        if (BeanMethod.GET.matches(method)) {
            toReturn.getters.add(method);

其中CCD_ 2是CCD_。Java反射为此类接口返回两个方法(仅在超级开发模式下发生…)

    public **abstract** PlaceProxy AppointmentProxy.getPlace()
    public **default** IPlace AppointmentProxy.getPlace()

第一个是GWT RequestFactory代码所期望并接受的,第二个不是。。。并导致java.lang.UnsupportedOperationException: IAppointment异常。非常奇怪的事实是,我们只有在已编译的GWT应用程序中才有这个问题。当我们使用超级开发模式从IDE启动应用程序时,第二个default ...方法没有列出,并且应用程序正在正常工作。

环境:

  • GWT2.6.1
  • Java版本1.8.0_66

你对如何解决这个问题有什么想法吗?

这可能是https://github.com/gwtproject/gwt/issues/5925已在2.7中固定。

最新更新