You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by "ponziani (via GitHub)" <gi...@apache.org> on 2026/10/06 11:37:38 UTC

[PR] Fix state of features with a leading zero in a version segment [karaf]

ponziani opened a new pull request, #2978:
URL: https://github.com/apache/karaf/pull/2978

   Fixes [KARAF-5784](https://issues.apache.org/jira/browse/KARAF-5784) and [KARAF-7163](https://issues.apache.org/jira/browse/KARAF-7163).
   
   ## Problem
   
   A feature whose version has a leading zero in a numeric segment (e.g. `1.0.01` or `1.01.1-SNAPSHOT`) gets installed: its bundles are deployed and running. Karaf still reports the feature as not installed / `Uninstalled`, without any error in the log:
   
   - KARAF-7163: a boot feature with such a version never reaches state `Started`.
   - KARAF-5784: a feature deployed through a KAR does not show up as installed and started.
   
   ## Cause
   
   Feature ids are built in two different ways:
   
   - `Feature.getId()` (and `FeaturesServiceImpl.normalize()`) keep the version string as written: `f/1.0.01`.
   - The deployment state (`State.installedFeatures` / `stateFeatures`) is keyed by `ResourceUtils.getFeatureId(Resource)`. That method uses the OSGi `Version` of the feature resource, which is normalized: `f/1.0.1`.
   
   The two ids never match, so:
   
   - `isInstalled()` / `getState()` don't find the feature;
   - `feature:start` / `feature:stop` (`updateFeaturesState`) are silently ignored;
   - the `Deployer` doesn't install (or delete) the feature's configurations and libraries.
   
   Resolution itself is not affected, because requirements use version ranges.
   
   ## Fix
   
   Feature ids are now normalized the OSGi way everywhere they are compared with the deployment state:
   
   - `ResourceUtils.getFeatureId(String, String)` and `normalizeFeatureId(String)` produce the same form as `getFeatureId(Resource)`.
   - `FeaturesServiceImpl.normalize()` uses that form, which fixes `isInstalled()` and `getState()`.
   - `Deployer` uses it for `featuresById`, for requested state changes, and when installing configurations and libraries.
   
   The persisted state already used the normalized form, so existing installations need no migration.
   
   ## Tests
   
   - New test `FeaturesServiceImplTest#testInstallAndStopFeatureWithLeadingZeroInVersion` installs a `1.0.01` feature. It checks that the feature is installed and `Started`, then stops it through its own id. Without the fix the test fails with `Feature f/1.0.01 not installed.`
   - `mvn -pl features/core install`: 141 tests, 0 failures.
   
   πŸ€– Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix state of features with a leading zero in a version segment [karaf]

Posted by "ponziani (via GitHub) via commits" <co...@karaf.apache.org>.
ponziani commented on PR #2978:
URL: https://github.com/apache/karaf/pull/2978#issuecomment-6851235823

   Addressed in 097b0a10b0 and bc2218427f. Two related things I left alone because this PR doesn't touch them: `getFeature("bad", "1.0.0.beta+1")` still throws in `FeatureReq.exactVersion`, and `Subsystem` still parses the version of every same-name feature, so an invalid `f/…beta+1` next to `f/1.0.0` would break installing `f`. Happy to open follow-up issues for those.
   
   Unrelated: could you approve the pending CI run on #2979? It's waiting for maintainer approval after the rebase on `main`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix state of features with a leading zero in a version segment [karaf]

Posted by "jbonofre (via GitHub) via commits" <co...@karaf.apache.org>.
jbonofre commented on code in PR #2978:
URL: https://github.com/apache/karaf/pull/2978#discussion_r4561711557


##########
features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java:
##########
@@ -91,6 +91,23 @@ public static String getFeatureId(Resource resource) {
         return null;
     }
 
+    /**
+     * Returns the feature ID in the same form as {@link #getFeatureId(Resource)}, which is the form used as key
+     * in the deployment state. The version is normalized the OSGi way, so <code>1.0.01</code> becomes
+     * <code>1.0.1</code>.
+     */
+    public static String getFeatureId(String name, String version) {
+        return version != null ? name + "/" + VersionTable.getVersion(version) : name;

Review Comment:
   `VersionTable.getVersion` throws `IllegalStateException` when the cleaned version still is not a valid OSGi version. A few inputs that survive `VersionCleaner.clean` and then fail:
   
   | version | cleaned | result |
   |---------|---------|-------|
   | `1.0.0.beta+1` | `1.0.0.beta+1` | `invalid qualifier "beta+1" ` |
   | `1.0.0.rc 1` | `1.0.0.rc 1` | `invalid qualifier "rc 1"` |
   | `20231112093000` | `20231112093000.0.0` | `non-numeric "20231112093000"` |
   
   Before this PR, these ids were only cleaned, never parsed, so the method couldn't throw. Since it's now called for every available feature (see the comments on `normalize()` and `partitionFeatures`), it needs to fall back instead of failing. Such a feature can't be in the deployment state anyway (`FeatureResource` would fail to parse it too), so keeping the raw version as the key is safe:
   
   
   ```suggestion
           if (version == null) {
               return name;
           }
           try {
               return name + "/" + VersionTable.getVersion(version);
           } catch (IllegalArgumentException e) {
               // not a valid OSGi version even after cleaning, keep it as is
               return name + "/" + version;
           }
   ```
   
   Could we also add a regression test? A repository with an unused feature that has an invalid version, next to the one being installed:
   
   ```xml
   <feature name="f" version="1.0.0">
       <bundle>a100</bundle>
   </feature>
   <feature name="bad" version="1.0.0.beta+1">
       <bundle>a100</bundle>
   </feature>
   ```
   
   Installing `f/1.0.0`, `listInstalledFeatures()`, stopping and uninstalling `f` should all still work.



##########
features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java:
##########
@@ -230,7 +230,8 @@ public void partitionFeatures(Collection<Feature> featuresList) {
             featuresById = new HashMap<>();
             for (Feature feature : featuresList) {
                 features.computeIfAbsent(feature.getName(), name -> new ArrayList<>()).add(feature);
-                featuresById.put(feature.getId(), feature);
+                // keyed like the deployment state, which uses normalized versions (1.0.01 -> 1.0.1)
+                featuresById.put(getFeatureId(feature.getName(), feature.getVersion()), feature);

Review Comment:
   Same issue on the deployment path. Before, only features whose name matched a requirement had their version parsed (in `Subsystem`/`FeatureReq`). This loop now parses the version of every available feature. If `f` was installed first and a repository with `bad/1.0.0.beta+1` is added later, every deployment fails, including stopping or uninstalling `f`:
   
   ```
   java.lang.IllegalArgumentException: invalid version "1.0.0.beta+1": invalid qualifier "beta+1"
       at o.a.k.features.internal.resolver.ResourceUtils.getFeatureId(ResourceUtils.java:100)
       at o.a.k.features.internal.service.Deployer$DeploymentState.partitionFeatures(Deployer.java:234)
       at o.a.k.features.internal.service.FeaturesServiceImpl.getDeploymentState(FeaturesServiceImpl.java:1038)
       at o.a.k.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1071)
   ```
   
   `partitionFeatures` is also used by `AssemblyDeployCallback` and `VerifyMojo`, so profile assembly and `karaf:verify` are affected too.
   
   The fallback in `ResourceUtils.getFeatureId` covers this as well.



##########
features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java:
##########
@@ -957,7 +958,8 @@ private String normalize(String feature) {
         }
         String name = feature.substring(0, idx);
         String version = feature.substring(idx + 1);
-        return name + VERSION_SEPARATOR + VersionCleaner.clean(version);
+        // same form as the ids in the deployment state, so 1.0.01 matches 1.0.1
+        return ResourceUtils.getFeatureId(name, VersionCleaner.clean(version));

Review Comment:
   This is where it breaks for users. `listInstalledFeatures()` calls `isInstalled()` -> `normalize()` on every cached feature, and `installFeatures()` calls `listInstalledFeatures()` via `computeFeaturesToAdd()`. With an unused `bad/1.0.0.beta+1` in any registered repository, installing an unrelated feature fails:
   
   ```
   java.lang.IllegalArgumentException: invalid version "1.0.0.beta+1": invalid qualifier "beta+1"
       at o.a.k.features.internal.resolver.ResourceUtils.getFeatureId(ResourceUtils.java:100)
       at o.a.k.features.internal.service.FeaturesServiceImpl.normalize(FeaturesServiceImpl.java:962)
       at o.a.k.features.internal.service.FeaturesServiceImpl.isInstalled(FeaturesServiceImpl.java:688)
       at o.a.k.features.internal.service.FeaturesServiceImpl.flattenFeatures(FeaturesServiceImpl.java:683)
       at o.a.k.features.internal.service.FeaturesServiceImpl.listInstalledFeatures(FeaturesServiceImpl.java:666)
       at o.a.k.features.internal.service.FeaturesServiceImpl.computeFeaturesToAdd(FeaturesServiceImpl.java:835)
       at o.a.k.features.internal.service.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:807)
   ```
   
   `feature:list`, the JMX MBean and `getState()` fail the same way. The fallback in `ResourceUtils.getFeatureId` fixes it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix state of features with a leading zero in a version segment [karaf]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #2978:
URL: https://github.com/apache/karaf/pull/2978#issuecomment-6017622385

   ## Test Results
   β€‡β€ˆ729 files  Β±0β€‚β€ƒβ€‡β€ˆ729 suites  Β±0   1h 14m 52s ⏱️ - 5m 23s
   1β€ˆ078 tests +1β€‚β€ƒβ€‡β€ˆ943 βœ… Β±0  134 πŸ’€ Β±0  0 ❌ Β±0  1 πŸ”₯ +1 
   3β€ˆ234 runsβ€Š +3  2β€ˆ831 βœ… +2  402 πŸ’€ Β±0  0 ❌ Β±0  1 πŸ”₯ +1 
   
   For more details on these errors, see [this check](https://github.com/apache/karaf/runs/112301969823).
   
   Results for commit 0e2b7b03. ± Comparison against base commit f7d9d4a7.
   
   [test-results]:data:application/gzip;base64,H4sIAFz7xGoC/02MSw6DMAwFr4Ky7iI4LnF6mSofkKLyqUKyQr17HSooyxk/zyaGOPareDQazK0Ra4n5gqEkm+Mys0A0wIavud5bqenA51q8Z2dQ/dUrvutM4akGG0dW8hR9SkuqIzapzDWrYH+odFSBVHuqXxUlHOYS3fna9Ms0xcwgZA9OO6k8dcF14EmrgB5ao8kGR3i3g3UUjPh8AazhxlIRAQAA
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix state of features with a leading zero in a version segment [karaf]

Posted by "ponziani (via GitHub) via commits" <co...@karaf.apache.org>.
ponziani commented on code in PR #2978:
URL: https://github.com/apache/karaf/pull/2978#discussion_r4562622648


##########
features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceUtils.java:
##########
@@ -91,6 +91,23 @@ public static String getFeatureId(Resource resource) {
         return null;
     }
 
+    /**
+     * Returns the feature ID in the same form as {@link #getFeatureId(Resource)}, which is the form used as key
+     * in the deployment state. The version is normalized the OSGi way, so <code>1.0.01</code> becomes
+     * <code>1.0.1</code>.
+     */
+    public static String getFeatureId(String name, String version) {
+        return version != null ? name + "/" + VersionTable.getVersion(version) : name;

Review Comment:
   Applied, thanks. Added `testFeatureWithInvalidVersionDoesNotBreakOtherFeatures`: `f/1.0.0` is installed first, then a repository with `bad/1.0.0.beta+1` is added. Listing, `getState`/`isInstalled` of `bad`, and stopping and uninstalling `f` all work. Without the fallback it fails at `listInstalledFeatures()` with `IllegalArgumentException: invalid version "1.0.0.beta+1"`.
   



##########
features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java:
##########
@@ -957,7 +958,8 @@ private String normalize(String feature) {
         }
         String name = feature.substring(0, idx);
         String version = feature.substring(idx + 1);
-        return name + VERSION_SEPARATOR + VersionCleaner.clean(version);
+        // same form as the ids in the deployment state, so 1.0.01 matches 1.0.1
+        return ResourceUtils.getFeatureId(name, VersionCleaner.clean(version));

Review Comment:
   Covered by the fallback. `normalize()` also no longer cleans the version itself, because `VersionTable.getVersion` already does that. So for an invalid version it falls back to the same raw string as `partitionFeatures`.
   



##########
features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java:
##########
@@ -230,7 +230,8 @@ public void partitionFeatures(Collection<Feature> featuresList) {
             featuresById = new HashMap<>();
             for (Feature feature : featuresList) {
                 features.computeIfAbsent(feature.getName(), name -> new ArrayList<>()).add(feature);
-                featuresById.put(feature.getId(), feature);
+                // keyed like the deployment state, which uses normalized versions (1.0.01 -> 1.0.1)
+                featuresById.put(getFeatureId(feature.getName(), feature.getVersion()), feature);

Review Comment:
   Covered by the same fallback, and the test follows this order: the repository with the invalid version is added after `f` was installed. While there, the config/library loop now uses the `featuresById` key instead of recomputing it.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org