This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/main by this push:
new 7740f7ec6e Filter out empty repository entries in feature descriptors
(#2515)
7740f7ec6e is described below
commit 7740f7ec6e728f61c4f65c431e8530364946b89c
Author: JB Onofré <[email protected]>
AuthorDate: Sun Apr 5 18:20:18 2026 +0200
Filter out empty repository entries in feature descriptors (#2515)
Empty or whitespace-only <repository> elements in feature XML
descriptors cause a RuntimeException from pax-url-mvn
(NullArgumentException: Repository spec is empty string) during
boot feature installation.
Both Features.trim() and RepositoryImpl.getRepositories()/
getResourceRepositories() now discard blank entries instead of
passing them through to URI creation.
---
.../karaf/features/internal/model/Features.java | 7 +++++-
.../features/internal/service/RepositoryImpl.java | 2 ++
.../org/apache/karaf/features/RepositoryTest.java | 15 +++++++++++++
.../resources/org/apache/karaf/features/repo5.xml | 26 ++++++++++++++++++++++
4 files changed, 49 insertions(+), 1 deletion(-)
diff --git
a/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
b/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
index 0c37b5b75d..86a3456c4c 100644
---
a/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
+++
b/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
@@ -188,7 +188,12 @@ public class Features implements Blacklisting {
private static void trim(List<String> list) {
if (list != null) {
for (ListIterator<String> it = list.listIterator(); it.hasNext();)
{
- it.set(it.next().trim());
+ String trimmed = it.next().trim();
+ if (trimmed.isEmpty()) {
+ it.remove();
+ } else {
+ it.set(trimmed);
+ }
}
}
}
diff --git
a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
index c8de71d90e..4c1ce07e8d 100644
---
a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
+++
b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
@@ -77,6 +77,7 @@ public class RepositoryImpl implements Repository {
public URI[] getRepositories() {
return features.getRepository().stream()
.map(String::trim)
+ .filter(s -> !s.isEmpty())
.map(URI::create)
.toArray(URI[]::new);
}
@@ -85,6 +86,7 @@ public class RepositoryImpl implements Repository {
public URI[] getResourceRepositories() {
return features.getResourceRepository().stream()
.map(String::trim)
+ .filter(s -> !s.isEmpty())
.map(URI::create)
.toArray(URI[]::new);
}
diff --git
a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
index a6c7edef00..0ddee486ce 100644
--- a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
@@ -175,6 +175,21 @@ public class RepositoryTest extends TestCase {
assertEquals(1, res.getRequirements("req").size());
}
+ public void testLoadRepoWithEmptyRepositoryEntries() throws Exception {
+ RepositoryImpl r = new
RepositoryImpl(getClass().getResource("repo5.xml").toURI());
+ // Empty and whitespace-only repository entries should be filtered out
+ URI[] repos = r.getRepositories();
+ assertNotNull(repos);
+ assertEquals(2, repos.length);
+ assertEquals(URI.create("urn:r1"), repos[0]);
+ assertEquals(URI.create("urn:r2"), repos[1]);
+ // Check features still load correctly
+ Feature[] features = r.getFeatures();
+ assertNotNull(features);
+ assertEquals(1, features.length);
+ assertEquals("f1", features[0].getName());
+ }
+
public void testShowWrongUriInException() throws Exception {
String uri =
"src/test/resources/org/apache/karaf/shell/features/repo1.xml";
try {
diff --git
a/features/core/src/test/resources/org/apache/karaf/features/repo5.xml
b/features/core/src/test/resources/org/apache/karaf/features/repo5.xml
new file mode 100644
index 0000000000..b6848bdecb
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/repo5.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<features name="test" xmlns="http://karaf.apache.org/xmlns/features/v1.1.0">
+ <repository>urn:r1</repository>
+ <repository></repository>
+ <repository> </repository>
+ <repository>urn:r2</repository>
+ <feature name="f1">
+ <bundle>b1</bundle>
+ </feature>
+</features>