Geronimo
  1. Geronimo
  2. GERONIMO-5090 Upgrade from java ee 5 to java ee 6 support
  3. GERONIMO-5178

Inconsistent handling of META-INF/services files by different Geronmo specs.

    Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 3.0-M1
    • Component/s: osgi
    • Security Level: public (Regular issues)
    • Labels:
      None

      Description

      A number of the Geronimo specs use the provider resolution pattern defined by the ServiceLoader class in Java 6 to resolve different provider classes. In this pattern, a file with a given class name in the META-INF/services directory can define one or more provider classes for a given source interface name. As implemented by the ServiceLoader class, these files can contain multiple lines with pure comment lines and line comments on lines that define classes, as well as multiple providers defined per file. Thus a file like this would be considered valiid:

      1. A set of provider classes for the blah.blah interface
        org.apache.geronimo.foo.BlahImpl # The default first one
        org.apache.geronimo.bar.BlahImpl # The secondary fall back.

      The different spec projects that use these files parse them under different assumptions:

      • Some unilaterally take the first line without any comment processing at all or recognition that there might be multiple providers defined per file.
      • Some projects allow for pure comment lines but don't parse for comments on a definition line.
      • Not all projects are opening these files assuming a utf-8 encoding.

      This could best be solved by refactoring the code to use some common methods. This refactoring will also allow OSGi-awareness to be added to the service file lookups.

        Activity

        Hide
        Donald Woods added a comment -

        Rick, please ping me before changing the jpa_2.0_spec code, as we've had some long discussions about how this should be handled over in OpenJPA (we currently allow multiple providers to be specified as allowed by the Java ServiceLoader spec) and have some legacy behaviors we need to support (like allowing users to override the provider via properties.) There are also some tie-ins with Apache Aries JPA support and we need the Spec API to continue support for Java SE 5 users and not rely on any Java SE 6 only APIs/behaviors.

        Show
        Donald Woods added a comment - Rick, please ping me before changing the jpa_2.0_spec code, as we've had some long discussions about how this should be handled over in OpenJPA (we currently allow multiple providers to be specified as allowed by the Java ServiceLoader spec) and have some legacy behaviors we need to support (like allowing users to override the provider via properties.) There are also some tie-ins with Apache Aries JPA support and we need the Spec API to continue support for Java SE 5 users and not rely on any Java SE 6 only APIs/behaviors.
        Hide
        Rick McGuire added a comment -

        Ok, will do. I don''t believe I'm introducing anything that will be a problem here. I'm not changing the lookup order at all, just delegating the reading/parsing of the META-INF/services files to methods I'm adding to the ProviderLocator class that is already getting included in the bundle as a result of my prior updates. I've avoided using the ServiceLoader class for some of this stuff for precisely that reason.

        Show
        Rick McGuire added a comment - Ok, will do. I don''t believe I'm introducing anything that will be a problem here. I'm not changing the lookup order at all, just delegating the reading/parsing of the META-INF/services files to methods I'm adding to the ProviderLocator class that is already getting included in the bundle as a result of my prior updates. I've avoided using the ServiceLoader class for some of this stuff for precisely that reason.
        Hide
        Donald Woods added a comment -

        General question on discovering Providers.
        In the JPA2 spec api, we now have something like -
        try {
        // add each one to our list
        List<Object> serviceProviders = ProviderLocator.getServices(PersistenceProvider.class.getName(), this.getClass(), cl);
        for (Object o : serviceProviders)

        { providers.add((PersistenceProvider)o); }

        } catch (ClassNotFoundException e) {
        . . .
        Since multiple providers can be listed in one services file, should the failure/exception to load one cause none of them to be returned? Should we silently eat or log the exceptions and just return null if we fail to load any of the configured providers?

        Show
        Donald Woods added a comment - General question on discovering Providers. In the JPA2 spec api, we now have something like - try { // add each one to our list List<Object> serviceProviders = ProviderLocator.getServices(PersistenceProvider.class.getName(), this.getClass(), cl); for (Object o : serviceProviders) { providers.add((PersistenceProvider)o); } } catch (ClassNotFoundException e) { . . . Since multiple providers can be listed in one services file, should the failure/exception to load one cause none of them to be returned? Should we silently eat or log the exceptions and just return null if we fail to load any of the configured providers?
        Hide
        Rick McGuire added a comment -

        Unfortunately, there has been no guidance on any of the specifications on how this should be handled. Most of the spec implementations would fail immediately if there was a classloading or instantiation failure when processing any of the META-INF/services files it located, so that's how I ended up coding the ProviderLocator.getServices() call. We end up with multiple levels of log points in this whole stack, so I suspect throwing the exception is the appropriate way to handle this.

        Show
        Rick McGuire added a comment - Unfortunately, there has been no guidance on any of the specifications on how this should be handled. Most of the spec implementations would fail immediately if there was a classloading or instantiation failure when processing any of the META-INF/services files it located, so that's how I ended up coding the ProviderLocator.getServices() call. We end up with multiple levels of log points in this whole stack, so I suspect throwing the exception is the appropriate way to handle this.
        Hide
        Rick McGuire added a comment -

        All spec implementations now use a comment service to resolve the services providers and the processing orders have been made compliant with the individual spec requirements.

        Show
        Rick McGuire added a comment - All spec implementations now use a comment service to resolve the services providers and the processing orders have been made compliant with the individual spec requirements.

          People

          • Assignee:
            Rick McGuire
            Reporter:
            Rick McGuire
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development