DS: Add tests for inner-class constructor injection#7085
Merged
chrisrueger merged 1 commit intobndtools:masterfrom Feb 4, 2026
Merged
DS: Add tests for inner-class constructor injection#7085chrisrueger merged 1 commit intobndtools:masterfrom
chrisrueger merged 1 commit intobndtools:masterfrom
Conversation
Add two test component classes and corresponding tests to verify DS constructor-injection behavior for inner classes. New classes: ConstructorInjectionErrorOnNonStaticInnerClassComponent (non-static inner should fail) and ConstructorInjectionStaticInnerClassComponent (static inner should succeed). Update DSAnnotationTest.java to import Pattern, add tests that build jars, assert expected failure for non-static inner class, assert success for static inner class, and validate generated OSGI-INF XML. Also include a minor whitespace fix and additional XML assertions for the existing default no-arg constructor test. Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7078 and successor of #7082
Add two test component classes and corresponding tests to verify DS constructor-injection behavior for inner classes. New classes: ConstructorInjectionErrorOnNonStaticInnerClassComponent (non-static inner should fail) and ConstructorInjectionStaticInnerClassComponent (static inner should succeed). Update DSAnnotationTest.java to import Pattern, add tests that build jars, assert expected failure for non-static inner class, assert success for static inner class, and validate generated OSGI-INF XML. Also include a minor whitespace fix and additional XML assertions for the existing default no-arg constructor test.
Background
After using bnd 7.3.0-SNAPSHOT of #7082 a project of mine suddenly showed errors. It turns out we have put a
@Componenton a non-static inner class.At first I thought PR #7082 was wrong. But it turns out it is correct. Our code is wrong:
This is impossible for DS to instantiate , as it has no outer instance.
I guess we did not notice this until today, because the
@Componentis not really needed, and the only thing we need are the@HttpWhiteboardannotations. But since there was no error, we just didn't care. The app was working as expected.Now the error shows and we can react:
@Componentstatic