From be713639fdb6d3788c1c0d2f913d509f31e50d44 Mon Sep 17 00:00:00 2001 From: Nicholas Lativy Date: Sun, 26 Apr 2026 23:19:54 +0100 Subject: [PATCH] Treat compile warnings as errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that the previous PRs cleared the long tail of error-prone and javadoc warnings, turn on the strict gates so any future regression breaks the build instead of being a silently ignored log line. - maven-compiler-plugin: true - maven-javadoc-plugin: true To get to a clean build first: - Add @SuppressWarnings("unused") on five test fixtures whose unused-ness is the whole point (an injection that should fail before the field is read; a non-zero-arg constructor that exists just so the test can verify a useful error message; a method parameter that exists so the method gets filtered out as ineligible; etc.). Each annotation has a one-line comment explaining why. - Refactor testWrapperExceptionPropagated so only the throwing call sits inside the assertThrows lambda — appeases AssertThrowsMinimizer, which the previous PR introduced. - Tell error-prone to skip generated sources via -XepExcludedPaths. AutoValue's generated equals() uses pre- pattern-matching instanceof, which we can't fix and shouldn't fail builds over. --- pom.xml | 6 +++- src/test/java/com/google/acai/AcaiTest.java | 4 +++ .../GuiceberryCompatibilityModuleTest.java | 28 +++++++++---------- .../java/com/google/acai/TestScopeTest.java | 1 + .../acai/TestingServiceManagerTest.java | 1 + 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index d65f4b3..41cbeb7 100644 --- a/pom.xml +++ b/pom.xml @@ -59,10 +59,11 @@ 3.14.0 26 + true -XDcompilePolicy=simple --should-stop=ifError=FLOW - -Xplugin:ErrorProne + -Xplugin:ErrorProne -XepExcludedPaths:.*/target/generated-(test-)?sources/.* @@ -95,6 +96,9 @@ org.apache.maven.plugins maven-javadoc-plugin 3.12.0 + + true + attach-javadocs diff --git a/src/test/java/com/google/acai/AcaiTest.java b/src/test/java/com/google/acai/AcaiTest.java index 5b161ca..fb9699f 100644 --- a/src/test/java/com/google/acai/AcaiTest.java +++ b/src/test/java/com/google/acai/AcaiTest.java @@ -313,6 +313,7 @@ MethodCalls incrementAfterTest() { } private static class TestWithUnsatisfiedBinding { + @SuppressWarnings("unused") // Fixture: injection should fail before this is read. @Inject @TestBindingAnnotation ExampleTest unsatisfiedBinding; } @@ -342,6 +343,8 @@ protected void configureTestingServices() { } } + // Fixture: existence of the non-zero-arg constructor is what the test verifies. + @SuppressWarnings("unused") private static class ModuleWithoutZeroArgumentConstructor extends AbstractModule { ModuleWithoutZeroArgumentConstructor(String argument) { // No-op. @@ -381,6 +384,7 @@ String provideValueAndAddTearDown(TearDownAccepter tearDownAccepter) { } private static class TearDownAccepterTest { + @SuppressWarnings("unused") // Forces @Provides to fire so the teardown is registered. @Inject @TestBindingAnnotation String injected; } diff --git a/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java b/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java index 9b99cc4..5db591f 100644 --- a/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java +++ b/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java @@ -131,21 +131,19 @@ public void evaluate() { @Test public void testWrapperExceptionPropagated() { FakeTestClass test = new FakeTestClass(); - - assertThrows( - TestException.class, - () -> - new Acai(ThrowingWrapperModule.class) - .apply( - new Statement() { - @Override - public void evaluate() { - assertWithMessage("Test should not run when TestWrapper throws").fail(); - } - }, - frameworkMethod, - test) - .evaluate()); + Statement statement = + new Acai(ThrowingWrapperModule.class) + .apply( + new Statement() { + @Override + public void evaluate() { + assertWithMessage("Test should not run when TestWrapper throws").fail(); + } + }, + frameworkMethod, + test); + + assertThrows(TestException.class, statement::evaluate); } private static class FakeTestClass { diff --git a/src/test/java/com/google/acai/TestScopeTest.java b/src/test/java/com/google/acai/TestScopeTest.java index 6b490e5..ac69559 100644 --- a/src/test/java/com/google/acai/TestScopeTest.java +++ b/src/test/java/com/google/acai/TestScopeTest.java @@ -253,6 +253,7 @@ private static class FakeTestClassWithProvider { private static class MyTestScopedClass {} private static class InvalidTestingService implements TestingService { + @SuppressWarnings("unused") // Fixture: @TestScoped injected into a TestingService is rejected. @Inject MyTestScopedClass testScoped; } diff --git a/src/test/java/com/google/acai/TestingServiceManagerTest.java b/src/test/java/com/google/acai/TestingServiceManagerTest.java index 6b10b7f..3a11624 100644 --- a/src/test/java/com/google/acai/TestingServiceManagerTest.java +++ b/src/test/java/com/google/acai/TestingServiceManagerTest.java @@ -150,6 +150,7 @@ private void incrementPrivateBeforeTestCount() { } @BeforeTest + @SuppressWarnings("unused") // Parameter is the whole point: makes the method ineligible. private void incrementBeforeTestWithParameterCount(int someParameter) { beforeTestWithParameterCount++; }