Felix
  1. Felix
  2. FELIX-3636

Using @Service without @Component should log a warning

    Details

      Description

      If I use the annotation @Service without @Component no entry in the serviceComponents.xml will be generated and no warning is given out during build from the maven-scr-plugin.

      You should either implicitly generate a component if @Service is given without @Component or an error should be logged during build, since using @Service without @Component right now has no effect at all and this is never intended by someone using @Service.

        Activity

        Hide
        Carsten Ziegeler added a comment -

        A warning is now logged

        Show
        Carsten Ziegeler added a comment - A warning is now logged
        Hide
        Carsten Ziegeler added a comment -

        Unfortunately, we really have a mismatch here: as Felix wrote @Component is the marker, only classes with this annotation should be processed - however when the super classes of a component are processed, it's not checked whether the class have a @Component annotation and @Service, @Property, and @Reference are always processed. This shouldn't be the case, but it seems we always had this in the plugin ,so for compatibility we can't change this.

        I wouldn't allow classes which have a @Service but no @Component to create a component.

        So I guess, creating a warning if the project contains a class with @Service, @Property, or @Reference but no @Component is the only thing we can do

        Show
        Carsten Ziegeler added a comment - Unfortunately, we really have a mismatch here: as Felix wrote @Component is the marker, only classes with this annotation should be processed - however when the super classes of a component are processed, it's not checked whether the class have a @Component annotation and @Service, @Property, and @Reference are always processed. This shouldn't be the case, but it seems we always had this in the plugin ,so for compatibility we can't change this. I wouldn't allow classes which have a @Service but no @Component to create a component. So I guess, creating a warning if the project contains a class with @Service, @Property, or @Reference but no @Component is the only thing we can do
        Hide
        Konrad Windszus added a comment -

        If you provide @Service without @Component it has an influence on the scrinfo.xml but not on the generated serviceComponents.xml. Only the latter is evaluated by the Felix SCR. That is confusing, because usually this is not intended by the developer. Rather he implicitly assumes, that the appropriate component is automatically generated, even if he only has @Service specified.

        I propose the following change:
        If @Service is given without @Component a warning should be given out by the maven-scr-plugin. That still assures backward compatibility for the cases, where @Service was deliberately used without @Component(see comment 1). In my mind this is a very rare use case and maybe in the future using one annotation without the other should rather lead to an error. The best solution would be, to make it configurable, whether that issue should be given out as error or as warning (default).

        Show
        Konrad Windszus added a comment - If you provide @Service without @Component it has an influence on the scrinfo.xml but not on the generated serviceComponents.xml. Only the latter is evaluated by the Felix SCR. That is confusing, because usually this is not intended by the developer. Rather he implicitly assumes, that the appropriate component is automatically generated, even if he only has @Service specified. I propose the following change: If @Service is given without @Component a warning should be given out by the maven-scr-plugin. That still assures backward compatibility for the cases, where @Service was deliberately used without @Component(see comment 1). In my mind this is a very rare use case and maybe in the future using one annotation without the other should rather lead to an error. The best solution would be, to make it configurable, whether that issue should be given out as error or as warning (default).
        Hide
        Felix Meschberger added a comment -

        The @Component annotation not only provides information about the component but is also used as a marker annotation: Only if @Component is provided will the SCR plugin pick up the class (at least, this is how was done initially)

        Show
        Felix Meschberger added a comment - The @Component annotation not only provides information about the component but is also used as a marker annotation: Only if @Component is provided will the SCR plugin pick up the class (at least, this is how was done initially)
        Hide
        Konrad Windszus added a comment -

        I may have found a usecase for using @Service without @Component: Components inheriting from that service would actually use that annotation. But then you should rather include @Component(componentAbstract=true) as well to make it explicit, that you don't want to have a component created from this service.

        Show
        Konrad Windszus added a comment - I may have found a usecase for using @Service without @Component: Components inheriting from that service would actually use that annotation. But then you should rather include @Component(componentAbstract=true) as well to make it explicit, that you don't want to have a component created from this service.

          People

          • Assignee:
            Carsten Ziegeler
            Reporter:
            Konrad Windszus
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development