From 4e93a2e5dac4b1e55bc249c4d7119b0cc5cd1fa0 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Wed, 9 Jul 2025 14:18:58 +0200 Subject: [PATCH 1/3] Enable ErrorProne checks and fix resulting findings * Classes with equals calling `getClass()` may potentially problematic. I made them `final` where they were "effectively" `final` by only having private or package-private constructors. * I switched from `LinkedList` to `ArrayList` or `ArrayDeque` based on ErrorProne's recommendations. --- .../src/main/java/example/domain/Person.java | 2 +- ...ld.java-nullability-conventions.gradle.kts | 18 +- .../org/junit/jupiter/api/Assertions.java | 198 +++++++++--------- .../org/junit/jupiter/api/Assumptions.java | 3 + .../org/junit/jupiter/api/condition/OS.java | 4 +- .../api/extension/ExtensionContext.java | 2 +- .../jupiter/api/extension/MediaType.java | 2 +- .../junit/jupiter/api/condition/JRE.java.jte | 20 +- .../descriptor/NestedClassTestDescriptor.java | 5 +- .../InterceptingExecutableInvoker.java | 4 +- .../engine/extension/TempDirectory.java | 1 + .../extension/TestInfoParameterResolver.java | 2 +- .../extension/TimeoutConfiguration.java | 3 +- .../engine/extension/TimeoutDuration.java | 3 +- .../extension/TimeoutInvocationFactory.java | 2 +- .../rules/ExpectedExceptionSupport.java | 6 +- .../params/ParameterizedClassContext.java | 14 +- .../ParameterizedInvocationNameFormatter.java | 2 + .../junit/jupiter/params/ResolverFacade.java | 8 +- .../params/provider/CsvArgumentsProvider.java | 1 + .../junit/platform/commons/function/Try.java | 4 +- .../commons/logging/LogRecordListener.java | 4 +- .../commons/support/AnnotationSupport.java | 3 + .../scanning/DefaultClasspathScanner.java | 6 +- .../commons/util/AnnotationUtils.java | 2 +- .../platform/commons/util/ExceptionUtils.java | 2 +- .../commons/util/ReflectionUtils.java | 11 +- .../commons/test/ConcurrencyTestingUtils.java | 1 + .../console/options/ConsoleUtils.java | 1 + .../platform/console/options/Details.java | 4 +- .../console/options/SelectorConverter.java | 2 + .../junit/platform/console/options/Theme.java | 3 +- .../platform/console/tasks/ColorPalette.java | 8 +- .../junit/platform/engine/FilterResult.java | 4 +- .../junit/platform/engine/TestDescriptor.java | 6 +- .../org/junit/platform/engine/UniqueId.java | 4 +- .../engine/discovery/ClassSelector.java | 2 +- .../discovery/ClasspathResourceSelector.java | 2 +- .../discovery/ClasspathRootSelector.java | 2 +- .../engine/discovery/DirectorySelector.java | 2 +- .../engine/discovery/FilePosition.java | 2 +- .../engine/discovery/FileSelector.java | 2 +- .../engine/discovery/IterationSelector.java | 2 +- .../engine/discovery/MethodSelector.java | 2 +- .../engine/discovery/ModuleSelector.java | 2 +- .../engine/discovery/NestedClassSelector.java | 2 +- .../discovery/NestedMethodSelector.java | 2 +- .../engine/discovery/PackageSelector.java | 2 +- .../engine/discovery/UniqueIdSelector.java | 2 +- .../engine/discovery/UriSelector.java | 2 +- .../platform/engine/reporting/FileEntry.java | 3 +- .../engine/reporting/ReportEntry.java | 3 +- .../descriptor/AbstractTestDescriptor.java | 1 + .../support/descriptor/ClassSource.java | 2 +- .../descriptor/ClasspathResourceSource.java | 2 +- .../descriptor/CompositeTestSource.java | 2 +- .../support/descriptor/DirectorySource.java | 2 +- .../support/descriptor/FilePosition.java | 2 +- .../engine/support/descriptor/FileSource.java | 2 +- .../support/descriptor/MethodSource.java | 2 +- .../support/descriptor/PackageSource.java | 2 +- .../discovery/DiscoveryIssueReporter.java | 1 + .../hierarchical/ExclusiveResource.java | 1 + ...inPoolHierarchicalTestExecutorService.java | 7 +- .../support/hierarchical/NodeTestTask.java | 1 + .../engine/support/store/Namespace.java | 2 +- .../platform/launcher/TestIdentifier.java | 1 + .../core/EngineDiscoveryOrchestrator.java | 6 +- .../core/LauncherConfigurationParameters.java | 87 +++++--- .../launcher/core/StreamInterceptor.java | 3 +- .../launcher/listeners/OutputDir.java | 27 ++- ...ortOnFailureLauncherDiscoveryListener.java | 2 +- .../LoggingLauncherDiscoveryListener.java | 2 +- .../launcher/tagexpression/ShuntingYard.java | 2 +- .../launcher/tagexpression/Tokenizer.java | 5 +- .../LegacyXmlReportGeneratingListener.java | 3 +- .../xml/OpenTestReportGeneratingListener.java | 1 + .../junit/platform/testkit/engine/Events.java | 1 + .../platform/testkit/engine/Executions.java | 2 + .../vintage/engine/execution/TestRun.java | 1 + .../tests/process/WatchedProcess.java | 1 + .../platform-tooling-support-tests.gradle.kts | 7 + 82 files changed, 340 insertions(+), 239 deletions(-) diff --git a/documentation/src/main/java/example/domain/Person.java b/documentation/src/main/java/example/domain/Person.java index 5da8625c722e..ad7d9ca52f69 100644 --- a/documentation/src/main/java/example/domain/Person.java +++ b/documentation/src/main/java/example/domain/Person.java @@ -12,7 +12,7 @@ import java.time.LocalDate; -public class Person { +public final class Person { public enum Gender { F, M diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts index a06ab1becca9..8b0ec60d8b18 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts @@ -19,9 +19,23 @@ nullaway { tasks.withType().configureEach { options.errorprone { - disableAllChecks = true + val onJ9 = java.toolchain.implementation.orNull == JvmImplementation.J9 + if (name == "compileJava" && !onJ9) { + disable( + "BadImport", + "UnnecessaryLambda", + "AnnotateFormatMethod", + "StringSplitter", + "DoNotCallSuggester", + "InlineMeSuggester", + "ImmutableEnumChecker", + "MissingSummary" + ) + } else { + disableAllChecks = true + } nullaway { - if (java.toolchain.implementation.orNull == JvmImplementation.J9) { + if (onJ9) { disable() } else { enable() diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assertions.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assertions.java index 90f5837520af..cc928e0eade9 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assertions.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assertions.java @@ -116,7 +116,7 @@ protected Assertions() { *

