Skip to content

more lenient osgi.ee=JavaSE for unknown JDKs#6859

Open
chrisrueger wants to merge 1 commit intobndtools:masterfrom
chrisrueger:6858-improve-osgiee-for-unknown-jdk
Open

more lenient osgi.ee=JavaSE for unknown JDKs#6859
chrisrueger wants to merge 1 commit intobndtools:masterfrom
chrisrueger:6858-improve-osgiee-for-unknown-jdk

Conversation

@chrisrueger
Copy link
Contributor

Closes #6858

Experimental:

For a yet to bnd unknown JDK (e.g. JDK-10000) Instead of

Require-Capability: osgi.ee;filter:="(osgi.ee=UNKNOWN)"

we now create

Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=9955))"

for a .class file with u2 major_version 10000 (9955 == 10000 - 45)

@chrisrueger chrisrueger changed the title more lenient osgi.ee for unknown JDKs more lenient osgi.ee=JavaSE for unknown JDKs Oct 6, 2025
@chrisrueger chrisrueger force-pushed the 6858-improve-osgiee-for-unknown-jdk branch 2 times, most recently from 3f533d5 to c63fede Compare October 10, 2025 19:12
@chrisrueger chrisrueger marked this pull request as ready for review October 18, 2025 14:44
@chrisrueger chrisrueger force-pushed the 6858-improve-osgiee-for-unknown-jdk branch from c63fede to 8d418ec Compare October 19, 2025 19:27
@laeubi
Copy link
Contributor

laeubi commented Oct 27, 2025

In the advent of regular Java versions released this seems the right approach. In general the EE enum might needs to be revised by:

  1. deprecate it
  2. replace all usages by a new JavaExecutionEnvironment class that can hold a java version and computes what ever is needed from that.

@laeubi
Copy link
Contributor

laeubi commented Oct 27, 2025

@chrisrueger I have fired up a task for the AI here maybe it produces something useful as a base-ground:

@chrisrueger
Copy link
Contributor Author

In general the EE enum might needs to be revised by

Just adding that currently there are two enums holding Java versions:

  • aQute.bnd.osgi.Clazz.JAVA
  • aQute.bnd.build.model.EE

@chrisrueger chrisrueger force-pushed the 6858-improve-osgiee-for-unknown-jdk branch from 8d418ec to 93558d3 Compare November 2, 2025 12:38
@peterkir
Copy link
Contributor

Selecting a ee from bndrun files is a little hard when there are so many list items available. Maybe we can downsize a little.

@chrisrueger
Copy link
Contributor Author

#6858 add enums up to JDK50 #6891

Feel free to downsize whatever I did in https://github.com/bndtools/bnd/pull/6891/files :)

@laeubi
Copy link
Contributor

laeubi commented Nov 27, 2025

Selecting a ee from bndrun files is a little hard when there are so many list items available. Maybe we can downsize a little.

mY recommendation would be to replace dropdowns by a spinner or something instead in the UI

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #6858 to make the osgi.ee requirement more lenient for unknown JDK versions. Instead of generating osgi.ee=UNKNOWN for class files compiled with future JDK versions, it now calculates and uses the Java version (major - 45) with osgi.ee=JavaSE.

Changes:

  • Modified the EE filter generation to compute JavaSE version numbers for unknown JDKs based on class file major version
  • Added tracking of the highest major version encountered during class analysis
  • Introduced new buildEEFilterLenient method to handle unknown JDK versions more gracefully
  • Added comprehensive test coverage for the lenient behavior including edge cases

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
biz.aQute.bndlib/src/aQute/bnd/osgi/Clazz.java Added buildEEFilterLenient static method to generate OSGi EE filters for unknown JDK versions, refactored existing filter construction to use new eeFilter helper method, and added getMajorVersion accessor
biz.aQute.bndlib/src/aQute/bnd/osgi/Analyzer.java Added tracking of highest major Java version during analysis and logic to use lenient filter generation when encountering UNKNOWN format
biz.aQute.bndlib.tests/test/test/ClazzTest.java Added comprehensive test coverage including a test with a fake class file with major version 10000, and unit tests for the lenient filter building logic covering known versions, too-low, and too-high edge cases
Comments suppressed due to low confidence (1)

biz.aQute.bndlib/src/aQute/bnd/osgi/Analyzer.java:3126

	public Map<TypeRef, Clazz> getClassspace() {

// even for yet unknown JDKs
int version = major - 45;
if ((version < 0)) {
return eeFilter("UNKNOWN");
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The filter string "(&(osgi.ee=JavaSE)(version=UNKNOWN))" is semantically incorrect for OSGi. In OSGi filter syntax, the version attribute expects a numeric value, not the string "UNKNOWN". For class files with invalid major versions (less than 45), consider either returning the original UNKNOWN filter "(osgi.ee=UNKNOWN)" or handling this as an error case, since such class files would be invalid according to the JVM specification.

Suggested change
return eeFilter("UNKNOWN");
return "(osgi.ee=UNKNOWN)";

Copilot uses AI. Check for mistakes.
void testBuildEEFilter_lenientTooLow() {
// version < 0 -> UNKNOWN
String result = Clazz.JAVA.buildEEFilterLenient(40);
assertEquals("(&(osgi.ee=JavaSE)(version=UNKNOWN))", result);
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

This test expects a filter with version=UNKNOWN, which is semantically incorrect for OSGi. The version attribute in OSGi filters expects a numeric value. The test should be updated to either expect the original UNKNOWN filter format "(osgi.ee=UNKNOWN)" or to test a different edge case, since a major version of 40 (predating Java 1.1 which starts at 45) represents an invalid class file.

Suggested change
assertEquals("(&(osgi.ee=JavaSE)(version=UNKNOWN))", result);
assertEquals("(osgi.ee=UNKNOWN)", result);

Copilot uses AI. Check for mistakes.
For a yet to bnd unknown JDK (e.g. JDK-10000) Instead of

```
Require-Capability: osgi.ee;filter:="(osgi.ee=UNKNOWN)"
```

we now create

Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=9955))"

for a  .class file with u2 major_version 10000 (9955 == 10000 - 45)

Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
@chrisrueger chrisrueger force-pushed the 6858-improve-osgiee-for-unknown-jdk branch from 03e02db to c6cbc7d Compare March 22, 2026 20:15
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.

Can the osgi.ee=JavaSE be more lenient on unknown JDK versions?

4 participants