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/08/14 13:53:02 UTC
[felix-dev] branch master updated: FELIX-6217 :
RootCauseCommand#rootcause causes a NoSuchElementException for OSGI
comonents that do not exist
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 50b85f1 FELIX-6217 : RootCauseCommand#rootcause causes a NoSuchElementException for OSGI comonents that do not exist
50b85f1 is described below
commit 50b85f107f2cddfa0f44b505df95c8fe55334499
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sat Aug 14 15:52:55 2021 +0200
FELIX-6217 : RootCauseCommand#rootcause causes a NoSuchElementException for OSGI comonents that do not exist
---
.../apache/felix/rootcause/RootCauseCommand.java | 11 ++++---
.../apache/felix/rootcause/RootCausePrinter.java | 36 +++++++++++++++++-----
2 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/rootcause/src/main/java/org/apache/felix/rootcause/RootCauseCommand.java b/rootcause/src/main/java/org/apache/felix/rootcause/RootCauseCommand.java
index 3a01aa9..345e3dd 100644
--- a/rootcause/src/main/java/org/apache/felix/rootcause/RootCauseCommand.java
+++ b/rootcause/src/main/java/org/apache/felix/rootcause/RootCauseCommand.java
@@ -31,16 +31,19 @@ import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
}
)
public class RootCauseCommand {
-
+
@Reference
ServiceComponentRuntime scr;
-
+
public DSComp rootcause(String componentName) {
ComponentDescriptionDTO cdesc = scr.getComponentDescriptionDTOs().stream()
.filter(desc -> desc.name.equals(componentName))
.findFirst().get();
- DSComp rootCause = new DSRootCause(scr).getRootCause(cdesc);
- new RootCausePrinter().print(rootCause);
+ DSComp rootCause = null;
+ if ( cdesc != null ) {
+ rootCause = new DSRootCause(scr).getRootCause(cdesc);
+ new RootCausePrinter().print(rootCause);
+ }
return rootCause;
}
}
diff --git a/rootcause/src/main/java/org/apache/felix/rootcause/RootCausePrinter.java b/rootcause/src/main/java/org/apache/felix/rootcause/RootCausePrinter.java
index 8434491..b476552 100644
--- a/rootcause/src/main/java/org/apache/felix/rootcause/RootCausePrinter.java
+++ b/rootcause/src/main/java/org/apache/felix/rootcause/RootCausePrinter.java
@@ -23,21 +23,41 @@ import java.util.function.Consumer;
import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+/**
+ * Root cause printer
+ *
+ */
public class RootCausePrinter {
private Consumer<String> printCallback;
-
+
+ /**
+ * Create new printer for system out
+ */
public RootCausePrinter() {
this(System.out::println);
}
-
+
+ /**
+ * Create new printer for callback
+ * @param printCallback The callback
+ */
public RootCausePrinter(Consumer<String> printCallback) {
this.printCallback = printCallback;
}
-
- public void print(DSComp desc) {
- print(desc, 0);
+
+ /**
+ * Print the root cause
+ * @param comp The component
+ */
+ public void print(DSComp comp) {
+ print(comp, 0);
}
-
+
+ /**
+ * Print the root cause
+ * @param comp The component
+ * @param level Indent
+ */
public void print(DSComp comp, int level) {
if (comp.config == null && "require".equals(comp.desc.configurationPolicy)) {
println(level, "Component %s missing config on pid %s", comp.desc.name, Arrays.asList(comp.desc.configurationPid));
@@ -57,7 +77,7 @@ public class RootCausePrinter {
}
}
}
-
+
private Object getFilterSt(String filter) {
return filter == null ? "" : ", filter " + filter;
}
@@ -65,7 +85,7 @@ public class RootCausePrinter {
private void println(int level, String format, Object... args) {
printCallback.accept(spaces(level) + String.format(format, args));
}
-
+
private String spaces(int length) {
char[] bytes = new char[length];
Arrays.fill(bytes, ' ');