Commits

Anonymous committed d7ca195

XWork guice container issues with constants
o fixing problem with optional constants on constructors causing exceptions

Issue Number: XW-601

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1767e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits ccd392f

Comments (0)

Files changed (1)

File src/java/com/opensymphony/xwork2/inject/ContainerImpl.java

       constructor = findConstructorIn(implementation);
       constructor.setAccessible(true);
 
+      MissingDependencyException exception = null;
+      Inject inject = null;
+      ParameterInjector<?>[] parameters = null;
+        
       try {
-        Inject inject = constructor.getAnnotation(Inject.class);
-        parameterInjectors = inject == null
-            ? null // default constructor.
-            : container.getParametersInjectors(
-                constructor,
-                constructor.getParameterAnnotations(),
-                constructor.getParameterTypes(),
-                inject.value()
-              );
+        inject = constructor.getAnnotation(Inject.class);
+        parameters = constructParameterInjector(inject, container, constructor);
       } catch (MissingDependencyException e) {
-        throw new DependencyException(e);
+        exception = e;
+      }
+      parameterInjectors = parameters;
+
+      if ( exception != null) {
+        if ( inject != null && inject.required()) {
+          throw new DependencyException(exception);
+        }
       }
       injectors = container.injectors.get(implementation);
     }
 
+    ParameterInjector<?>[] constructParameterInjector(
+    Inject inject, ContainerImpl container, Constructor<T> constructor) throws MissingDependencyException{
+    return constructor.getParameterTypes().length == 0
+      ? null // default constructor.
+      : container.getParametersInjectors(
+        constructor,
+        constructor.getParameterAnnotations(),
+        constructor.getParameterTypes(),
+        inject.value()
+      );
+    }
+
     @SuppressWarnings("unchecked")
     private Constructor<T> findConstructorIn(Class<T> implementation) {
       Constructor<T> found = null;