Fix ClassCastException in logging bridge stop 05/4605/1
authorPrasanth Pallamreddy <ppallamr@cisco.com>
Wed, 22 Jan 2014 18:45:40 +0000 (10:45 -0800)
committerPrasanth Pallamreddy <ppallamr@cisco.com>
Wed, 22 Jan 2014 19:33:00 +0000 (11:33 -0800)
  - Additional fix to handle NPE during logging bridge start

Change-Id: Id6d4b727dd08db18a91b509cad99450fd41a5171
Signed-off-by: Prasanth Pallamreddy <ppallamr@cisco.com>
opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java

index b231faf..75990c7 100644 (file)
@@ -50,14 +50,15 @@ public class Activator implements BundleActivator {
                 if (reader == null) {
                     this.log.error("Cannot register the LogListener because "
                             + "cannot retrieve LogReaderService");
-                }
-                reader.addLogListener(this.listener);
-                // Now lets walk all the exiting messages
-                Enumeration<LogEntry> entries = reader.getLog();
-                if (entries != null) {
-                    while (entries.hasMoreElements()) {
-                        LogEntry entry = (LogEntry) entries.nextElement();
-                        this.listener.logged(entry);
+                } else {
+                    reader.addLogListener(this.listener);
+                    // Now lets walk all the exiting messages
+                    Enumeration<LogEntry> entries = reader.getLog();
+                    if (entries != null) {
+                        while (entries.hasMoreElements()) {
+                            LogEntry entry = entries.nextElement();
+                            this.listener.logged(entry);
+                        }
                     }
                 }
 
@@ -98,10 +99,10 @@ public class Activator implements BundleActivator {
 
     @Override
     public void stop(BundleContext context) {
-        ServiceReference service = null;
-        service = context.getServiceReference(LogReaderService.class.getName());
-        if (service != null) {
-            LogReaderService reader = (LogReaderService) service;
+        ServiceReference serviceRef = context.getServiceReference(
+                LogReaderService.class.getName());
+        if (serviceRef != null) {
+            LogReaderService reader = (LogReaderService) context.getService(serviceRef);
             reader.removeLogListener(this.listener);
         }
         if (this.shutdownHandler != null) {