Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1484

Injection of @Singleton bean into @SessionScoped bean fails with error WELD-001413

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Blocker Blocker
    • None
    • 2.0.2.Final
    • Scopes & Contexts
    • None
    • Hide

      The following three classes are needed to reproduce:

      @javax.inject.Singleton
      public class SingletonBean {
      }
      
      @javax.enterprise.context.SessionScoped
      public class SessionBean implements java.io.Serializable {
          @javax.inject.Inject SingletonBean singletonBean;
      }
      
      public class Main {
          public static void main(String[] args) {
              new org.jboss.weld.environment.se.Weld().initialize();
          }
      }
      
      Show
      The following three classes are needed to reproduce: @javax.inject.Singleton public class SingletonBean { } @javax.enterprise.context.SessionScoped public class SessionBean implements java.io.Serializable { @javax.inject.Inject SingletonBean singletonBean; } public class Main { public static void main( String [] args) { new org.jboss.weld.environment.se.Weld().initialize(); } }

      Injecting a @Singleton bean into a @SessionScoped bean fails with the following error message:

      Exception in thread "main" org.jboss.weld.exceptions.UnserializableDependencyException: WELD-001413 The bean Managed Bean [class SessionBean] with qualifiers [@Any @Default] declares passivating scope but has non-passivation-capable dependency Managed Bean [class SingletonBean] with qualifiers [@Any @Default]

      A quick look into the code revealed the following in Managedbean at line 111

      this.passivationCapableDependency = isNormalScoped() || (isDependent() && passivationCapableBean);

      Meaning that a the singleton beans can never be flagged as passivation capable dependencies because the @Singleton scope is not annotated as normale scoped and, obviously, the beans are not dependent.

      But this is against the CDI 1.1 specification 6.6.3 which clearly states that:

      The container must guarantee that:
      ...
      all singleton beans are passivation capable dependencies,
      ...

              rhn-engineering-jharting Jozef Hartinger
              rbaradari Ramin Baradari (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: