Skip to content

Fix state of features with a leading zero in a version segment - #2978

Merged
jbonofre merged 3 commits into
apache:mainfrom
ponziani:fix-feature-version-leading-zero
Nov 20, 2026
Merged

jbonofre merged 3 commits into
apache:mainfrom
ponziani:fix-feature-version-leading-zero

Conversation

@ponziani

@ponziani ponziani commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Fixes KARAF-5784 and 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

A feature version such as 1.0.01 was used as-is in Feature.getId(), while
the deployment state keys features by the id of their resolver resource,
where the version is an OSGi Version and is therefore normalized to 1.0.1.
Because the two ids never matched, such a feature was reported as not
installed (UNINSTALLED) even though its bundles were running, feature
state changes were ignored, and its configurations and libraries were not
installed.

Normalize feature ids the OSGi way everywhere they are compared with the
deployment state: in FeaturesServiceImpl (isInstalled/getState) and in the
Deployer (features by id, requested state changes, configuration and
library installation). The persisted state already used the normalized
form, so existing installations need no migration.

Fixes KARAF-5784 and KARAF-7163.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Normalizing feature IDs in Deployer.partitionFeatures, the updateFeaturesState key handling, and FeaturesServiceImpl.normalize makes versions like 1.0.01 match the 1.0.1 form used in the deployment state.

One minor note: updateFeaturesState keys now go through ResourceUtils.normalizeFeatureId, so a key with an unparseable version would throw IllegalArgumentException where it was previously skipped silently. I don't see a realistic caller that does this, so I'm fine with it.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Test Results

  744 files  +15    744 suites  +15   58m 50s ⏱️ - 21m 25s
1 110 tests +33    976 ✅ +33  134 💤 ±0  0 ❌ ±0 
3 330 runs  +99  2 927 ✅ +98  403 💤 +1  0 ❌ ±0 

Results for commit bc22184. ± Comparison against base commit f7d9d4a.

♻️ This comment has been updated with latest results.

* <code>1.0.1</code>.
*/
public static String getFeatureId(String name, String version) {
return version != null ? name + "/" + VersionTable.getVersion(version) : name;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
return version != null ? name + "/" + VersionTable.getVersion(version) : name;
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:

<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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ponziani and others added 2 commits November 13, 2026 11:56
ResourceUtils.getFeatureId(name, version) now falls back to the raw
version when VersionTable cannot parse it, even after cleaning. Without
the fallback, a single feature such as bad/1.0.0.beta+1 in any
registered repository made listing, installing, stopping and
uninstalling unrelated features fail with an IllegalArgumentException.
Such a feature can never be in the deployment state, because
FeatureResource cannot parse its version either.

The regression test installs f first and then adds the repository with
the invalid version, as in the review. The leading-zero test now uses
the same bundle mock helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- FeaturesServiceImpl.normalize no longer cleans the version itself:
  ResourceUtils.getFeatureId already does, and the invalid-version
  fallback now keeps the same raw version as Deployer.partitionFeatures.
- Deployer uses the featuresById key instead of recomputing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ponziani

Copy link
Copy Markdown
Contributor Author

Addressed in 097b0a1 and bc22184. 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.

@jbonofre
jbonofre self-requested a review November 20, 2026 06:36

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @ponziani!

The fallback in ResourceUtils.getFeatureId for invalid OSGi versions, the cleanup in FeaturesServiceImpl.normalize and Deployer, and the regression test in FeaturesServiceImplTest look good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants