gnodet-bot commented on code in PR #1144:
URL:
https://github.com/apache/maven-compiler-plugin/pull/1144#discussion_r4134408441
##########
pom.xml:
##########
@@ -192,6 +192,34 @@ under the License.
</plugin>
</plugins>
</pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <!--
+ Compile sources that require java.lang.classfile (JDK 24+)
separately
+ with release=24, so the main sources stay at the baseline Java
version.
+ The compiled classes land alongside the main classes in the
output directory.
+ BytecodeAnalyzer loads ClassfileClassAnalyzer reflectively at
runtime when
+ the running JVM is JDK 24 or later; AsmClassAnalyzer is used
otherwise.
+ -->
+ <id>compile-java24</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <phase>compile</phase>
+ <configuration>
+ <compileSourceRoots>
+
<compileSourceRoot>${project.basedir}/src/main/java24</compileSourceRoot>
+ </compileSourceRoots>
+ <release>24</release>
Review Comment:
🔴 **Critical — Build broken on JDK < 24.** The `compile-java24` execution is
in the main `<build><plugins>` section, not inside a profile. On JDK 17 or 21,
`javac` does not support `--release 24` (it only accepts release values up to
the running JDK version), so this execution will fail with:
```
error: release version 24 not supported
```
This breaks CI (the shared `maven-verify.yml` workflow tests on JDK 17, 21,
24, 25) and contributor builds on any JDK below 24.
Fix: wrap the execution in a JDK 24+ activation profile:
```suggestion
<release>24</release>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>java24+</id>
<activation>
<jdk>[24,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile-java24</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java24</compileSourceRoot>
</compileSourceRoots>
<release>24</release>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
```
Note: This means `ClassfileClassAnalyzer.class` won't be in the JAR when
built on JDK < 24, but that's fine — the reflective loading in
`selectAnalyzer()` handles this gracefully (catches `Exception | LinkageError`
and falls back to ASM). The class will be included in the release JAR when
built on JDK 24+.
##########
src/test/java/org/apache/maven/plugin/compiler/incremental/BytecodeAnalyzerTest.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.compiler.incremental;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class BytecodeAnalyzerTest {
+
+ @TempDir
+ Path sourceDir;
+
+ @TempDir
+ Path outputDir;
+
+ @Test
+ void descriptorToReadableVoid() {
+ assertEquals("void", BytecodeAnalyzer.descriptorToReadable("V"));
+ }
+
+ @Test
+ void descriptorToReadableBoolean() {
+ assertEquals("boolean", BytecodeAnalyzer.descriptorToReadable("Z"));
+ }
+
+ @Test
+ void descriptorToReadableByte() {
+ assertEquals("byte", BytecodeAnalyzer.descriptorToReadable("B"));
+ }
+
+ @Test
+ void descriptorToReadableChar() {
+ assertEquals("char", BytecodeAnalyzer.descriptorToReadable("C"));
+ }
+
+ @Test
+ void descriptorToReadableShort() {
+ assertEquals("short", BytecodeAnalyzer.descriptorToReadable("S"));
+ }
+
+ @Test
+ void descriptorToReadableInt() {
+ assertEquals("int", BytecodeAnalyzer.descriptorToReadable("I"));
+ }
+
+ @Test
+ void descriptorToReadableLong() {
+ assertEquals("long", BytecodeAnalyzer.descriptorToReadable("J"));
+ }
+
+ @Test
+ void descriptorToReadableFloat() {
+ assertEquals("float", BytecodeAnalyzer.descriptorToReadable("F"));
+ }
+
+ @Test
+ void descriptorToReadableDouble() {
+ assertEquals("double", BytecodeAnalyzer.descriptorToReadable("D"));
+ }
+
+ @Test
+ void descriptorToReadableObject() {
+ assertEquals("java.lang.String",
BytecodeAnalyzer.descriptorToReadable("Ljava/lang/String;"));
+ }
+
+ @Test
+ void descriptorToReadableArray() {
+ assertEquals("int[]", BytecodeAnalyzer.descriptorToReadable("[I"));
+ assertEquals("java.lang.String[]",
BytecodeAnalyzer.descriptorToReadable("[Ljava/lang/String;"));
+ }
+
+ @Test
+ void descriptorToReadableEmpty() {
+ assertEquals("", BytecodeAnalyzer.descriptorToReadable(""));
+ }
+
+ @Test
+ void parseParamsMultiple() {
+ assertEquals("java.lang.String, int",
BytecodeAnalyzer.parseParams("(Ljava/lang/String;I)V"));
+ }
+
+ @Test
+ void parseParamsEmpty() {
+ assertEquals("", BytecodeAnalyzer.parseParams("()V"));
+ }
+
+ @Test
+ void parseReturnType() {
+ assertEquals("java.lang.String",
BytecodeAnalyzer.parseReturn("(I)Ljava/lang/String;"));
+ assertEquals("void", BytecodeAnalyzer.parseReturn("()V"));
+ assertEquals("int", BytecodeAnalyzer.parseReturn("()I"));
+ }
+
+ @Test
+ void analyzePathProducesCorrectClassName() throws Exception {
+ CompilerTestHelper.writeSource(
+ sourceDir,
+ "test",
+ "Hello",
+ "package test; public class Hello { public String greet() {
return \"hi\"; } }");
+ CompilerTestHelper.compileAndAnalyze(sourceDir, outputDir);
+
+ Path classFile = outputDir.resolve("test/Hello.class");
+ assertTrue(Files.exists(classFile));
+
+ var analysis = BytecodeAnalyzer.analyze(classFile);
+ assertEquals("test.Hello", analysis.className());
+ assertNotNull(analysis.abiFingerprint());
+ assertNotNull(analysis.abiCanonical());
+ }
+
+ @Test
+ void analyzeBytesEquivalentToAnalyzePath() throws Exception {
+ CompilerTestHelper.writeSource(
+ sourceDir, "test", "Hello", "package test; public class Hello
{ public int value() { return 42; } }");
+ CompilerTestHelper.compileAndAnalyze(sourceDir, outputDir);
+
+ Path classFile = outputDir.resolve("test/Hello.class");
+ var fromPath = BytecodeAnalyzer.analyze(classFile);
+ var fromBytes =
BytecodeAnalyzer.analyze(Files.readAllBytes(classFile));
+
+ assertEquals(fromPath.className(), fromBytes.className());
+ assertEquals(fromPath.abiFingerprint(), fromBytes.abiFingerprint());
+ assertEquals(fromPath.abiCanonical(), fromBytes.abiCanonical());
+ assertEquals(fromPath.referencedTypes(), fromBytes.referencedTypes());
+ }
+
+ /**
+ * When running on JDK 24+, {@link BytecodeAnalyzer} uses {@link
ClassfileClassAnalyzer}
+ * instead of {@link AsmClassAnalyzer}. Both must produce identical
results for the same
+ * class file. This test cross-validates the two implementations against
each other.
+ */
+ @Test
+ void asmAndClassfileAnalyzersProduceIdenticalResults() throws Exception {
+ CompilerTestHelper.writeSource(sourceDir, "test", "Subject", """
+ package test;
+ public class Subject implements Runnable {
+ public static final String CONST = "hello";
+ private int secret = 42;
+ public String greet(int x, java.util.List<String> items) {
return CONST + x; }
+ @Override public void run() { greet(1, null); }
+ protected static int helper(byte b) throws
java.io.IOException { return b; }
+ }
+ """);
+ CompilerTestHelper.compileAndAnalyze(sourceDir, outputDir);
+
+ byte[] bytes =
Files.readAllBytes(outputDir.resolve("test/Subject.class"));
+
+ var asmResult = new AsmClassAnalyzer().analyze(bytes);
+ var cfResult = new ClassfileClassAnalyzer().analyze(bytes);
Review Comment:
🔴 **Critical — Test compilation broken on JDK < 24.** This test directly
instantiates `ClassfileClassAnalyzer`, which is compiled from
`src/main/java24/` with `--release 24`. On JDK < 24:
1. The `compile-java24` execution fails (see pom.xml comment), so
`ClassfileClassAnalyzer.class` doesn't exist
2. This test source references that class by name → compilation error
Fix: make the test conditional on JDK 24+ using JUnit 5's
`@EnabledForJreRange`:
```suggestion
var asmResult = new AsmClassAnalyzer().analyze(bytes);
```
Actually, the entire test method needs to be guarded:
```java
@Test
@org.junit.jupiter.api.condition.EnabledForJreRange(
min = org.junit.jupiter.api.condition.JRE.JAVA_24)
void asmAndClassfileAnalyzersProduceIdenticalResults() throws Exception {
```
But even with the annotation, the class reference in the method body will
fail compilation on JDK < 24. The cross-validation test needs to use
**reflection** to instantiate `ClassfileClassAnalyzer` (same pattern as
`BytecodeAnalyzer.selectAnalyzer()`), or be moved to a separate test source
root compiled with `--release 24` (e.g. `src/test/java24/`).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]