-
-
Notifications
You must be signed in to change notification settings - Fork 300
more lenient osgi.ee=JavaSE for unknown JDKs #6859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,16 +6,20 @@ | |||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||
| import static org.junit.jupiter.api.Assertions.fail; | ||||||
|
|
||||||
| import java.io.ByteArrayInputStream; | ||||||
| import java.io.File; | ||||||
| import java.io.FileInputStream; | ||||||
| import java.io.Serializable; | ||||||
| import java.lang.annotation.ElementType; | ||||||
| import java.lang.annotation.Target; | ||||||
| import java.nio.file.Files; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.EnumSet; | ||||||
| import java.util.List; | ||||||
| import java.util.Set; | ||||||
| import java.util.concurrent.atomic.AtomicReference; | ||||||
| import java.util.jar.Attributes; | ||||||
| import java.util.jar.Manifest; | ||||||
|
|
||||||
| import org.junit.jupiter.api.Test; | ||||||
| import org.junit.jupiter.api.condition.EnabledForJreRange; | ||||||
|
|
@@ -30,16 +34,21 @@ | |||||
| import aQute.bnd.osgi.ClassDataCollector; | ||||||
| import aQute.bnd.osgi.Clazz; | ||||||
| import aQute.bnd.osgi.Clazz.FieldDef; | ||||||
| import aQute.bnd.osgi.Clazz.JAVA; | ||||||
| import aQute.bnd.osgi.Clazz.MethodDef; | ||||||
| import aQute.bnd.osgi.Clazz.QUERY; | ||||||
| import aQute.bnd.osgi.Constants; | ||||||
| import aQute.bnd.osgi.Descriptors; | ||||||
| import aQute.bnd.osgi.Descriptors.PackageRef; | ||||||
| import aQute.bnd.osgi.EmbeddedResource; | ||||||
| import aQute.bnd.osgi.FileResource; | ||||||
| import aQute.bnd.osgi.Instruction; | ||||||
| import aQute.bnd.osgi.Jar; | ||||||
| import aQute.bnd.osgi.Macro; | ||||||
| import aQute.bnd.osgi.Resource; | ||||||
| import aQute.bnd.xmlattribute.XMLAttributeFinder; | ||||||
| import aQute.lib.io.IO; | ||||||
| import aQute.lib.manifest.ManifestUtil; | ||||||
|
|
||||||
| public class ClazzTest { | ||||||
|
|
||||||
|
|
@@ -1111,4 +1120,77 @@ public void kotlin_LambdaClass() throws Exception { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * This test creates a fake java .class file with an imaginary large major | ||||||
| * version (10000) to test how our Analyzer handles class files of a yet | ||||||
| * unknown future JDK. | ||||||
| */ | ||||||
| @Test | ||||||
| void testUnknownJDKClass() throws Exception { | ||||||
|
|
||||||
|
|
||||||
| File file = IO.getFile("bin_test/test/ClazzTest$Inner.class"); | ||||||
| byte[] fakeClassBytes = Files.readAllBytes(file.toPath()); | ||||||
|
|
||||||
| int newMajor = 10_000; | ||||||
| int expected = 9955; // newMajor - 45; | ||||||
| // Patch major version (u2 big-endian) | ||||||
| // https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html | ||||||
| fakeClassBytes[6] = (byte) ((newMajor >> 8) & 0xFF); | ||||||
| fakeClassBytes[7] = (byte) (newMajor & 0xFF); | ||||||
|
|
||||||
| try (Jar jar = new Jar("future"); | ||||||
| Analyzer a = new Analyzer(jar)) { | ||||||
|
|
||||||
| Resource r = new EmbeddedResource(fakeClassBytes, fakeClassBytes.length); | ||||||
|
|
||||||
| Clazz c = new Clazz(a, "", r); | ||||||
| c.parseClassFile(new ByteArrayInputStream(fakeClassBytes), new ClassDataCollector() {}); | ||||||
| a.getClassspace() | ||||||
| .put(c.getClassName(), c); | ||||||
|
|
||||||
| assertThat(c.getMajorVersion()).isEqualTo(newMajor); | ||||||
|
|
||||||
| Manifest calcManifest = a.calcManifest(); | ||||||
| ManifestUtil.write(calcManifest, System.out); | ||||||
| Attributes mainAttributes = calcManifest.getMainAttributes(); | ||||||
| assertThat(mainAttributes.getValue(Constants.REQUIRE_CAPABILITY)) | ||||||
| .contains("(&(osgi.ee=JavaSE)(version=" + expected + "))"); | ||||||
| assertThat(a.getEEs()).containsExactly(JAVA.UNKNOWN); | ||||||
|
|
||||||
|
|
||||||
|
Comment on lines
+1161
to
+1162
|
||||||
| } | ||||||
| catch (Exception e) { | ||||||
| e.printStackTrace(); | ||||||
| throw e; | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void testBuildEEFilter_lenientKnown() { | ||||||
| // lenient = true but version within known range | ||||||
| String result = Clazz.JAVA.buildEEFilterLenient(55); // within range | ||||||
| assertEquals("(&(osgi.ee=JavaSE)(version=11))", result); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
||||||
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
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.
| assertEquals("(&(osgi.ee=JavaSE)(version=UNKNOWN))", result); | |
| assertEquals("(osgi.ee=UNKNOWN)", result); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -118,6 +118,7 @@ public class Analyzer extends Processor { | |||||
| private final static Logger logger = LoggerFactory.getLogger(Analyzer.class); | ||||||
| private final static Version frameworkR7 = new Version("1.9"); | ||||||
| private final SortedSet<Clazz.JAVA> ees = new TreeSet<>(); | ||||||
| private int highestMajorJavaVersion = 0; | ||||||
|
||||||
| private int highestMajorJavaVersion = 0; | |
| private int highestMajorJavaVersion = 0; |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after if keyword. The codebase convention is to use if ( with a space before the opening parenthesis.
| if(majorVersion > highestMajorJavaVersion) { | |
| if (majorVersion > highestMajorJavaVersion) { |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary blank line inside the forEach block. This should be removed to maintain consistency with the coding style in the rest of the file.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -198,7 +198,7 @@ public Map<String, Set<String>> getProfiles() throws IOException { | |||||
| this.major = ordinal() + 45; | ||||||
| String version = Integer.toString(ordinal() + 1); | ||||||
| this.ee = "JavaSE-" + version; | ||||||
| this.filter = "(&(osgi.ee=JavaSE)(version=" + version + "))"; | ||||||
| this.filter = eeFilter(version); | ||||||
| } | ||||||
|
|
||||||
| JAVA(String ee, String filter) { | ||||||
|
|
@@ -248,6 +248,28 @@ public String getEE() { | |||||
| return ee; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Returns an eeFilter String also supporting yet unknown JDKs (lenient) | ||||||
| */ | ||||||
| public static String buildEEFilterLenient(int major) { | ||||||
|
|
||||||
| // lenient: We try to return a useful filter | ||||||
| // even for yet unknown JDKs | ||||||
| int version = major - 45; | ||||||
| if ((version < 0)) { | ||||||
|
||||||
| if ((version < 0)) { | |
| if (version < 0) { |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
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.
| return eeFilter("UNKNOWN"); | |
| return "(osgi.ee=UNKNOWN)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary blank lines. Remove the extra blank line to maintain consistent formatting with the rest of the test file.