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

Observers with classloading problems should not be ignored

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      BeanDeployer uses reflection to find declared members of classes. When any member's class is missing from the classpath, a ClassNotFoundException is thrown by Class.getDeclaredXxx(). Weld catches this exception and ignores the class (no bean of that type will be registered) - see WELD-644.

      While ignoring external classes (such as described in WELD-644) is ok, the fix introduces a new problem.

      Consider the following observer:

      class VeryImportantObserver {
          @Inject MissingBean missingBean;
      
          public void observe(@Observes SomeEvent event) {
              ...
          }
      }
      

      If MissingBean is missing from the classpath, Weld will ignore VeryImportantObserver.

      The effect is that VeryImportantObserver will not be invoked. For non-observer beans, this isn't a big problem, since you usually inject the bean into some other bean and Weld will throw an Unsatisfied dependencies exception. For observers that are not injected into anything, no such exception will be thrown. The observer will simply be ignored quietly (well actually, a single log line (with log level INFO, not WARN!) will be printed in the log, but this is definitely not loud enough).

      According to the spec, these kinds of cases should not be ignored at all:

      The container must validate all injection points of all enabled beans, all observer methods, all disposer methods and all other Java EE component classes supporting injection when the application is initialized to ensure that there are no unsatisfied or unresolvable ambiguous dependencies.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                jharting Jozef Hartinger
                Reporter:
                luksa Marko Luksa
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: