This is an automated email from the ASF dual-hosted git repository.
stbischof 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 be6f5eacc9 FELIX-6820 Log exceptions during
ConfigurationPrinter.printConfiguration(PrintWriter pw)
be6f5eacc9 is described below
commit be6f5eacc9e26c0846d3bd1f23a64f9497e6cdde
Author: Konrad Windszus <[email protected]>
AuthorDate: Mon Feb 2 17:07:54 2026 +0100
FELIX-6820 Log exceptions during
ConfigurationPrinter.printConfiguration(PrintWriter pw)
Use OSGi LogService by default.
As fallback print to System.err.
---
.../org/apache/felix/inventory/impl/Activator.java | 21 +++++++++---------
.../webconsole/ConfigurationPrinterAdapter.java | 25 ++++++++++++++++++++--
2 files changed, 33 insertions(+), 13 deletions(-)
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
index c3498485ee..3457e315f2 100644
--- a/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
+++ b/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
@@ -29,9 +29,9 @@ import org.osgi.util.tracker.ServiceTracker;
public class Activator implements BundleActivator
{
- private static Object logService;
+ private static LogService logService;
- private ServiceTracker logServiceTracker;
+ private ServiceTracker<LogService, LogService> logServiceTracker;
private InventoryPrinterManagerImpl printerManager;
@@ -42,17 +42,17 @@ public class Activator implements BundleActivator
*/
public void start(final BundleContext context) throws Exception
{
- this.logServiceTracker = new ServiceTracker(context,
"org.osgi.service.log.LogService", null)
+ this.logServiceTracker = new ServiceTracker<LogService,
LogService>(context, LogService.class, null)
{
@Override
- public Object addingService(ServiceReference reference)
+ public LogService addingService(ServiceReference<LogService>
reference)
{
Activator.logService = super.addingService(reference);
return Activator.logService;
}
@Override
- public void removedService(ServiceReference reference, Object
service)
+ public void removedService(ServiceReference<LogService> reference,
LogService service)
{
Activator.logService = null;
super.removedService(reference, service);
@@ -87,12 +87,11 @@ public class Activator implements BundleActivator
}
}
- public static void log(final ServiceReference sr, final int level, final
String message, final Throwable exception)
+ public static void log(final int level, final String message, final
Throwable exception)
{
- Object logService = Activator.logService;
- if (logService != null)
+ if (Activator.logService != null)
{
- ((LogService) logService).log(sr, level, message, exception);
+ Activator.logService.log(level, message, exception);
}
else
{
@@ -116,10 +115,10 @@ public class Activator implements BundleActivator
code = "*DEBUG*";
}
- System.out.println(code + " " + message);
+ System.err.println(code + " " + message);
if (exception != null)
{
- exception.printStackTrace(System.out);
+ exception.printStackTrace(System.err);
}
}
}
diff --git
a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
index ae177d72d7..f366b3de88 100644
---
a/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
+++
b/inventory/src/main/java/org/apache/felix/inventory/impl/webconsole/ConfigurationPrinterAdapter.java
@@ -17,6 +17,7 @@
package org.apache.felix.inventory.impl.webconsole;
import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
@@ -26,7 +27,9 @@ import java.util.List;
import java.util.Set;
import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.impl.Activator;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
/**
* Helper class for a configuration printer.
@@ -312,9 +315,27 @@ public class ConfigurationPrinterAdapter
{
return m.invoke(obj, args);
}
- catch (final Throwable e)
+ catch (InvocationTargetException ite)
{
- // ignore
+ Activator.log(
+ LogService.LOG_ERROR,
+ String.format(
+ "Error invoking method '%s' on %s: %s",
+ m.getName(),
+ obj.getClass(),
+ ite.getTargetException().getMessage()),
+ ite.getTargetException());
+ }
+ catch (IllegalAccessException iae)
+ {
+ Activator.log(
+ LogService.LOG_ERROR,
+ String.format(
+ "Illegal access while invoking method '%s' on %s: %s",
+ m.getName(),
+ obj.getClass(),
+ iae.getMessage()),
+ iae);
}
return null;
}