[sdk] Treat Java SDK compiler warnings as build errors#2200
Open
iwahbe wants to merge 3 commits into
Open
Conversation
Add `-Xlint:all -Werror` to all `JavaCompile` tasks and `-Werror` to the javadoc task in the Java SDK build. Also exclude the proto-generated `codegen` package from javadoc, matching the existing `pulumirpc` exclusion, so generated stubs do not contribute spurious warnings. This intentionally fails CI until the underlying warnings are fixed.
Address the unchecked, rawtypes, serial, varargs, cast, and try warnings surfaced by `-Xlint:all -Werror` on the Java SDK build, both in the main sources and in the test sources. The changes are scoped to internal implementation: method bodies, local variables, `serialVersionUID` fields on exception types, and tightly scoped `@SuppressWarnings` annotations on the lines (or methods) where casts are genuinely unavoidable under type erasure. No public method signatures change. Also drops the unsupported javadoc `-Werror` option that JDK 11's javadoc rejects, and excludes the proto-generated `codegen` package from javadoc to match the existing `pulumirpc` exclusion.
JDK 11's javadoc does not support `-Werror`; the flag was added in JDK 17. Configure the `javadoc` task to run under a JDK 17 toolchain so we can use it, while compilation continues to target JDK 11. - `build.gradle` (javadoc task): set `javadocTool` via `javaToolchains.javadocToolFor`, enable `-Werror`, and apply `-Xdoclint:all,-missing` so the build fails on real javadoc problems (broken HTML, bad `@link` references, syntax errors) while tolerating pre-existing methods that lack `@param`/`@return` tags. Fixing those is tracked separately. - `ci.yml`: have `actions/setup-java` provision both JDK 11 (default JAVA_HOME, used for compilation) and JDK 17 (picked up by Gradle's toolchain detection for the javadoc task). - `.mise.toml`: install both JDKs for local development. Also fix the seven real javadoc warnings that the new -Werror surfaced: empty `<p>` tags in `Mocks`, `StackOptions`, `StackReference`, and `StackReferenceOutputDetails`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Configures the Java SDK Gradle build to treat compiler warnings as errors (
-Xlint:all -Werroron allJavaCompiletasks) and addresses every pre-existing warning so CI compiles cleanly.Build configuration change
tasks.withType(JavaCompile).configureEach { options.compilerArgs.addAll(['-Xlint:all', '-Werror']) }— applies to both main and test compilation.codegenpackage from javadoc, matching the existingpulumirpcexclusion.Source changes
Resolves the warnings that
-Werrorthen surfaces:private static final long serialVersionUID = 1Lto ~14 exception classes (e.g.RunException,ResourceException, automation exceptions,KeyMissingException, nestedInvokeException/CallException/etc.).@SuppressWarnings(\"varargs\")alongside@SafeVarargson methods likeOutput.all,Output.ofList,ResourceOptions.Builder.aliases. JDK 11's@SafeVarargsonly suppresses the declaration-site warning; the call-site use of the non-reifiable array needs the additional suppression.@SuppressWarnings(\"try\")to AutoCloseable classes/methods whoseclose()may throwInterruptedException(Workspace, WorkspaceStack, EventLogWatcher, LocalWorkspace, LocalPulumiCommand) and toContextAwareCompletableFutureandInstrumentationwhich deliberately use try-with-resources for context-scoped side effects.new CompletableFuture<?>[0],new OutputInternal<>(...), etc. inCompletableFutures,DeploymentImpl,PropertyValueSerializer.PropertyValueSerializerandPropertyValueSerializerTest.@SuppressWarnings(\"unchecked\")via local-variable declarations on each genuinely unavoidable type-erasure cast (e.g. insideConverter,Serializer,Deserializer,OutputData, theImportMetadata/ExportMetadatareflection paths,Output.ensureOutput,Left/Right.flatMap,TypeShape.getType,MockMonitor.serializeToMap). Class-level suppression only used in the one case where the entireBuilderpattern is(B) this(ResourceOptions.Builder— 21 identical casts).No public method signatures change — only method bodies, locals, and annotations.
Test plan
gradle assemble— passes (was the failure case before).gradle build— passes with 0 javac warnings.gradle testAll— passes locally.