Skip to content

[sdk] Treat Java SDK compiler warnings as build errors#2200

Open
iwahbe wants to merge 3 commits into
mainfrom
iwahbe/no-warnings
Open

[sdk] Treat Java SDK compiler warnings as build errors#2200
iwahbe wants to merge 3 commits into
mainfrom
iwahbe/no-warnings

Conversation

@iwahbe
Copy link
Copy Markdown
Member

@iwahbe iwahbe commented May 20, 2026

Summary

Configures the Java SDK Gradle build to treat compiler warnings as errors (-Xlint:all -Werror on all JavaCompile tasks) 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.
  • Excludes the proto-generated codegen package from javadoc, matching the existing pulumirpc exclusion.

Source changes

Resolves the warnings that -Werror then surfaces:

  • serial: add private static final long serialVersionUID = 1L to ~14 exception classes (e.g. RunException, ResourceException, automation exceptions, KeyMissingException, nested InvokeException/CallException/etc.).
  • varargs: add @SuppressWarnings(\"varargs\") alongside @SafeVarargs on methods like Output.all, Output.ofList, ResourceOptions.Builder.aliases. JDK 11's @SafeVarargs only suppresses the declaration-site warning; the call-site use of the non-reifiable array needs the additional suppression.
  • try: add @SuppressWarnings(\"try\") to AutoCloseable classes/methods whose close() may throw InterruptedException (Workspace, WorkspaceStack, EventLogWatcher, LocalWorkspace, LocalPulumiCommand) and to ContextAwareCompletableFuture and Instrumentation which deliberately use try-with-resources for context-scoped side effects.
  • rawtypes: parameterize new CompletableFuture<?>[0], new OutputInternal<>(...), etc. in CompletableFutures, DeploymentImpl, PropertyValueSerializer.
  • cast: drop the redundant casts in PropertyValueSerializer and PropertyValueSerializerTest.
  • unchecked: add line-scoped @SuppressWarnings(\"unchecked\") via local-variable declarations on each genuinely unavoidable type-erasure cast (e.g. inside Converter, Serializer, Deserializer, OutputData, the ImportMetadata/ExportMetadata reflection paths, Output.ensureOutput, Left/Right.flatMap, TypeShape.getType, MockMonitor.serializeToMap). Class-level suppression only used in the one case where the entire Builder pattern 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.
  • CI `prerequisites` (`gradle assemble`) passes.
  • CI `java-sdk-tests` compile passes; the remaining failure (`LocalWorkspaceTest.testStateDeleteForce` timeout) reproduces on `main` and is unrelated to this PR.

iwahbe added 2 commits May 20, 2026 11:08
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.
@iwahbe iwahbe marked this pull request as ready for review May 20, 2026 10:28
@iwahbe iwahbe requested a review from a team as a code owner May 20, 2026 10:28
@iwahbe iwahbe changed the title [sdk] Fail Java SDK build on warnings [sdk] Treat Java SDK compiler warnings as build errors May 20, 2026
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`.
@iwahbe iwahbe enabled auto-merge (squash) May 20, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant