2

I am struggling with requestfactories and generics. In the code below, the proxy methods are matching exactly with the entity methods, but I get the log trace:

java.lang.NullPointerException: null
    at com.google.web.bindery.autobean.vm.impl.MethodPropertyContext.traverse(MethodPropertyContext.java:102) ~[gwt-servlet-2.6.0.jar:na]
    at com.google.web.bindery.autobean.vm.impl.MethodPropertyContext.accept(MethodPropertyContext.java:75) ~[gwt-servlet-2.6.0.jar:na]
    at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyCoderCreator.maybeCreateCoder(AutoBeanCodexImpl.java:353) ~[gwt-servlet-2.6.0.jar:na]
    at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyCoderCreator.visitReferenceProperty(AutoBeanCodexImpl.java:341) ~[gwt-servlet-2.6.0.jar:na]
    at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:324) ~[gwt-servlet-2.6.0.jar:na]
    at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:166) ~[gwt-servlet-2.6.0.jar:na]
...

My proxy class:

@ProxyFor(value = OutilLibre.class, locator = OutilLibreLocator.class)
public interface OutilLibreProxy extends ProxyWithId, ProxyWithCartoLibre<OutilProxy>, EntityProxy {

    public Long getId();

    public void setId(Long id);

    @Override
    OutilProxy getCompetence();

    @Override
    void setCompetence(OutilProxy outil);

    @Override
    String getCompetenceAutre();

    @Override
    void setCompetenceAutre(String competence);

}

The interface with generics:

public interface ProxyWithCartoLibre<T> {

    T getCompetence();

    void setCompetence(T competence);

    String getCompetenceAutre();

    void setCompetenceAutre(String competence);

}   

The corresponding server entity:

@Entity
@Table(name = "outil_libre")
public class OutilLibre extends AEntityLongId implements IBeanCartoLibre<Outil>, IUniqueVersionEntity {

    private static final long serialVersionUID = 45107725880220830L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "outil_libre_seq_gen")
    @SequenceGenerator(name = "outil_libre_seq_gen", sequenceName = "seq_outil_libre")
    @Column(name = "id", unique = true, nullable = false, precision = 5, scale = 0)
    private Long id;

    @Cascade(value = {org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "outil", nullable = false)
    private Outil outil;

    @Column(name = "outil_autre")
    private String outilAutre;

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public Outil getCompetence() {
        return outil;
    }

    @Override
    public void setCompetence(Outil outil) {
        this.outil = outil;
    }

    @Override
    public String getCompetenceAutre() {
        return outilAutre;
    }

    @Override
    public void setCompetenceAutre(String competence) {
        this.outilAutre = competence;
    }

}   

I don't know why I get this error because the ProxyWithCartoLibre interface is just used by client side classes and hasn't any purpose in defining the requestfactory.

Is there a way to tell the GWT generator to exclude the ProxyWithCartoLibre interface?

Thanks in advance.

EDIT

java.lang.NullPointerException: null
     at com.google.web.bindery.autobean.vm.impl.MethodPropertyContext.traverse(MethodPropertyContext.java:102) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.vm.impl.MethodPropertyContext.accept(MethodPropertyContext.java:75) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyCoderCreator.maybeCreateCoder(AutoBeanCodexImpl.java:353) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyCoderCreator.visitReferenceProperty(AutoBeanCodexImpl.java:341) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:324) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:166) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:101) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doCoderFor(AutoBeanCodexImpl.java:522) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.setProperty(AbstractAutoBean.java:276) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.setProperty(ProxyAutoBean.java:253) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.vm.impl.BeanPropertyContext.set(BeanPropertyContext.java:44) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.requestfactory.server.Resolver$PropertyResolver.visitValueProperty(Resolver.java:211) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:289) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:166) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:101) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.requestfactory.server.Resolver.resolveClientValue(Resolver.java:470) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.processInvocationMessages(SimpleRequestProcessor.java:491) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:233) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:135) ~[gwt-servlet.jar:na]
     at com.google.web.bindery.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:133) ~[gwt-servlet.jar:na]
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) [servlet-api.jar:na]
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) [servlet-api.jar:na]
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.39.B]
     at ch.qos.logback.access.servlet.TeeFilter.doFilter(TeeFilter.java:55) [logback-access-1.0.13.jar:na]
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.39.B]
     at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180) [spring-orm-3.2.4.RELEASE.jar:3.2.4.RELEASE]
     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.39.B]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
     at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
     at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.39.B]
     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) [catalina.jar:7.0.39.B]
     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) [catalina.jar:7.0.39.B]
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) [catalina.jar:7.0.39.B]
     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947) [catalina.jar:7.0.39.B]
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.39.B]
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [catalina.jar:7.0.39.B]
     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009) [tomcat-coyote.jar:7.0.39.B]
     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) [tomcat-coyote.jar:7.0.39.B]
     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) [tomcat-coyote.jar:7.0.39.B]
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_60]
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_60]
     at java.lang.Thread.run(Thread.java:745) [na:1.7.0_60]
7
  • I looks more complicated than it seems. This problem happens onhly at the first web page load just after server launch (debug mode super dev).
    – JFB
    Jul 10, 2014 at 12:37
  • Worth upgrading to 2.6.1? Also have you attached the debugger to see the code and state at the point of the NPE? The GWT code is quite nice so usually helpful.
    – salk31
    Jul 11, 2014 at 10:32
  • I'am already using gwt 2.6.1. And there is nothing on client side console either with super dev or standard dev mode: the error is on the server console. What I've done actually is a refactoring in order to avoid generics in the proxies. But I would like to understand why it doesn't work and if it's possible to use generics in such a way.
    – JFB
    Jul 11, 2014 at 11:06
  • Might be worth adding the 2.6.1 stack trace here so others can look at the exact line.
    – salk31
    Jul 11, 2014 at 11:29
  • Done but the trace is the same. (NB: gwt-servlet.jar is 2.6.1). Thanks for your interest.
    – JFB
    Jul 11, 2014 at 11:59

1 Answer 1

0

I also got this exception and tried a lot and came up with the following workaround:

  1. build a basic "underlying" bean/POJO model for your classes avoiding generics (in the outmost class, using generics does not seem to be a problem) and maybe using some "marker strings" like _ to help avoiding (via "optimistic" interface usage) later usage of "undesired classes/methods" or provide desired variants, e.g.:

    interface _Person< PERSON extends _Person<PERSON> > extends IsSerializable {  
                       // generics here: just to show that generics work if _Person is not 
                       // referenced itself in AutoBean (de)serialization
      int getId();
      void setId( int id );     // normally we may not want to expose this, but for the
                                // (de)serialization it is/may be necessary or benefitial 
                                // here now
      String getName();
      void setName( String name );
      //_Person setName_( String name );
                            // to have fluent setters is against Bean definition and does 
                            // not work with AutoBeans, but since there is no getter
                            // "getName()" it is ignored and would work :-)
                            // (but it may be better to not include it in here)
      _Address getAddr_();
      void setAddr_( _Address addr );
    }
    
    //interface _Address< ADDR extends _Address > extends IsSerializable {
      // => would e.g. cause the NullPointerException ! :-(
      //    at com.google.web.bindery.autobean.vm.impl.MethodPropertyContext.traverse(
      //         MethodPropertyContext.java:102) ~[gwt-user-2.6.0.jar:na]
    interface _Address extends IsSerializable {
       String getCity_();
       void setCity_( String city );
    }
    
    • now using this with AutoBean functionality will work on those and if one uses generic interfaces and implementations around these later on should work (I tried only a simple example like this to test it for me). Example with above should work (incomplete snippet): AutoBeanCodex.encode( personAutoBean ).deepCopy()
  2. now creating generic interfaces and classes inheriting from those would have the disadvantage of e.g. not beeing able to

    • return a generic person.getAddr_().getNonBeanFooExtension() or
    • utilize a fluent interface like person.setName_( "foo" ).setMail( "bar" ) or
    • preventing/discourage access to person.setId( 123 )

    Therefore I am planning now (I'll report back when it's done) to derive from these beens nevertheless, but also writing "inheritance unrelated"/overlapping interfaces, that are/should be "normally" used throughout the business application, e.g.:

    interface Person< PERSON extends Person<PERSON>> {
       // extends _Person <= no, because then we could not "hide/discourage" users calling 
       // e.g. "setId(....)"
      int getId();
    
      String getName();
      //void setName( String name );  // we could provide it, but setName_() does the same
                                      // and more and only one setter keeps the interface 
                                      // smaller
      PERSON setName_( String name );
      Address<PERSON> getAddr();
      PERSON setAddr( Address<PERSON> addr );
    
      PERSON setFancyThing();          // not "seen" by AutoBean and thus should not 
                                       // cause trouble there
    }
    
    interface Address< PERSON extends Person<PERSON> > {
      ...
    }
    
  3. now implementing classes like this should work in general (only tested simple case for now):

    class PersonDTO implements Person<PersonDTO>, _Person<PersonDTO> {
      ...
    }
    
  4. the "users" of those implementations should as much as possible work with the interfaces from 2. Person<PersonDto> pers = ... so they see some quite nice person interface and can't easily call pers.setId( 123 ), but pers.setName_( "Dimitri Khalezov" ).setMail_( ... )

It's already a long post and I hope you can imagine the missing details in various locations.

1
  • Thanks for the reply. Your solution is quite a bit different from what I wanted to do, but it's still interesting.NB: I solved this issues some time ago by just not using generic (I used object ids instead).
    – JFB
    Feb 11, 2015 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.