See Javadoc for {@link #fail(String)} for an explanation of this method's * generic return type {@code V}. */ - @SuppressWarnings("NullAway") + @SuppressWarnings({ "NullAway", "TypeParameterUnusedInFormals" }) public static V fail() { AssertionUtils.fail(); return null; // appeasing the compiler: this line will never be executed. @@ -136,7 +136,7 @@ public static V fail() { * Stream.of().map(entry -> fail("should not be called")); * } */ - @SuppressWarnings("NullAway") + @SuppressWarnings({ "NullAway", "TypeParameterUnusedInFormals" }) public static V fail(@Nullable String message) { AssertionUtils.fail(message); return null; // appeasing the compiler: this line will never be executed. @@ -149,7 +149,7 @@ public static V fail(@Nullable String message) { *

See Javadoc for {@link #fail(String)} for an explanation of this method's * generic return type {@code V}. */ - @SuppressWarnings("NullAway") + @SuppressWarnings({ "NullAway", "TypeParameterUnusedInFormals" }) public static V fail(@Nullable String message, @Nullable Throwable cause) { AssertionUtils.fail(message, cause); return null; // appeasing the compiler: this line will never be executed. @@ -161,7 +161,7 @@ public static V fail(@Nullable String message, @Nullable Throwable cause) { *

See Javadoc for {@link #fail(String)} for an explanation of this method's * generic return type {@code V}. */ - @SuppressWarnings("NullAway") + @SuppressWarnings({ "NullAway", "TypeParameterUnusedInFormals" }) public static V fail(@Nullable Throwable cause) { AssertionUtils.fail(cause); return null; // appeasing the compiler: this line will never be executed. @@ -174,7 +174,7 @@ public static V fail(@Nullable Throwable cause) { *

See Javadoc for {@link #fail(String)} for an explanation of this method's * generic return type {@code V}. */ - @SuppressWarnings("NullAway") + @SuppressWarnings({ "NullAway", "TypeParameterUnusedInFormals" }) public static V fail(Supplier<@Nullable String> messageSupplier) { AssertionUtils.fail(messageSupplier); return null; // appeasing the compiler: this line will never be executed. @@ -1741,7 +1741,7 @@ public static void assertLinesMatch(Stream expectedLines, Stream // --- assertNotEquals ----------------------------------------------------- /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1751,7 +1751,7 @@ public static void assertNotEquals(byte unexpected, byte actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1761,7 +1761,7 @@ public static void assertNotEquals(byte unexpected, @Nullable Byte actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1771,7 +1771,7 @@ public static void assertNotEquals(@Nullable Byte unexpected, byte actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1781,7 +1781,7 @@ public static void assertNotEquals(@Nullable Byte unexpected, @Nullable Byte act } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1793,7 +1793,7 @@ public static void assertNotEquals(byte unexpected, byte actual, @Nullable Strin } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1805,7 +1805,7 @@ public static void assertNotEquals(byte unexpected, @Nullable Byte actual, @Null } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1817,7 +1817,7 @@ public static void assertNotEquals(@Nullable Byte unexpected, byte actual, @Null } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1829,7 +1829,7 @@ public static void assertNotEquals(@Nullable Byte unexpected, @Nullable Byte act } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -1842,7 +1842,7 @@ public static void assertNotEquals(byte unexpected, byte actual, Supplier<@Nulla } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -1856,7 +1856,7 @@ public static void assertNotEquals(byte unexpected, @Nullable Byte actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -1870,7 +1870,7 @@ public static void assertNotEquals(@Nullable Byte unexpected, byte actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -1884,7 +1884,7 @@ public static void assertNotEquals(@Nullable Byte unexpected, @Nullable Byte act } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1894,7 +1894,7 @@ public static void assertNotEquals(short unexpected, short actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1904,7 +1904,7 @@ public static void assertNotEquals(short unexpected, @Nullable Short actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1914,7 +1914,7 @@ public static void assertNotEquals(@Nullable Short unexpected, short actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -1924,7 +1924,7 @@ public static void assertNotEquals(@Nullable Short unexpected, @Nullable Short a } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1936,7 +1936,7 @@ public static void assertNotEquals(short unexpected, short actual, @Nullable Str } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1948,7 +1948,7 @@ public static void assertNotEquals(short unexpected, @Nullable Short actual, @Nu } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1960,7 +1960,7 @@ public static void assertNotEquals(@Nullable Short unexpected, short actual, @Nu } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -1972,7 +1972,7 @@ public static void assertNotEquals(@Nullable Short unexpected, @Nullable Short a } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -1985,7 +1985,7 @@ public static void assertNotEquals(short unexpected, short actual, Supplier<@Nul } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -1999,7 +1999,7 @@ public static void assertNotEquals(short unexpected, @Nullable Short actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2013,7 +2013,7 @@ public static void assertNotEquals(@Nullable Short unexpected, short actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2027,7 +2027,7 @@ public static void assertNotEquals(@Nullable Short unexpected, @Nullable Short a } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2037,7 +2037,7 @@ public static void assertNotEquals(int unexpected, int actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2047,7 +2047,7 @@ public static void assertNotEquals(int unexpected, @Nullable Integer actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2057,7 +2057,7 @@ public static void assertNotEquals(@Nullable Integer unexpected, int actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2067,7 +2067,7 @@ public static void assertNotEquals(@Nullable Integer unexpected, @Nullable Integ } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2079,7 +2079,7 @@ public static void assertNotEquals(int unexpected, int actual, @Nullable String } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2091,7 +2091,7 @@ public static void assertNotEquals(int unexpected, @Nullable Integer actual, @Nu } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2103,7 +2103,7 @@ public static void assertNotEquals(@Nullable Integer unexpected, int actual, @Nu } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2116,7 +2116,7 @@ public static void assertNotEquals(@Nullable Integer unexpected, @Nullable Integ } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2129,7 +2129,7 @@ public static void assertNotEquals(int unexpected, int actual, Supplier<@Nullabl } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2143,7 +2143,7 @@ public static void assertNotEquals(int unexpected, @Nullable Integer actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2157,7 +2157,7 @@ public static void assertNotEquals(@Nullable Integer unexpected, int actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2171,7 +2171,7 @@ public static void assertNotEquals(@Nullable Integer unexpected, @Nullable Integ } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2181,7 +2181,7 @@ public static void assertNotEquals(long unexpected, long actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2191,7 +2191,7 @@ public static void assertNotEquals(long unexpected, @Nullable Long actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2201,7 +2201,7 @@ public static void assertNotEquals(@Nullable Long unexpected, long actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2211,7 +2211,7 @@ public static void assertNotEquals(@Nullable Long unexpected, @Nullable Long act } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2223,7 +2223,7 @@ public static void assertNotEquals(long unexpected, long actual, @Nullable Strin } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2235,7 +2235,7 @@ public static void assertNotEquals(long unexpected, @Nullable Long actual, @Null } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2247,7 +2247,7 @@ public static void assertNotEquals(@Nullable Long unexpected, long actual, @Null } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2259,7 +2259,7 @@ public static void assertNotEquals(@Nullable Long unexpected, @Nullable Long act } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2272,7 +2272,7 @@ public static void assertNotEquals(long unexpected, long actual, Supplier<@Nulla } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2286,7 +2286,7 @@ public static void assertNotEquals(long unexpected, @Nullable Long actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2300,7 +2300,7 @@ public static void assertNotEquals(@Nullable Long unexpected, long actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2314,7 +2314,7 @@ public static void assertNotEquals(@Nullable Long unexpected, @Nullable Long act } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2327,7 +2327,7 @@ public static void assertNotEquals(float unexpected, float actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2340,7 +2340,7 @@ public static void assertNotEquals(float unexpected, @Nullable Float actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2353,7 +2353,7 @@ public static void assertNotEquals(@Nullable Float unexpected, float actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2366,7 +2366,7 @@ public static void assertNotEquals(@Nullable Float unexpected, @Nullable Float a } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2381,7 +2381,7 @@ public static void assertNotEquals(float unexpected, float actual, @Nullable Str } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2396,7 +2396,7 @@ public static void assertNotEquals(float unexpected, @Nullable Float actual, @Nu } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2411,7 +2411,7 @@ public static void assertNotEquals(@Nullable Float unexpected, float actual, @Nu } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2426,7 +2426,7 @@ public static void assertNotEquals(@Nullable Float unexpected, @Nullable Float a } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2439,7 +2439,7 @@ public static void assertNotEquals(float unexpected, float actual, Supplier<@Nul } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2453,7 +2453,7 @@ public static void assertNotEquals(float unexpected, @Nullable Float actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2467,7 +2467,7 @@ public static void assertNotEquals(@Nullable Float unexpected, float actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Float#equals(Object)} and {@link Float#compare(float, float)}. @@ -2481,7 +2481,7 @@ public static void assertNotEquals(@Nullable Float unexpected, @Nullable Float a } /** - * Assert that {@code expected} and {@code actual} are not equal + * Assert that {@code unexpected} and {@code actual} are not equal * within the given {@code delta}. * *

Inequality imposed by this method is consistent with @@ -2495,7 +2495,7 @@ public static void assertNotEquals(float unexpected, float actual, float delta) } /** - * Assert that {@code expected} and {@code actual} are not equal + * Assert that {@code unexpected} and {@code actual} are not equal * within the given {@code delta}. * *

Inequality imposed by this method is consistent with @@ -2511,7 +2511,7 @@ public static void assertNotEquals(float unexpected, float actual, float delta, } /** - * Assert that {@code expected} and {@code actual} are not equal + * Assert that {@code unexpected} and {@code actual} are not equal * within the given {@code delta}. * *

Inequality imposed by this method is consistent with @@ -2526,7 +2526,7 @@ public static void assertNotEquals(float unexpected, float actual, float delta, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2539,7 +2539,7 @@ public static void assertNotEquals(double unexpected, double actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2552,7 +2552,7 @@ public static void assertNotEquals(double unexpected, @Nullable Double actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2565,7 +2565,7 @@ public static void assertNotEquals(@Nullable Double unexpected, double actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2578,7 +2578,7 @@ public static void assertNotEquals(@Nullable Double unexpected, @Nullable Double } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2593,7 +2593,7 @@ public static void assertNotEquals(double unexpected, double actual, @Nullable S } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2608,7 +2608,7 @@ public static void assertNotEquals(double unexpected, @Nullable Double actual, @ } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2623,7 +2623,7 @@ public static void assertNotEquals(@Nullable Double unexpected, double actual, @ } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2638,7 +2638,7 @@ public static void assertNotEquals(@Nullable Double unexpected, @Nullable Double } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2651,7 +2651,7 @@ public static void assertNotEquals(double unexpected, double actual, Supplier<@N } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2665,7 +2665,7 @@ public static void assertNotEquals(double unexpected, @Nullable Double actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2679,7 +2679,7 @@ public static void assertNotEquals(@Nullable Double unexpected, double actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Inequality imposed by this method is consistent with * {@link Double#equals(Object)} and {@link Double#compare(double, double)}. @@ -2693,7 +2693,7 @@ public static void assertNotEquals(@Nullable Double unexpected, @Nullable Double } /** - * Assert that {@code expected} and {@code actual} are not equal + * Assert that {@code unexpected} and {@code actual} are not equal * within the given {@code delta}. * *

Inequality imposed by this method is consistent with @@ -2707,7 +2707,7 @@ public static void assertNotEquals(double unexpected, double actual, double delt } /** - * Assert that {@code expected} and {@code actual} are not equal + * Assert that {@code unexpected} and {@code actual} are not equal * within the given {@code delta}. * *

Inequality imposed by this method is consistent with @@ -2723,7 +2723,7 @@ public static void assertNotEquals(double unexpected, double actual, double delt } /** - * Assert that {@code expected} and {@code actual} are not equal + * Assert that {@code unexpected} and {@code actual} are not equal * within the given {@code delta}. * *

Inequality imposed by this method is consistent with @@ -2738,7 +2738,7 @@ public static void assertNotEquals(double unexpected, double actual, double delt } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2748,7 +2748,7 @@ public static void assertNotEquals(char unexpected, char actual) { } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2758,7 +2758,7 @@ public static void assertNotEquals(char unexpected, @Nullable Character actual) } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2768,7 +2768,7 @@ public static void assertNotEquals(@Nullable Character unexpected, char actual) } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * * @since 5.4 */ @@ -2778,7 +2778,7 @@ public static void assertNotEquals(@Nullable Character unexpected, @Nullable Cha } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2790,7 +2790,7 @@ public static void assertNotEquals(char unexpected, char actual, @Nullable Strin } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2802,7 +2802,7 @@ public static void assertNotEquals(char unexpected, @Nullable Character actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2814,7 +2814,7 @@ public static void assertNotEquals(@Nullable Character unexpected, char actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails with the supplied failure {@code message}. * @@ -2827,7 +2827,7 @@ public static void assertNotEquals(@Nullable Character unexpected, @Nullable Cha } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2840,7 +2840,7 @@ public static void assertNotEquals(char unexpected, char actual, Supplier<@Nulla } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2854,7 +2854,7 @@ public static void assertNotEquals(char unexpected, @Nullable Character actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2868,7 +2868,7 @@ public static void assertNotEquals(@Nullable Character unexpected, char actual, } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

If necessary, the failure message will be retrieved lazily from the * supplied {@code messageSupplier}. @@ -2882,7 +2882,7 @@ public static void assertNotEquals(@Nullable Character unexpected, @Nullable Cha } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails if both are {@code null}. * @@ -2893,7 +2893,7 @@ public static void assertNotEquals(@Nullable Object unexpected, @Nullable Object } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails if both are {@code null}. * @@ -2906,7 +2906,7 @@ public static void assertNotEquals(@Nullable Object unexpected, @Nullable Object } /** - * Assert that {@code expected} and {@code actual} are not equal. + * Assert that {@code unexpected} and {@code actual} are not equal. * *

Fails if both are {@code null}. * @@ -3098,7 +3098,7 @@ public static void assertAll(Stream executables) throws MultipleFail * and all exceptions will be aggregated and reported in a {@link MultipleFailuresError}. * In addition, all aggregated exceptions will be added as {@linkplain * Throwable#addSuppressed(Throwable) suppressed exceptions} to the - * {@code MultipleFailuresError}. However, if an {@code executable} throws an + * {@code MultipleFailuresError}. However, if one of the {@code executables} throws an * unrecoverable exception — for example, an {@link OutOfMemoryError} * — execution will halt immediately, and the unrecoverable exception will be * rethrown as is but masked as an unchecked exception. diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java index b0619ad3cc32..4e293a9fee4b 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java @@ -278,6 +278,7 @@ public static void assumingThat(boolean assumption, Executable executable) { * @since 5.9 */ @API(status = STABLE, since = "5.9") + @SuppressWarnings("TypeParameterUnusedInFormals") public static V abort() { throw new TestAbortedException(); } @@ -301,6 +302,7 @@ public static V abort() { * @since 5.9 */ @API(status = STABLE, since = "5.9") + @SuppressWarnings("TypeParameterUnusedInFormals") public static V abort(String message) { throw new TestAbortedException(message); } @@ -317,6 +319,7 @@ public static V abort(String message) { * @since 5.9 */ @API(status = STABLE, since = "5.9") + @SuppressWarnings("TypeParameterUnusedInFormals") public static V abort(Supplier messageSupplier) { throw new TestAbortedException(messageSupplier.get()); } diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/OS.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/OS.java index 0c7ab8be1bc6..9af0daed730d 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/OS.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/OS.java @@ -147,8 +147,8 @@ public enum OS { } /** - * @return {@code true} if this {@code OS} is known to be the - * operating system on which the current JVM is executing + * {@return {@code true} if this {@code OS} is known to be the + * operating system on which the current JVM is executing} */ public boolean isCurrentOs() { return this == CURRENT_OS; diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ExtensionContext.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ExtensionContext.java index ce7523be8980..086a89f8d37d 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ExtensionContext.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ExtensionContext.java @@ -751,7 +751,7 @@ default V getOrDefault(Object key, Class requiredType, V defaultValue) { * mixing data between extensions or across different invocations within the * lifecycle of a single extension. */ - class Namespace { + final class Namespace { /** * The default, global namespace which allows access to stored data from diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/MediaType.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/MediaType.java index 2a8458e61a4e..83e9140af658 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/MediaType.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/MediaType.java @@ -35,7 +35,7 @@ * @see ExtensionContext#publishFile(String, MediaType, ThrowingConsumer) */ @API(status = MAINTAINED, since = "5.13.3") -public class MediaType { +public final class MediaType { private static final Pattern PATTERN; static { diff --git a/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte b/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte index 4d7d64286bd8..8b7da5172543 100644 --- a/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte +++ b/junit-jupiter-api/src/templates/resources/main/org/junit/jupiter/api/condition/JRE.java.jte @@ -113,9 +113,9 @@ public enum JRE { } /** - * @return {@code true} if this {@code JRE} is known to be the + * {@return {@code true} if this {@code JRE} is known to be the * Java Runtime Environment version for the currently executing JVM or if - * the version is {@link #OTHER} + * the version is {@link #OTHER}} * * @see #currentJre() * @see #currentVersionNumber() @@ -125,8 +125,8 @@ public enum JRE { } /** - * @return the {@link JRE} for the currently executing JVM, potentially - * {@link #OTHER} + * {@return the {@link JRE} for the currently executing JVM, potentially + * {@link #OTHER}} * * @since 5.7 * @see #currentVersionNumber() @@ -139,8 +139,8 @@ public enum JRE { } /** - * @return the {@link JRE} for the currently executing JVM, potentially - * {@link #OTHER} + * {@return the {@link JRE} for the currently executing JVM, potentially + * {@link #OTHER}} * * @since 5.12 * @see #currentVersionNumber() @@ -156,8 +156,8 @@ public enum JRE { } /** - * @return the version number for the currently executing JVM, or {@code -1} - * if the current JVM version could not be determined + * {@return the version number for the currently executing JVM, or {@code -1} + * if the current JVM version could not be determined} * * @since 5.12 * @see Runtime.Version#feature() @@ -169,10 +169,10 @@ public enum JRE { } /** - * @return {@code true} if the supplied version number is known to be the + * {@return {@code true} if the supplied version number is known to be the * Java Runtime Environment version for the currently executing JVM or if * the supplied version number is {@code -1} and the current JVM version - * could not be determined + * could not be determined} * * @since 5.12 * @see Runtime.Version#feature() diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/NestedClassTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/NestedClassTestDescriptor.java index d4b354b09d0e..6680c28f6b94 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/NestedClassTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/NestedClassTestDescriptor.java @@ -10,7 +10,6 @@ package org.junit.jupiter.engine.descriptor; -import static java.util.Collections.emptyList; import static org.apiguardian.api.API.Status.INTERNAL; import static org.junit.jupiter.engine.descriptor.DisplayNameUtils.createDisplayNameSupplierForNestedClass; import static org.junit.jupiter.engine.descriptor.ResourceLockAware.enclosingInstanceTypesDependentResourceLocksProviderEvaluator; @@ -92,9 +91,9 @@ public static List> getEnclosingTestClasses(@Nullable TestDescriptor pa if (parent instanceof TestClassAware testClassAwareParent) { List> result = new ArrayList<>(testClassAwareParent.getEnclosingTestClasses()); result.add(testClassAwareParent.getTestClass()); - return result; + return List.copyOf(result); } - return emptyList(); + return List.of(); } // --- ClassBasedTestDescriptor -------------------------------------------- diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/InterceptingExecutableInvoker.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/InterceptingExecutableInvoker.java index 416131d853cf..27a0b5fc2f60 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/InterceptingExecutableInvoker.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/InterceptingExecutableInvoker.java @@ -119,10 +119,10 @@ T apply(InvocationInterceptor interceptor, Invocation invocation, ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable; static ReflectiveInterceptorCall ofVoidMethod(VoidMethodInterceptorCall call) { - return ((interceptorChain, invocation, invocationContext, extensionContext) -> { + return (interceptorChain, invocation, invocationContext, extensionContext) -> { call.apply(interceptorChain, invocation, invocationContext, extensionContext); return null; - }); + }; } interface VoidMethodInterceptorCall { diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java index d352e94a358a..a20c136fe73a 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java @@ -526,6 +526,7 @@ private IOException createIOExceptionWithAttachedFailures(SortedMap optional) { return optional != null ? optional.orElse(null) : null; } diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutConfiguration.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutConfiguration.java index 42831f0e737d..cce55eb24638 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutConfiguration.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutConfiguration.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Timeout.ThreadMode.SAME_THREAD; import static org.junit.jupiter.api.Timeout.ThreadMode.SEPARATE_THREAD; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -126,7 +127,7 @@ Optional getDefaultTimeoutThreadMode() { private Optional parseTimeoutThreadModeConfiguration() { return extensionContext.getConfigurationParameter(DEFAULT_TIMEOUT_THREAD_MODE_PROPERTY_NAME).map(value -> { try { - ThreadMode threadMode = ThreadMode.valueOf(value.toUpperCase()); + ThreadMode threadMode = ThreadMode.valueOf(value.toUpperCase(Locale.ROOT)); if (threadMode == ThreadMode.INFERRED) { logger.warn( () -> "Invalid timeout thread mode '%s', only %s and %s can be used as configuration parameter for %s.".formatted( diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutDuration.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutDuration.java index 66c154faba5a..6643c16b7d60 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutDuration.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutDuration.java @@ -12,6 +12,7 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; +import java.util.Locale; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Timeout; @@ -35,7 +36,7 @@ static TimeoutDuration from(Timeout timeout) { @Override public String toString() { - String label = unit.name().toLowerCase(); + String label = unit.name().toLowerCase(Locale.ROOT); if (value == 1 && label.endsWith("s")) { label = label.substring(0, label.length() - 1); } diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java index 41312b59d622..290da23062d0 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java @@ -80,7 +80,7 @@ public void close() throws Exception { @SuppressWarnings("try") static class SingleThreadExecutorResource extends ExecutorResource { - @SuppressWarnings("unused") + @SuppressWarnings({ "unused", "ThreadPriorityCheck" }) SingleThreadExecutorResource() { super(Executors.newSingleThreadScheduledExecutor(runnable -> { Thread thread = new Thread(runnable, "junit-jupiter-timeout-watcher"); diff --git a/junit-jupiter-migrationsupport/src/main/java/org/junit/jupiter/migrationsupport/rules/ExpectedExceptionSupport.java b/junit-jupiter-migrationsupport/src/main/java/org/junit/jupiter/migrationsupport/rules/ExpectedExceptionSupport.java index ec84443b488d..e4a7e4e9bb0a 100644 --- a/junit-jupiter-migrationsupport/src/main/java/org/junit/jupiter/migrationsupport/rules/ExpectedExceptionSupport.java +++ b/junit-jupiter-migrationsupport/src/main/java/org/junit/jupiter/migrationsupport/rules/ExpectedExceptionSupport.java @@ -10,8 +10,6 @@ package org.junit.jupiter.migrationsupport.rules; -import static java.lang.Boolean.FALSE; -import static java.lang.Boolean.TRUE; import static org.apiguardian.api.API.Status.DEPRECATED; import org.apiguardian.api.API; @@ -57,13 +55,13 @@ public ExpectedExceptionSupport() { @Override public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable { - getStore(context).put(EXCEPTION_WAS_HANDLED, TRUE); + getStore(context).put(EXCEPTION_WAS_HANDLED, true); this.support.handleTestExecutionException(context, throwable); } @Override public void afterEach(ExtensionContext context) throws Exception { - Boolean handled = getStore(context).getOrComputeIfAbsent(EXCEPTION_WAS_HANDLED, key -> FALSE, Boolean.class); + Boolean handled = getStore(context).getOrComputeIfAbsent(EXCEPTION_WAS_HANDLED, key -> false, Boolean.class); if (handled != null && !handled) { this.support.afterEach(context); } diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedClassContext.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedClassContext.java index b6002a4ad817..b55964af555b 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedClassContext.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedClassContext.java @@ -60,14 +60,14 @@ class ParameterizedClassContext implements ParameterizedDeclarationContext(findLifecycleMethodsAndAssertStaticAndNonPrivate(testClass, - testInstanceLifecycle, BOTTOM_UP, AfterParameterizedClassInvocation.class, - AfterParameterizedClassInvocation::injectArguments, this.resolverFacade)); + this.afterMethods = new ArrayList<>(findLifecycleMethodsAndAssertStaticAndNonPrivate(testClass, BOTTOM_UP, + AfterParameterizedClassInvocation.class, AfterParameterizedClassInvocation::injectArguments, + this.resolverFacade)); // Since the bottom-up ordering of afterMethods will later be reversed when the // AfterParameterizedClassInvocationMethodInvoker extensions are executed within @@ -146,8 +146,8 @@ List getAfterMethods() { } private static List findLifecycleMethodsAndAssertStaticAndNonPrivate( - Class testClass, TestInstance.Lifecycle testInstanceLifecycle, HierarchyTraversalMode traversalMode, - Class annotationType, Predicate injectArgumentsPredicate, ResolverFacade resolverFacade) { + Class testClass, HierarchyTraversalMode traversalMode, Class annotationType, + Predicate injectArgumentsPredicate, ResolverFacade resolverFacade) { List methods = findAnnotatedMethods(testClass, annotationType, traversalMode); diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java index 4df551843e4d..d459709fde13 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java @@ -98,6 +98,7 @@ String format(int invocationIndex, EvaluatedArgumentSet arguments) { } } + @SuppressWarnings("JdkObsolete") private String formatSafely(int invocationIndex, EvaluatedArgumentSet arguments) { ArgumentsContext context = new ArgumentsContext(invocationIndex, arguments.getConsumedNames(), arguments.getName()); @@ -200,6 +201,7 @@ private static String argumentsPattern(int length) { private record PlaceholderPosition(int index, String placeholder) { } + @SuppressWarnings("ArrayRecordComponent") private record ArgumentsContext(int invocationIndex, @Nullable Object[] consumedArguments, Optional argumentSetName) { } diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java index 3aebf1fe27b1..9980fe7eefbf 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java @@ -234,8 +234,8 @@ ArgumentSetLifecycleMethod.ParameterResolver createLifecycleMethodParameterResol ResolverFacade lifecycleMethodResolverFacade = create(method, annotation); Map parameterDeclarationMapping = new HashMap<>(); - List errors = validateLifecycleMethodParameters(method, annotation, originalResolverFacade, - lifecycleMethodResolverFacade, parameterDeclarationMapping); + List errors = validateLifecycleMethodParameters(originalResolverFacade, lifecycleMethodResolverFacade, + parameterDeclarationMapping); return Try // .call(() -> configurationErrorOrSuccess(errors, @@ -336,8 +336,8 @@ private static NavigableMap validateFieldDec .collect(toMap(Map.Entry::getKey, entry -> entry.getValue().get(0), (d, __) -> d, TreeMap::new))); } - private static List validateLifecycleMethodParameters(Method method, Annotation annotation, - ResolverFacade originalResolverFacade, ResolverFacade lifecycleMethodResolverFacade, + private static List validateLifecycleMethodParameters(ResolverFacade originalResolverFacade, + ResolverFacade lifecycleMethodResolverFacade, Map parameterDeclarationMapping) { List actualDeclarations = lifecycleMethodResolverFacade.indexedParameterDeclarations.getAll(); List errors = new ArrayList<>(); diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java index 9a7c4ee47184..9f270d350387 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java @@ -103,6 +103,7 @@ private static List getHeaders(CsvRecord record) { return ((NamedCsvRecord) record).getHeader(); } + @SuppressWarnings({ "ReferenceEquality", "StringEquality" }) private static @Nullable String resolveNullMarker(String record) { return record == CsvReaderFactory.DefaultFieldModifier.NULL_MARKER ? null : record; } diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/function/Try.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/function/Try.java index 115ccb8e8ef2..7ac71abb59dc 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/function/Try.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/function/Try.java @@ -249,7 +249,7 @@ public interface Transformer extends Try { + private static final class Success extends Try { private final V value; @@ -327,7 +327,7 @@ public int hashCode() { } } - private static class Failure extends Try { + private static final class Failure extends Try { private final Exception cause; diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java index e5ac90f9d8fb..f530db714ce7 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/logging/LogRecordListener.java @@ -75,7 +75,7 @@ public Stream stream() { * @see #stream(Class) * @see #stream(Class, Level) */ - @SuppressWarnings("ConstantValue") + @SuppressWarnings({ "ConstantValue", "ReferenceEquality" }) public Stream stream(Level level) { // NOTE: we cannot use org.junit.platform.commons.util.Preconditions here // since that would introduce a package cycle. @@ -129,7 +129,7 @@ public Stream stream(Class clazz) { * @see #stream(Level) * @see #stream(Class) */ - @SuppressWarnings("ConstantValue") + @SuppressWarnings({ "ConstantValue", "ReferenceEquality" }) public Stream stream(Class clazz, Level level) { // NOTE: we cannot use org.junit.platform.commons.util.Preconditions here // since that would introduce a package cycle. diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java index 24044ac09e27..97e245989f26 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java @@ -70,6 +70,7 @@ private AnnotationSupport() { * @see #findRepeatableAnnotations(Optional, Class) */ @API(status = MAINTAINED, since = "1.3") + @SuppressWarnings("NullableOptional") public static boolean isAnnotated(@Nullable Optional element, Class annotationType) { @@ -112,6 +113,7 @@ public static boolean isAnnotated(@Nullable AnnotatedElement element, Class Optional findAnnotation( @Nullable Optional element, Class annotationType) { @@ -253,6 +255,7 @@ public static Optional findAnnotation(@Nullable Class< * @see #findRepeatableAnnotations(AnnotatedElement, Class) */ @API(status = MAINTAINED, since = "1.5") + @SuppressWarnings("NullableOptional") public static List findRepeatableAnnotations( @Nullable Optional element, Class annotationType) { diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/support/scanning/DefaultClasspathScanner.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/scanning/DefaultClasspathScanner.java index 16d545daf141..28b76fb19a2c 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/support/scanning/DefaultClasspathScanner.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/scanning/DefaultClasspathScanner.java @@ -10,7 +10,6 @@ package org.junit.platform.commons.support.scanning; -import static java.util.Collections.emptyList; import static java.util.stream.Collectors.joining; import static org.apiguardian.api.API.Status.INTERNAL; import static org.junit.platform.commons.support.scanning.ClasspathFilters.CLASS_FILE_SUFFIX; @@ -341,19 +340,18 @@ private static String packagePath(String packageName) { } private List getRootUrisForPackage(String basePackageName) { + List uris = new ArrayList<>(); try { Enumeration resources = getClassLoader().getResources(packagePath(basePackageName)); - List uris = new ArrayList<>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); uris.add(resource.toURI()); } - return uris; } catch (Exception ex) { logger.warn(ex, () -> "Error reading URIs from class loader for base package " + basePackageName); - return emptyList(); } + return uris; } } diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java index 0e7d7b7e2441..d277c250cfd4 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java @@ -326,7 +326,7 @@ private static void findRepeatableAnnotations(AnnotatedEl findRepeatableAnnotations(element.getAnnotations(), annotationType, containerType, inherited, found, visited); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "GetClassOnAnnotation" }) private static void findRepeatableAnnotations(Annotation[] candidates, Class annotationType, Class containerType, boolean inherited, Set found, Set visited) { diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ExceptionUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ExceptionUtils.java index 8874905af32a..3f68495d2393 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ExceptionUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ExceptionUtils.java @@ -76,7 +76,7 @@ public static RuntimeException throwAsUncheckedException(Throwable t) { return ExceptionUtils.throwAs(t); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "TypeParameterUnusedInFormals" }) private static T throwAs(Throwable t) throws T { throw (T) t; } diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java index 103b8f2fd234..ecb187cdb48a 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java @@ -217,6 +217,11 @@ public enum HierarchyTraversalMode { classNameToTypeMap = Collections.unmodifiableMap(classNamesToTypes); + primitiveToWrapperMap = createPrimitivesToWrapperMap(); + } + + @SuppressWarnings("IdentityHashMapUsage") + private static Map, Class> createPrimitivesToWrapperMap() { Map, Class> primitivesToWrappers = new IdentityHashMap<>(8); primitivesToWrappers.put(boolean.class, Boolean.class); @@ -228,7 +233,7 @@ public enum HierarchyTraversalMode { primitivesToWrappers.put(float.class, Float.class); primitivesToWrappers.put(double.class, Double.class); - primitiveToWrapperMap = Collections.unmodifiableMap(primitivesToWrappers); + return Collections.unmodifiableMap(primitivesToWrappers); } public static boolean isPublic(Class clazz) { @@ -637,13 +642,12 @@ public static Try tryToReadFieldValue(Class clazz, String fieldNa * @see #tryToReadFieldValue(Class, String, Object) */ @API(status = INTERNAL, since = "1.4") - @SuppressWarnings("NullAway") public static Try<@Nullable Object> tryToReadFieldValue(Field field, @Nullable Object instance) { Preconditions.notNull(field, "Field must not be null"); Preconditions.condition((instance != null || isStatic(field)), () -> String.format("Cannot read non-static field [%s] on a null instance.", field)); - return Try.call(() -> makeAccessible(field).get(instance)); + return Try.<@Nullable Object> call(() -> makeAccessible(field).get(instance)); } /** @@ -1421,6 +1425,7 @@ public static Try tryToGetMethod(Class clazz, String methodName, Clas * @since 1.11 */ @API(status = INTERNAL, since = "1.11") + @SuppressWarnings("ReferenceEquality") public static Method getInterfaceMethodIfPossible(Method method, @Nullable Class targetClass) { if (!isPublic(method) || method.getDeclaringClass().isInterface()) { return method; diff --git a/junit-platform-commons/src/testFixtures/java/org/junit/platform/commons/test/ConcurrencyTestingUtils.java b/junit-platform-commons/src/testFixtures/java/org/junit/platform/commons/test/ConcurrencyTestingUtils.java index 6f63ab1d7432..49818e769298 100644 --- a/junit-platform-commons/src/testFixtures/java/org/junit/platform/commons/test/ConcurrencyTestingUtils.java +++ b/junit-platform-commons/src/testFixtures/java/org/junit/platform/commons/test/ConcurrencyTestingUtils.java @@ -32,6 +32,7 @@ public static void executeConcurrently(int threads, Runnable action) throws Exce }); } + @SuppressWarnings("Finally") public static List executeConcurrently(int threads, Callable action) throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(threads); diff --git a/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java b/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java index bd39bff687da..d470acbd7963 100644 --- a/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java +++ b/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java @@ -35,6 +35,7 @@ public class ConsoleUtils { /** * {@return the charset of the console} */ + @SuppressWarnings("SystemConsoleNull") public static Charset charset() { Console console = System.console(); return console != null ? console.charset() : Charset.defaultCharset(); diff --git a/junit-platform-console/src/main/java/org/junit/platform/console/options/Details.java b/junit-platform-console/src/main/java/org/junit/platform/console/options/Details.java index 19008f76425c..b699385c2cc1 100644 --- a/junit-platform-console/src/main/java/org/junit/platform/console/options/Details.java +++ b/junit-platform-console/src/main/java/org/junit/platform/console/options/Details.java @@ -12,6 +12,8 @@ import static org.apiguardian.api.API.Status.INTERNAL; +import java.util.Locale; + import org.apiguardian.api.API; /** @@ -58,7 +60,7 @@ public enum Details { */ @Override public String toString() { - return name().toLowerCase(); + return name().toLowerCase(Locale.ROOT); } } diff --git a/junit-platform-console/src/main/java/org/junit/platform/console/options/SelectorConverter.java b/junit-platform-console/src/main/java/org/junit/platform/console/options/SelectorConverter.java index 66c7f6f14d89..b36e8dc437ec 100644 --- a/junit-platform-console/src/main/java/org/junit/platform/console/options/SelectorConverter.java +++ b/junit-platform-console/src/main/java/org/junit/platform/console/options/SelectorConverter.java @@ -73,6 +73,7 @@ public DirectorySelector convert(String value) { } } + @SuppressWarnings("JavaLangClash") static class Package implements ITypeConverter { @Override public PackageSelector convert(String value) { @@ -80,6 +81,7 @@ public PackageSelector convert(String value) { } } + @SuppressWarnings("JavaLangClash") static class Class implements ITypeConverter { @Override public ClassSelector convert(String value) { diff --git a/junit-platform-console/src/main/java/org/junit/platform/console/options/Theme.java b/junit-platform-console/src/main/java/org/junit/platform/console/options/Theme.java index 1abf7f8e0084..dca56000bb76 100644 --- a/junit-platform-console/src/main/java/org/junit/platform/console/options/Theme.java +++ b/junit-platform-console/src/main/java/org/junit/platform/console/options/Theme.java @@ -14,6 +14,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.Locale; import org.apiguardian.api.API; import org.junit.platform.engine.TestExecutionResult; @@ -129,7 +130,7 @@ public final String status(TestExecutionResult result) { */ @Override public final String toString() { - return name().toLowerCase(); + return name().toLowerCase(Locale.ROOT); } } diff --git a/junit-platform-console/src/main/java/org/junit/platform/console/tasks/ColorPalette.java b/junit-platform-console/src/main/java/org/junit/platform/console/tasks/ColorPalette.java index 120f2de48a6f..34c1aadd287c 100644 --- a/junit-platform-console/src/main/java/org/junit/platform/console/tasks/ColorPalette.java +++ b/junit-platform-console/src/main/java/org/junit/platform/console/tasks/ColorPalette.java @@ -13,9 +13,11 @@ import java.io.FileReader; import java.io.IOException; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.Arrays; import java.util.EnumMap; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.function.Function; @@ -89,8 +91,8 @@ private ColorPalette(Map colorsToAnsiSequences, boolean disableAn } private static Map toOverrideMap(Properties properties) { - Map upperCaseProperties = properties.entrySet().stream().collect( - Collectors.toMap(entry -> ((String) entry.getKey()).toUpperCase(), entry -> (String) entry.getValue())); + Map upperCaseProperties = properties.entrySet().stream().collect(Collectors.toMap( + entry -> ((String) entry.getKey()).toUpperCase(Locale.ROOT), entry -> (String) entry.getValue())); return Arrays.stream(Style.values()).filter(style -> upperCaseProperties.containsKey(style.name())).collect( Collectors.toMap(Function.identity(), style -> upperCaseProperties.get(style.name()))); @@ -108,7 +110,7 @@ private static Properties getProperties(Reader reader) { } private static Properties getProperties(Path path) { - try (FileReader fileReader = new FileReader(path.toFile())) { + try (FileReader fileReader = new FileReader(path.toFile(), StandardCharsets.UTF_8)) { return getProperties(fileReader); } catch (IOException e) { diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/FilterResult.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/FilterResult.java index eabfcfe20815..7007436f4d9b 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/FilterResult.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/FilterResult.java @@ -80,14 +80,14 @@ private FilterResult(boolean included, @Nullable String reason) { } /** - * @return {@code true} if the filtered object should be included + * {@return {@code true} if the filtered object should be included} */ public boolean included() { return this.included; } /** - * @return {@code true} if the filtered object should be excluded + * {@return {@code true} if the filtered object should be excluded} */ public boolean excluded() { return !included(); diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/TestDescriptor.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/TestDescriptor.java index 2039ecf8ba11..8d146c05b616 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/TestDescriptor.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/TestDescriptor.java @@ -371,15 +371,15 @@ enum Type { CONTAINER_AND_TEST; /** - * @return {@code true} if this type represents a descriptor that can - * contain other descriptors + * {@return {@code true} if this type represents a descriptor that can + * contain other descriptors} */ public boolean isContainer() { return this == CONTAINER || this == CONTAINER_AND_TEST; } /** - * @return {@code true} if this type represents a descriptor for a test + * {@return {@code true} if this type represents a descriptor for a test} */ public boolean isTest() { return this == TEST || this == CONTAINER_AND_TEST; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/UniqueId.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/UniqueId.java index c60e716d54ec..d98070bafb78 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/UniqueId.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/UniqueId.java @@ -35,7 +35,7 @@ * @since 1.0 */ @API(status = STABLE, since = "1.0") -public class UniqueId implements Cloneable, Serializable { +public final class UniqueId implements Cloneable, Serializable { @Serial private static final long serialVersionUID = 1L; @@ -295,7 +295,7 @@ public String toString() { * value. */ @API(status = STABLE, since = "1.0") - public static class Segment implements Serializable { + public static final class Segment implements Serializable { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClassSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClassSelector.java index 82a0b305ee65..2a84df0d55ba 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClassSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClassSelector.java @@ -46,7 +46,7 @@ * @see org.junit.platform.engine.support.descriptor.ClassSource */ @API(status = STABLE, since = "1.0") -public class ClassSelector implements DiscoverySelector { +public final class ClassSelector implements DiscoverySelector { private final @Nullable ClassLoader classLoader; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathResourceSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathResourceSelector.java index a7f83f3b4715..5cd34a04a990 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathResourceSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathResourceSelector.java @@ -53,7 +53,7 @@ * @see #getClasspathResourceName() */ @API(status = STABLE, since = "1.0") -public class ClasspathResourceSelector implements DiscoverySelector { +public final class ClasspathResourceSelector implements DiscoverySelector { private final String classpathResourceName; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathRootSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathRootSelector.java index 27708e10f8f2..17fea2805930 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathRootSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ClasspathRootSelector.java @@ -44,7 +44,7 @@ * @see Thread#getContextClassLoader() */ @API(status = STABLE, since = "1.0") -public class ClasspathRootSelector implements DiscoverySelector { +public final class ClasspathRootSelector implements DiscoverySelector { private final URI classpathRoot; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/DirectorySelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/DirectorySelector.java index 577b97bc93a1..f6e9a3cc92eb 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/DirectorySelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/DirectorySelector.java @@ -40,7 +40,7 @@ * @see #getRawPath() */ @API(status = STABLE, since = "1.0") -public class DirectorySelector implements DiscoverySelector { +public final class DirectorySelector implements DiscoverySelector { private final String path; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FilePosition.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FilePosition.java index 74973ef3fa90..fcf3f1f0889c 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FilePosition.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FilePosition.java @@ -37,7 +37,7 @@ * @since 1.7 */ @API(status = STABLE, since = "1.7") -public class FilePosition implements Serializable { +public final class FilePosition implements Serializable { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FileSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FileSelector.java index ac01e74b5379..e90a75ade8e6 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FileSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/FileSelector.java @@ -42,7 +42,7 @@ * @see #getRawPath() */ @API(status = STABLE, since = "1.0") -public class FileSelector implements DiscoverySelector { +public final class FileSelector implements DiscoverySelector { private final String path; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/IterationSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/IterationSelector.java index 8b63b8a01a77..0d06e7c3a264 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/IterationSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/IterationSelector.java @@ -45,7 +45,7 @@ * @see DiscoverySelectors#selectIteration(DiscoverySelector, int...) */ @API(status = MAINTAINED, since = "1.13.3") -public class IterationSelector implements DiscoverySelector { +public final class IterationSelector implements DiscoverySelector { private final DiscoverySelector parentSelector; private final SortedSet iterationIndices; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/MethodSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/MethodSelector.java index 74efbcf9c5f2..27fd6aea479a 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/MethodSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/MethodSelector.java @@ -58,7 +58,7 @@ * @see org.junit.platform.engine.support.descriptor.MethodSource */ @API(status = STABLE, since = "1.0") -public class MethodSelector implements DiscoverySelector { +public final class MethodSelector implements DiscoverySelector { private final @Nullable ClassLoader classLoader; private final String className; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ModuleSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ModuleSelector.java index 0cac7f2e3bfe..1ecd5d7de8fa 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ModuleSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/ModuleSelector.java @@ -31,7 +31,7 @@ * @see DiscoverySelectors#selectModules(java.util.Set) */ @API(status = STABLE, since = "1.1") -public class ModuleSelector implements DiscoverySelector { +public final class ModuleSelector implements DiscoverySelector { private final String moduleName; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedClassSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedClassSelector.java index 30996cd3e167..b24e907c0285 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedClassSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedClassSelector.java @@ -51,7 +51,7 @@ * @see ClassSelector */ @API(status = STABLE, since = "1.6") -public class NestedClassSelector implements DiscoverySelector { +public final class NestedClassSelector implements DiscoverySelector { private final @Nullable ClassLoader classLoader; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedMethodSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedMethodSelector.java index 9fc6415b63a7..c796e862cb01 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedMethodSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/NestedMethodSelector.java @@ -56,7 +56,7 @@ * @see MethodSelector */ @API(status = STABLE, since = "1.6") -public class NestedMethodSelector implements DiscoverySelector { +public final class NestedMethodSelector implements DiscoverySelector { private final NestedClassSelector nestedClassSelector; private final MethodSelector methodSelector; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/PackageSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/PackageSelector.java index 8f84886873cf..b95b89c43077 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/PackageSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/PackageSelector.java @@ -31,7 +31,7 @@ * @see org.junit.platform.engine.support.descriptor.PackageSource */ @API(status = STABLE, since = "1.0") -public class PackageSelector implements DiscoverySelector { +public final class PackageSelector implements DiscoverySelector { private final String packageName; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UniqueIdSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UniqueIdSelector.java index ebf1e35697ba..9677e1c4976b 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UniqueIdSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UniqueIdSelector.java @@ -32,7 +32,7 @@ * @see DiscoverySelectors#selectUniqueId(UniqueId) */ @API(status = STABLE, since = "1.0") -public class UniqueIdSelector implements DiscoverySelector { +public final class UniqueIdSelector implements DiscoverySelector { private final UniqueId uniqueId; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UriSelector.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UriSelector.java index 1c7b635a915e..1d4521679b16 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UriSelector.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/discovery/UriSelector.java @@ -35,7 +35,7 @@ * @see org.junit.platform.engine.support.descriptor.UriSource */ @API(status = STABLE, since = "1.0") -public class UriSelector implements DiscoverySelector { +public final class UriSelector implements DiscoverySelector { private final URI uri; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/FileEntry.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/FileEntry.java index 3d02c01f797a..5627479185f1 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/FileEntry.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/FileEntry.java @@ -14,6 +14,7 @@ import java.nio.file.Path; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Optional; import org.apiguardian.api.API; @@ -43,7 +44,7 @@ public static FileEntry from(Path path, @Nullable String mediaType) { return new FileEntry(path, mediaType); } - private final LocalDateTime timestamp = LocalDateTime.now(); + private final LocalDateTime timestamp = LocalDateTime.now(ZoneId.systemDefault()); private final Path path; private final @Nullable String mediaType; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/ReportEntry.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/ReportEntry.java index 28587cfe0615..2dfc47d49683 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/ReportEntry.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/reporting/ReportEntry.java @@ -13,6 +13,7 @@ import static org.apiguardian.api.API.Status.STABLE; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -32,7 +33,7 @@ @API(status = STABLE, since = "1.0") public final class ReportEntry { - private final LocalDateTime timestamp = LocalDateTime.now(); + private final LocalDateTime timestamp = LocalDateTime.now(ZoneId.systemDefault()); private final Map keyValuePairs = new LinkedHashMap<>(); private ReportEntry() { diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/AbstractTestDescriptor.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/AbstractTestDescriptor.java index 4292bc7f6028..645b835eb95b 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/AbstractTestDescriptor.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/AbstractTestDescriptor.java @@ -190,6 +190,7 @@ public final int hashCode() { } @Override + @SuppressWarnings("EqualsGetClass") public final boolean equals(Object other) { if (other == null) { return false; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClassSource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClassSource.java index 7852ba45b8a0..07304feec0e1 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClassSource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClassSource.java @@ -43,7 +43,7 @@ * @see org.junit.platform.engine.discovery.ClassSelector */ @API(status = STABLE, since = "1.0") -public class ClassSource implements TestSource { +public final class ClassSource implements TestSource { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClasspathResourceSource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClasspathResourceSource.java index 838b92d9ad8e..988f8c314e2b 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClasspathResourceSource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/ClasspathResourceSource.java @@ -33,7 +33,7 @@ * @see org.junit.platform.engine.discovery.ClasspathResourceSelector */ @API(status = STABLE, since = "1.0") -public class ClasspathResourceSource implements TestSource { +public final class ClasspathResourceSource implements TestSource { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/CompositeTestSource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/CompositeTestSource.java index 15438b93c4b1..59b94cc5ca90 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/CompositeTestSource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/CompositeTestSource.java @@ -29,7 +29,7 @@ * @since 1.0 */ @API(status = STABLE, since = "1.0") -public class CompositeTestSource implements TestSource { +public final class CompositeTestSource implements TestSource { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/DirectorySource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/DirectorySource.java index a2b3645bd203..79505ee177fd 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/DirectorySource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/DirectorySource.java @@ -29,7 +29,7 @@ * @see org.junit.platform.engine.discovery.DirectorySelector */ @API(status = STABLE, since = "1.0") -public class DirectorySource implements FileSystemSource { +public final class DirectorySource implements FileSystemSource { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FilePosition.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FilePosition.java index 7d8d9b5500ff..65b0bae08118 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FilePosition.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FilePosition.java @@ -32,7 +32,7 @@ * @since 1.0 */ @API(status = STABLE, since = "1.0") -public class FilePosition implements Serializable { +public final class FilePosition implements Serializable { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FileSource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FileSource.java index 577f602659db..dd253f6a0087 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FileSource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/FileSource.java @@ -33,7 +33,7 @@ * @see org.junit.platform.engine.discovery.FileSelector */ @API(status = STABLE, since = "1.0") -public class FileSource implements FileSystemSource { +public final class FileSource implements FileSystemSource { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/MethodSource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/MethodSource.java index 1917dd19b168..cde3533a72b0 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/MethodSource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/MethodSource.java @@ -36,7 +36,7 @@ * @see org.junit.platform.engine.discovery.MethodSelector */ @API(status = STABLE, since = "1.0") -public class MethodSource implements TestSource { +public final class MethodSource implements TestSource { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/PackageSource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/PackageSource.java index d3c46953a3f9..94befac98143 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/PackageSource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/descriptor/PackageSource.java @@ -30,7 +30,7 @@ * @see org.junit.platform.engine.discovery.PackageSelector */ @API(status = STABLE, since = "1.0") -public class PackageSource implements TestSource { +public final class PackageSource implements TestSource { @Serial private static final long serialVersionUID = 1L; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/discovery/DiscoveryIssueReporter.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/discovery/DiscoveryIssueReporter.java index bfe4a854902c..ffebf29bd580 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/discovery/DiscoveryIssueReporter.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/discovery/DiscoveryIssueReporter.java @@ -165,6 +165,7 @@ static Condition alwaysSatisfied() { * * @return the composed condition; never {@code null} */ + @SuppressWarnings("ShortCircuitBoolean") default Condition and(Condition that) { Preconditions.notNull(that, "condition must not be null"); return value -> this.check(value) & that.check(value); diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ExclusiveResource.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ExclusiveResource.java index 3373f9259f4e..fdb0361862b9 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ExclusiveResource.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ExclusiveResource.java @@ -92,6 +92,7 @@ public LockMode getLockMode() { } @Override + @SuppressWarnings("EqualsGetClass") public boolean equals(Object o) { if (this == o) { return true; diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ForkJoinPoolHierarchicalTestExecutorService.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ForkJoinPoolHierarchicalTestExecutorService.java index 60677dea7bac..ced88fc1b946 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ForkJoinPoolHierarchicalTestExecutorService.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/ForkJoinPoolHierarchicalTestExecutorService.java @@ -21,7 +21,6 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; -import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.concurrent.Callable; @@ -161,9 +160,9 @@ public void invokeAll(List tasks) { new ExclusiveTask(tasks.get(0)).execSync(); return; } - Deque isolatedTasks = new LinkedList<>(); - Deque sameThreadTasks = new LinkedList<>(); - Deque concurrentTasksInReverseOrder = new LinkedList<>(); + Deque isolatedTasks = new ArrayDeque<>(); + Deque sameThreadTasks = new ArrayDeque<>(); + Deque concurrentTasksInReverseOrder = new ArrayDeque<>(); forkConcurrentTasks(tasks, isolatedTasks, sameThreadTasks, concurrentTasksInReverseOrder); executeSync(sameThreadTasks); joinConcurrentTasksInReverseOrderToEnableWorkStealing(concurrentTasksInReverseOrder); diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/NodeTestTask.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/NodeTestTask.java index 321c3df0027b..1f09383680fd 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/NodeTestTask.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/NodeTestTask.java @@ -241,6 +241,7 @@ private class DefaultDynamicTestExecutor implements DynamicTestExecutor { private final Map unfinishedTasks = new ConcurrentHashMap<>(); @Override + @SuppressWarnings("FutureReturnValueIgnored") public void execute(TestDescriptor testDescriptor) { execute(testDescriptor, taskContext.listener()); } diff --git a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/Namespace.java b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/Namespace.java index d18935b75c4f..9f5a885c0b2f 100644 --- a/junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/Namespace.java +++ b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/Namespace.java @@ -28,7 +28,7 @@ * lifecycle of a single extension. */ @API(status = EXPERIMENTAL, since = "6.0") -public class Namespace { +public final class Namespace { /** * The default, global namespace which allows access to stored data from diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java index 6cc56a0dd9af..335fc24dafdc 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/TestIdentifier.java @@ -52,6 +52,7 @@ public final class TestIdentifier implements Serializable { @Serial private static final long serialVersionUID = 1L; @Serial + @SuppressWarnings("UnusedVariable") private static final ObjectStreamField[] serialPersistentFields = ObjectStreamClass.lookup( SerializedForm.class).getFields(); diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/EngineDiscoveryOrchestrator.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/EngineDiscoveryOrchestrator.java index 7d2e7c529d4e..5c4a2f779ae9 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/EngineDiscoveryOrchestrator.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/EngineDiscoveryOrchestrator.java @@ -15,9 +15,9 @@ import static org.junit.platform.engine.Filter.composeFilters; import static org.junit.platform.launcher.core.LauncherPhase.getDiscoveryIssueFailurePhase; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -177,7 +177,7 @@ private Map discoverSafely(LauncherDiscoveryReques engineFilterer.performSanityChecks(); - List filters = new LinkedList<>(postDiscoveryFilters); + List filters = new ArrayList<>(postDiscoveryFilters); filters.addAll(request.getPostDiscoveryFilters()); applyPostDiscoveryFilters(testEngineDescriptors, filters); @@ -238,7 +238,7 @@ private void applyPostDiscoveryFilters(Map testEng private void populateExclusionReasonInMap(Optional reason, TestDescriptor testDescriptor, Map> excludedTestDescriptorsByReason) { - excludedTestDescriptorsByReason.computeIfAbsent(reason.orElse("Unknown"), list -> new LinkedList<>()).add( + excludedTestDescriptorsByReason.computeIfAbsent(reason.orElse("Unknown"), __ -> new ArrayList<>()).add( testDescriptor); } diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherConfigurationParameters.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherConfigurationParameters.java index be3128ed4758..7d105169d7c0 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherConfigurationParameters.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherConfigurationParameters.java @@ -12,14 +12,16 @@ import static java.util.stream.Collectors.joining; +import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -34,6 +36,7 @@ import org.junit.platform.commons.logging.LoggerFactory; import org.junit.platform.commons.util.ClassLoaderUtils; import org.junit.platform.commons.util.CollectionUtils; +import org.junit.platform.commons.util.ExceptionUtils; import org.junit.platform.commons.util.Preconditions; import org.junit.platform.commons.util.ToStringBuilder; import org.junit.platform.engine.ConfigurationParameters; @@ -252,32 +255,9 @@ private static Properties loadClasspathResource(String configFileName) { Properties props = new Properties(); try { - ClassLoader classLoader = ClassLoaderUtils.getDefaultClassLoader(); - Set resources = new LinkedHashSet<>(Collections.list(classLoader.getResources(configFileName))); - - if (!resources.isEmpty()) { - - URL configFileUrl = CollectionUtils.getFirstElement(resources).get(); - - if (resources.size() > 1) { - logger.warn(() -> { - String formattedResourceList = Stream.concat( // - Stream.of(configFileUrl + " (*)"), // - resources.stream().skip(1).map(URL::toString) // - ).collect(joining("\n- ", "\n- ", "")); - return "Discovered %d '%s' configuration files on the classpath (see below); only the first (*) will be used.%s".formatted( - resources.size(), configFileName, formattedResourceList); - }); - } - - logger.config( - () -> "Loading JUnit Platform configuration parameters from classpath resource [%s].".formatted( - configFileUrl)); - URLConnection urlConnection = configFileUrl.openConnection(); - urlConnection.setUseCaches(false); - try (InputStream inputStream = urlConnection.getInputStream()) { - props.load(inputStream); - } + URL configFileUrl = findConfigFile(configFileName); + if (configFileUrl != null) { + loadClasspathResource(configFileUrl, props); } } catch (Exception ex) { @@ -289,4 +269,57 @@ private static Properties loadClasspathResource(String configFileName) { return props; } + private static @Nullable URL findConfigFile(String configFileName) throws IOException { + + ClassLoader classLoader = ClassLoaderUtils.getDefaultClassLoader(); + List urls = Collections.list(classLoader.getResources(configFileName)); + + if (urls.size() == 1) { + return urls.get(0); + } + + if (urls.size() > 1) { + + List resources = urls.stream() // + .map(LauncherConfigurationParameters::toURI) // + .distinct() // + .toList(); + + URL configFileUrl = resources.get(0).toURL(); + + if (resources.size() > 1) { + logger.warn(() -> { + String formattedResourceList = Stream.concat( // + Stream.of(configFileUrl + " (*)"), // + resources.stream().skip(1).map(URI::toString) // + ).collect(joining("\n- ", "\n- ", "")); + return "Discovered %d '%s' configuration files on the classpath (see below); only the first (*) will be used.%s".formatted( + resources.size(), configFileName, formattedResourceList); + }); + } + return configFileUrl; + } + + return null; + } + + private static void loadClasspathResource(URL configFileUrl, Properties props) throws IOException { + logger.config(() -> "Loading JUnit Platform configuration parameters from classpath resource [%s].".formatted( + configFileUrl)); + URLConnection urlConnection = configFileUrl.openConnection(); + urlConnection.setUseCaches(false); + try (InputStream inputStream = urlConnection.getInputStream()) { + props.load(inputStream); + } + } + + private static URI toURI(URL url) { + try { + return url.toURI(); + } + catch (URISyntaxException e) { + throw ExceptionUtils.throwAsUncheckedException(e); + } + } + } diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/StreamInterceptor.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/StreamInterceptor.java index 60a3d6a8cc9a..d10db3855648 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/StreamInterceptor.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/StreamInterceptor.java @@ -12,6 +12,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.nio.charset.Charset; import java.util.ArrayDeque; import java.util.Deque; import java.util.Optional; @@ -138,7 +139,7 @@ String rewind() { } int length = count - position; count -= length; - return new String(buf, position, length); + return new String(buf, position, length, Charset.defaultCharset()); } } } diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java index 34be95e19c12..925c437d5f1a 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java @@ -60,12 +60,7 @@ private static OutputDir createSafely(Optional customDir, Supplier Path outputDir; if (customDir.isPresent() && StringUtils.isNotBlank(customDir.get())) { - String customPath = customDir.get(); - while (customPath.contains(OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER)) { - customPath = OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER_PATTERN.matcher(customPath) // - .replaceFirst(String.valueOf(Math.abs(random.nextLong()))); - } - outputDir = cwd.resolve(customPath); + outputDir = cwd.resolve(expandPlaceholders(customDir.get(), random)); } else if (Files.exists(cwd.resolve("pom.xml"))) { outputDir = cwd.resolve("target"); @@ -84,6 +79,15 @@ else if (containsFilesWithExtensions(cwd, ".gradle", ".gradle.kts")) { return new OutputDir(outputDir.normalize(), random); } + private static String expandPlaceholders(String customDir, SecureRandom random) { + String customPath = customDir; + while (customPath.contains(OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER)) { + customPath = OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER_PATTERN.matcher(customPath) // + .replaceFirst(String.valueOf(positiveLong(random))); + } + return customPath; + } + private final Path path; private final SecureRandom random; @@ -97,7 +101,7 @@ public Path toPath() { } public Path createFile(String prefix, String extension) throws UncheckedIOException { - String filename = "%s-%d.%s".formatted(prefix, Math.abs(random.nextLong()), extension); + String filename = "%s-%d.%s".formatted(prefix, positiveLong(random), extension); Path outputFile = path.resolve(filename); try { @@ -111,6 +115,15 @@ public Path createFile(String prefix, String extension) throws UncheckedIOExcept } } + private static long positiveLong(SecureRandom random) { + var value = random.nextLong(); + if (value == Long.MIN_VALUE) { + // ensure Math.abs returns positive value + value++; + } + return Math.abs(value); + } + /** * Determine if the supplied directory contains files with any of the * supplied extensions. diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/AbortOnFailureLauncherDiscoveryListener.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/AbortOnFailureLauncherDiscoveryListener.java index 3892a8ae565c..ce38669105eb 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/AbortOnFailureLauncherDiscoveryListener.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/AbortOnFailureLauncherDiscoveryListener.java @@ -19,7 +19,7 @@ * @since 1.6 * @see LauncherDiscoveryListeners#abortOnFailure() */ -class AbortOnFailureLauncherDiscoveryListener implements LauncherDiscoveryListener { +final class AbortOnFailureLauncherDiscoveryListener implements LauncherDiscoveryListener { @Override public void engineDiscoveryFinished(UniqueId engineId, EngineDiscoveryResult result) { diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/LoggingLauncherDiscoveryListener.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/LoggingLauncherDiscoveryListener.java index 922b9068b2e4..1e1f008cbda3 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/LoggingLauncherDiscoveryListener.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/discovery/LoggingLauncherDiscoveryListener.java @@ -31,7 +31,7 @@ * @since 1.6 * @see LauncherDiscoveryListeners#logging() */ -class LoggingLauncherDiscoveryListener implements LauncherDiscoveryListener { +final class LoggingLauncherDiscoveryListener implements LauncherDiscoveryListener { private static final Logger logger = LoggerFactory.getLogger(LoggingLauncherDiscoveryListener.class); diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/ShuntingYard.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/ShuntingYard.java index 8a1922012d2d..18eb18fab029 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/ShuntingYard.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/ShuntingYard.java @@ -111,7 +111,7 @@ private ParseStatus findMatchingLeftParenthesis(Token token) { private ParseStatus findOperands(Token token, Operator currentOperator) { while (currentOperator.hasLowerPrecedenceThan(previousOperator()) - || currentOperator.hasSamePrecedenceAs(previousOperator()) && currentOperator.isLeftAssociative()) { + || (currentOperator.hasSamePrecedenceAs(previousOperator()) && currentOperator.isLeftAssociative())) { TokenWith tokenWithWithOperator = operators.pop(); ParseStatus parseStatus = tokenWithWithOperator.element().createAndAddExpressionTo(expressions, tokenWithWithOperator.token()); diff --git a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/Tokenizer.java b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/Tokenizer.java index 57a5e6cbe687..34a236838dcc 100644 --- a/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/Tokenizer.java +++ b/junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/Tokenizer.java @@ -10,7 +10,6 @@ package org.junit.platform.launcher.tagexpression; -import static java.util.Collections.emptyList; import static java.util.regex.Pattern.CASE_INSENSITIVE; import java.util.ArrayList; @@ -30,14 +29,14 @@ class Tokenizer { List tokenize(@Nullable String infixTagExpression) { if (infixTagExpression == null) { - return emptyList(); + return List.of(); } List parts = new ArrayList<>(); Matcher matcher = PATTERN.matcher(infixTagExpression); while (matcher.find()) { parts.add(new Token(matcher.start(), matcher.group())); } - return parts; + return List.copyOf(parts); } } diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListener.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListener.java index cf96452b202d..0638788519d0 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListener.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListener.java @@ -19,6 +19,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Clock; +import java.time.ZoneId; import javax.xml.stream.XMLStreamException; @@ -53,7 +54,7 @@ public class LegacyXmlReportGeneratingListener implements TestExecutionListener private @Nullable XmlReportData reportData; public LegacyXmlReportGeneratingListener(Path reportsDir, PrintWriter out) { - this(reportsDir, out, Clock.systemDefaultZone()); + this(reportsDir, out, Clock.system(ZoneId.systemDefault())); } // For tests only diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java index 94c1a128c57e..d0af0bdf8977 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java @@ -149,6 +149,7 @@ private boolean isGitEnabled(ConfigurationParameters config) { return config.getBoolean(GIT_ENABLED_PROPERTY_NAME).orElse(false); } + @SuppressWarnings("EmptyCatch") private void reportInfrastructure(ConfigurationParameters config) { eventsFileWriter.append(infrastructure(), infrastructure -> { try { diff --git a/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Events.java b/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Events.java index 744ff5a3aed3..5755925f4234 100644 --- a/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Events.java +++ b/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Events.java @@ -376,6 +376,7 @@ public Events debug() { * @param out the {@code OutputStream} to print to; never {@code null} * @return this {@code Events} object for method chaining; never {@code null} */ + @SuppressWarnings("DefaultCharset") public Events debug(OutputStream out) { Preconditions.notNull(out, "OutputStream must not be null"); debug(new PrintWriter(out, true)); diff --git a/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Executions.java b/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Executions.java index edfd4311fd67..2e7c3dd3ff32 100644 --- a/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Executions.java +++ b/junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Executions.java @@ -205,6 +205,7 @@ public Executions debug() { * @param out the {@code OutputStream} to print to; never {@code null} * @return this {@code Executions} object for method chaining; never {@code null} */ + @SuppressWarnings("DefaultCharset") public Executions debug(OutputStream out) { Preconditions.notNull(out, "OutputStream must not be null"); debug(new PrintWriter(out, true)); @@ -217,6 +218,7 @@ public Executions debug(OutputStream out) { * @param writer the {@code Writer} to print to; never {@code null} * @return this {@code Executions} object for method chaining; never {@code null} */ + @SuppressWarnings("DefaultCharset") public Executions debug(Writer writer) { Preconditions.notNull(writer, "Writer must not be null"); debug(new PrintWriter(writer, true)); diff --git a/junit-vintage-engine/src/main/java/org/junit/vintage/engine/execution/TestRun.java b/junit-vintage-engine/src/main/java/org/junit/vintage/engine/execution/TestRun.java index c33c0afc7436..9993a73243ec 100644 --- a/junit-vintage-engine/src/main/java/org/junit/vintage/engine/execution/TestRun.java +++ b/junit-vintage-engine/src/main/java/org/junit/vintage/engine/execution/TestRun.java @@ -254,6 +254,7 @@ void add(VintageTestDescriptor descriptor) { * * @param description the {@code Description} to look up */ + @SuppressWarnings("ReferenceEquality") Optional getUnambiguously(Description description) { if (descriptors.isEmpty()) { return Optional.empty(); diff --git a/platform-tests/src/processStarter/java/org/junit/platform/tests/process/WatchedProcess.java b/platform-tests/src/processStarter/java/org/junit/platform/tests/process/WatchedProcess.java index b3a864bce6ff..3a811314ea1f 100644 --- a/platform-tests/src/processStarter/java/org/junit/platform/tests/process/WatchedProcess.java +++ b/platform-tests/src/processStarter/java/org/junit/platform/tests/process/WatchedProcess.java @@ -55,6 +55,7 @@ ProcessResult waitFor() throws InterruptedException { } } + @SuppressWarnings("EmptyCatch") private static void closeQuietly(Optional fileStream) { if (fileStream.isEmpty()) { return; diff --git a/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts b/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts index d2a769977d0c..fd5f6d234763 100644 --- a/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts +++ b/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts @@ -1,6 +1,7 @@ import com.gradle.develocity.agent.gradle.internal.test.TestDistributionConfigurationInternal import junitbuild.extensions.capitalized import junitbuild.extensions.dependencyProject +import net.ltgt.gradle.errorprone.errorprone import org.gradle.api.tasks.PathSensitivity.RELATIVE import org.gradle.kotlin.dsl.support.listFilesOrdered import java.time.Duration @@ -150,6 +151,12 @@ val archUnit by testing.suites.registering(JvmTestSuite::class) { } } +tasks.compileJava { + options.errorprone { + disableAllChecks = true + } +} + tasks.named("checkstyle${archUnit.name.capitalized()}").configure { config = resources.text.fromFile(checkstyle.configDirectory.file("checkstyleTest.xml")) } From b8357c322b721385af7f6c0d9e0b1685a2f3270a Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Thu, 10 Jul 2025 11:39:03 +0200 Subject: [PATCH 2/3] Enable `PackageLocation` check as error --- .../kotlin/junitbuild.java-nullability-conventions.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts index 8b0ec60d8b18..4c95c73d1116 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts @@ -31,6 +31,7 @@ tasks.withType().configureEach { "ImmutableEnumChecker", "MissingSummary" ) + error("PackageLocation") } else { disableAllChecks = true } From 73e3dad4627f5b005a963ebd50ef3239158a2e01 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Thu, 10 Jul 2025 11:49:39 +0200 Subject: [PATCH 3/3] Add explanatory comments for disabled checks --- ...build.java-nullability-conventions.gradle.kts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts index 4c95c73d1116..ddb8f9f67b40 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts @@ -22,14 +22,26 @@ tasks.withType().configureEach { val onJ9 = java.toolchain.implementation.orNull == JvmImplementation.J9 if (name == "compileJava" && !onJ9) { disable( + + // This check is opinionated wrt. which method names it considers unsuitable for import which includes + // a few of our own methods in `ReflectionUtils` etc. "BadImport", + + // The findings of this check are subjective because a named constant can be more readable in many cases "UnnecessaryLambda", + + // Resolving findings for these checks requires ErrorProne's annotations which we don't want to use "AnnotateFormatMethod", - "StringSplitter", "DoNotCallSuggester", "InlineMeSuggester", "ImmutableEnumChecker", - "MissingSummary" + + // Resolving findings for this checks requires using Guava which we don't want to use + "StringSplitter", + + // Produces a lot of findings that we consider to be false positives, for example for package-private + // classes and methods + "MissingSummary", ) error("PackageLocation") } else {