Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2182

NullPointerException at org.apache.logging.log4j.util.Activator.loadProvider(Activator.java:81) in log4j 2.10.0

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.10.0
    • Fix Version/s: 2.11.0
    • Component/s: Boot
    • Labels:
      None

      Description

      I use log4j 2.10.0 in project development, But there is Exception occurs:

      2018-01-11 12:22:13,515 Start Level: Equinox Container: 3a750538-5739-473e-a609-4213b1901911 WARN Problem checking bundle org.apache.logging.log4j.coreconf for Log4j 2 provider. java.lang.NullPointerException
      at org.apache.logging.log4j.util.Activator.loadProvider(Activator.java:81)
      at org.apache.logging.log4j.util.Activator.loadProvider(Activator.java:70)
      at org.apache.logging.log4j.util.Activator.start(Activator.java:113)
      at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:774)
      at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:767)
      at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:724)
      at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:932)
      at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:309)
      at org.eclipse.osgi.container.Module.doStart(Module.java:581)
      at org.eclipse.osgi.container.Module.start(Module.java:449)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1620)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1600)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1571)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1514)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
      at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
      at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

      I checked the code, The ERROR occurs in Activator.class in org.apache.logging.log4j.util in log4j-api-2.10.0.jar:

      77 private void loadProvider(BundleContext context, BundleWiring bundleWiring)
      78 {
      79 + String filter = "(APIVersion>=2.60)";
      80 + try {
      81 + Collection<ServiceReference<Provider>> serviceReferences = context.getServiceReferences(Provider.class, "(APIVersion>=2.60)");
      82 + Provider maxProvider = null;
      83 + for (ServiceReference<Provider> serviceReference : serviceReferences) {
      84 + Provider provider = (Provider)context.getService(serviceReference);
      85 + if ((maxProvider == null) || (provider.getPriority().intValue() > maxProvider.getPriority().intValue()))
      86 +

      { maxProvider = provider; 87 + }

      88 + }
      89 + if (maxProvider != null)
      90 +

      { ProviderUtil.addProvider(maxProvider); 91 + }

      92 + }
      93 + catch (InvalidSyntaxException ex)
      94 +

      { LOGGER.error("Invalid service filter: (APIVersion>=2.60)", ex); 95 + }

      List<URL> urls = bundleWiring.findEntries("META-INF", "log4j-provider.properties", 0);
      for (URL url : urls)

      { ProviderUtil.loadProvider(url, bundleWiring.getClassLoader()); }

      }

      compared with log4j-api-2.8.jar, we can see the codes marked with '+' are the new added codes in 2.10.0, The Exceptions occur because in line 81, context is null. But checking getBundleContext method in OSGI, we can see getBundleContext could return null if this bundle is not in the STARTING, ACTIVE, or STOPPING states or this bundle is a fragment bundle.

      In my case, bundle org.apache.logging.log4j.coreconf is a fragment bundle. So How to handle fragment in this case and let NullPointerException not ccur. Thanks.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              liwenxian2017 liwenxian2017
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: