Skip to content

Commit ccdf28e

Browse files
authored
Add -proc:full whenever we run under Java 22 or newer (#660)
This fixes some warnings when compiling sources with JDK22 while targeting older compilers.
2 parents 59ace7a + 793ef5d commit ccdf28e

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JavacJctFlagBuilderImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ public JctFlagBuilder compilationMode(CompilationMode compilationMode) {
9393
break;
9494

9595
default:
96-
// In Java 22, the default is to disable all annotation processing by default.
97-
// Prior to Java 22, the default was to enable all annotation processing by default.
98-
craftedFlags.add(PROC_FULL);
96+
if (Runtime.version().feature() >= 22) {
97+
// In Java 22, the default is to disable all annotation processing by default
98+
// Prior to Java 22, the default was to enable all annotation processing by default.
99+
craftedFlags.add(PROC_FULL);
100+
}
99101
break;
100102
}
101103

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/compilers/impl/JavacJctFlagBuilderImplTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static io.github.ascopes.jct.tests.helpers.Fixtures.someRelease;
2020
import static org.assertj.core.api.Assertions.assertThat;
2121
import static org.assertj.core.api.Assertions.assertThatThrownBy;
22+
import static org.assertj.core.api.Assumptions.assumeThat;
2223

2324
import io.github.ascopes.jct.compilers.CompilationMode;
2425
import io.github.ascopes.jct.compilers.DebuggingInfo;
@@ -211,16 +212,38 @@ void annotationProcessingOnlyAddsProcOnly() {
211212
assertThat(flagBuilder.build()).containsExactly("-proc:only");
212213
}
213214

214-
@DisplayName(".compilationMode(COMPILATION_AND_ANNOTATION_PROCESSING) adds -proc:full")
215+
@DisplayName(".compilationMode(COMPILATION_AND_ANNOTATION_PROCESSING) adds -proc:full (JDK22)")
215216
@Test
216-
void compilationAndAnnotationProcessingAddsProcAll() {
217+
void compilationAndAnnotationProcessingAddsProcFullOnJdk22() {
218+
// Given
219+
assumeThat(Runtime.version().feature())
220+
.as("JDK version")
221+
.withFailMessage("this test only works on JDK 22 and newer")
222+
.isGreaterThanOrEqualTo(22);
223+
217224
// When
218225
flagBuilder.compilationMode(CompilationMode.COMPILATION_AND_ANNOTATION_PROCESSING);
219226

220227
// Then
221228
assertThat(flagBuilder.build()).containsExactly("-proc:full");
222229
}
223230

231+
@DisplayName(".compilationMode(COMPILATION_AND_ANNOTATION_PROCESSING) adds nothing (<JDK22)")
232+
@Test
233+
void compilationAndAnnotationProcessingAddsNothingBeforeJdk22() {
234+
// Given
235+
assumeThat(Runtime.version().feature())
236+
.as("JDK version")
237+
.withFailMessage("this test only works on JDK 21 and older")
238+
.isLessThan(22);
239+
240+
// When
241+
flagBuilder.compilationMode(CompilationMode.COMPILATION_AND_ANNOTATION_PROCESSING);
242+
243+
// Then
244+
assertThat(flagBuilder.build()).isEmpty();
245+
}
246+
224247
@DisplayName(".compilationMode(...) returns the flag builder")
225248
@EnumSource(CompilationMode.class)
226249
@ParameterizedTest(name = "for compilationMode = {0}")

0 commit comments

Comments
 (0)