glassfish
  1. glassfish
  2. GLASSFISH-11923

Package private constructors cause CDI instantiation & injection point resolution to fail

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Incomplete
    • Affects Version/s: V3
    • Fix Version/s: 3.1
    • Component/s: cdi
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Linux

    • Issuezilla Id:
      11,923

      Description

      While the workaround for this issue is to not use a package-private constructor,
      the use-case should work, and does work on JBoss AS 6

      ---- Create an Extension:

      /*

      • JBoss, Home of Professional Open Source
      • Copyright 2010, Red Hat, Inc., and individual contributors
      • by the @authors tag. See the copyright.txt in the distribution for a
      • full listing of individual contributors.
        *
      • Licensed under the Apache License, Version 2.0 (the "License");
      • you may not use this file except in compliance with the License.
      • You may obtain a copy of the License at
      • http://www.apache.org/licenses/LICENSE-2.0
      • Unless required by applicable law or agreed to in writing, software
      • distributed under the License is distributed on an "AS IS" BASIS,
      • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      • See the License for the specific language governing permissions and
      • limitations under the License.
        */
        package org.jboss.weld.extensions.interceptor;

      import java.util.Collection;
      import java.util.Collections;
      import java.util.HashSet;

      import javax.enterprise.event.Observes;
      import javax.enterprise.inject.spi.Extension;
      import javax.enterprise.inject.spi.Interceptor;
      import javax.enterprise.inject.spi.ProcessBean;

      public class InterceptorExtension implements Extension
      {

      private final Collection<Class<?>> enabledInterceptors;

      InterceptorExtension()

      { this.enabledInterceptors = Collections.synchronizedSet(new HashSet<Class<?>>()); }

      @SuppressWarnings("unused")
      void observeInterceptors(@Observes ProcessBean<?> pmb)
      {
      if (pmb.getBean() instanceof Interceptor<?>)

      { this.enabledInterceptors.add(pmb.getBean().getBeanClass()); }

      }

      Collection<Class<?>> getEnabledInterceptors()

      { return enabledInterceptors; }

      }

      ----- Register it in META-INF/services/javax.enterprise.inject.spi.Extension:

      org.jboss.weld.extensions.interceptor.InterceptorExtension

      ----- Reference it in another class within the same package:

      /*

      • JBoss, Home of Professional Open Source
      • Copyright 2010, Red Hat, Inc., and individual contributors
      • by the @authors tag. See the copyright.txt in the distribution for a
      • full listing of individual contributors.
        *
      • Licensed under the Apache License, Version 2.0 (the "License");
      • you may not use this file except in compliance with the License.
      • You may obtain a copy of the License at
      • http://www.apache.org/licenses/LICENSE-2.0
      • Unless required by applicable law or agreed to in writing, software
      • distributed under the License is distributed on an "AS IS" BASIS,
      • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      • See the License for the specific language governing permissions and
      • limitations under the License.
        */
        package org.jboss.weld.extensions.interceptor;

      import javax.inject.Inject;

      public class Interceptors
      {

      @Inject
      private InterceptorExtension interceptorExtension;

      private Interceptors()
      {
      }

      public boolean isInterceptorEnabled(Class<?> clazz)

      { return interceptorExtension.getEnabledInterceptors().contains(clazz); }

      }

      ----- Deploy a beans-enabled application containing this code to GlassFish, the
      deployment will fail with:

      "Unsatisfied injection point: Interceptors.interceptorExtension"

        Activity

        Hide
        Alexis MP added a comment -

        Cc

        Show
        Alexis MP added a comment - Cc
        Hide
        rogerk added a comment -

        Assign to Siva

        Show
        rogerk added a comment - Assign to Siva
        Hide
        Sivakumar Thyagarajan added a comment -

        I can't seem to reproduce this issue now with the latest GlassFish 3.1. The test
        case I used to reproduce this is at [1].

        Please feel free to re-open this issue, if you could reproduce this again.

        Thanks.
        [1] https://glassfish-svn.dev.java.net/source/browse/glassfish-
        svn/trunk/v2/appserv-tests/devtests/cdi/portable-extensions/package-private-
        extension-constructor

        Show
        Sivakumar Thyagarajan added a comment - I can't seem to reproduce this issue now with the latest GlassFish 3.1. The test case I used to reproduce this is at [1] . Please feel free to re-open this issue, if you could reproduce this again. Thanks. [1] https://glassfish-svn.dev.java.net/source/browse/glassfish- svn/trunk/v2/appserv-tests/devtests/cdi/portable-extensions/package-private- extension-constructor

          People

          • Assignee:
            Sivakumar Thyagarajan
            Reporter:
            lincolnbaxter
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: