You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2021/03/15 08:10:51 UTC

[felix-dev] branch master updated: FELIX-6388 : ERROR: Bundle org.apache.felix.log [4] EventDispatcher: Error during dispatch. (java.lang.NullPointerException)

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 9417fc7  FELIX-6388 : ERROR: Bundle org.apache.felix.log [4] EventDispatcher: Error during dispatch. (java.lang.NullPointerException)
9417fc7 is described below

commit 9417fc701c6a3a9b79900c0dbd3c468cd63daee5
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Mar 15 09:10:28 2021 +0100

    FELIX-6388 : ERROR: Bundle org.apache.felix.log [4] EventDispatcher: Error during dispatch. (java.lang.NullPointerException)
---
 .../felix/log/ConfigurationListenerImpl.java       | 14 +++++++---
 log/src/main/java/org/apache/felix/log/Log.java    | 32 ++++++++++++++--------
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/log/src/main/java/org/apache/felix/log/ConfigurationListenerImpl.java b/log/src/main/java/org/apache/felix/log/ConfigurationListenerImpl.java
index a90eb7c..2f7dc86 100644
--- a/log/src/main/java/org/apache/felix/log/ConfigurationListenerImpl.java
+++ b/log/src/main/java/org/apache/felix/log/ConfigurationListenerImpl.java
@@ -27,6 +27,7 @@ import java.util.Collections;
 import java.util.Dictionary;
 import java.util.List;
 
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
@@ -86,12 +87,17 @@ public class ConfigurationListenerImpl {
             m_caReference = caReference;
             m_ca = m_context.getService(m_caReference);
 
+            final Bundle bundle = m_caReference.getBundle();
+            if ( bundle == null )
+            {
+                throw new IllegalStateException("Service already unregistered again");
+            }
             try {
-                m_caClass = m_caReference.getBundle().loadClass(CONFIGURATION_ADMIN_CLASS);
+                m_caClass = bundle.loadClass(CONFIGURATION_ADMIN_CLASS);
                 m_caGetConfiguration = m_caClass.getMethod("getConfiguration", String.class, String.class);
                 m_caListConfigurations = m_caClass.getMethod("listConfigurations", String.class);
 
-                m_configurationClass = m_caReference.getBundle().loadClass(CONFIGURATION_CLASS);
+                m_configurationClass = bundle.loadClass(CONFIGURATION_CLASS);
                 m_configurationGetProperties = m_configurationClass.getMethod("getProperties");
                 Method configurationGetProcessedProperties = null;
                 try {
@@ -103,11 +109,11 @@ public class ConfigurationListenerImpl {
                 }
                 m_configurationGetProcessedProperties = configurationGetProcessedProperties;
 
-                m_ceClass = m_caReference.getBundle().loadClass(CONFIGURATION_EVENT_CLASS);
+                m_ceClass = bundle.loadClass(CONFIGURATION_EVENT_CLASS);
                 m_ceGetPid = m_ceClass.getMethod("getPid");
                 m_ceGetType = m_ceClass.getMethod("getType");
 
-                m_clClass = m_caReference.getBundle().loadClass(CONFIGURATION_LISTENER_CLASS);
+                m_clClass = bundle.loadClass(CONFIGURATION_LISTENER_CLASS);
                 m_clConfigurationEvent = m_clClass.getMethod("configurationEvent", m_ceClass);
             }
             catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
diff --git a/log/src/main/java/org/apache/felix/log/Log.java b/log/src/main/java/org/apache/felix/log/Log.java
index 73c1040..1172372 100644
--- a/log/src/main/java/org/apache/felix/log/Log.java
+++ b/log/src/main/java/org/apache/felix/log/Log.java
@@ -42,17 +42,19 @@ import org.osgi.service.log.LogListener;
 final class Log implements BundleListener, FrameworkListener, ServiceListener
 {
     /** The first log entry. */
-    private LogNode m_head;
+    private volatile LogNode m_head;
     /** The last log entry. */
-    private LogNode m_tail;
+    private volatile LogNode m_tail;
     /** The log size. */
-    private int m_size;
+    private volatile int m_size;
     /** The log listener thread. */
-    private LogListenerThread listenerThread;
+    private volatile LogListenerThread listenerThread;
     /** The maximum size for the log. */
     private final int m_maxSize;
     /** Whether or not to store debug messages. */
     private final boolean m_storeDebug;
+    /** Active flag */
+    private volatile boolean active = true;
 
     /**
      * Create a new instance.
@@ -68,8 +70,9 @@ final class Log implements BundleListener, FrameworkListener, ServiceListener
     /**
      * Close the log.
      */
-    void close()
+    synchronized void close()
     {
+        active = false;
         if (listenerThread != null)
         {
             listenerThread.shutdown();
@@ -98,6 +101,10 @@ final class Log implements BundleListener, FrameworkListener, ServiceListener
      */
     synchronized void addEntry(final LogEntry entry)
     {
+        if ( !active )
+        {
+            return;
+        }
         if (m_maxSize != 0)
         {
             // add the entry to the historic log
@@ -152,14 +159,17 @@ final class Log implements BundleListener, FrameworkListener, ServiceListener
      */
     synchronized void addListener(final LogListener listener)
     {
-        if (listenerThread == null)
+        if ( active )
         {
-            // create a new listener thread if necessary:
-            // the listener thread only runs if there are any registered listeners
-            listenerThread = new LogListenerThread();
-            listenerThread.start();
+            if (listenerThread == null)
+            {
+                // create a new listener thread if necessary:
+                // the listener thread only runs if there are any registered listeners
+                listenerThread = new LogListenerThread();
+                listenerThread.start();
+            }
+            listenerThread.addListener(listener);
         }
-        listenerThread.addListener(listener);
     }
 
     /**