Skip to content

BUILD: Treat every javac and javadoc warning as an error - #240

Draft
jwrosewell wants to merge 2 commits into
rcfrom
build/managed-warnings-as-errors
Draft

jwrosewell wants to merge 2 commits into
rcfrom
build/managed-warnings-as-errors

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Why

javac and javadoc warnings did not fail every build. The package trees turned off the options and try lints, Location had -Werror commented out, and the examples trees had no lint. javadoc ran with <doclint>none</doclint> and <quiet>true</quiet>, so its warnings were neither shown nor fatal. And javac 21 warns that Java 8 is obsolete, so the JDK 21 entries could not build with -Werror.

What changes

  • -Xlint:all and -Werror in pipeline/pom.xml, device-detection/pom.xml, ip-intelligence/pom.xml, location/pom.xml and both examples/*/pom.xml. A release-8 profile compiles against the Java 8 API with --release 8 on JDK 9 and later.
  • CI compiles with JDK 17, found from the entry's runner variable, and runs the tests on the entry's own JDK (8, 11, 17 or 21). The helpers are in ci/packages.ps1, tested in the new ci/java-home.Tests.ps1. The Cloud 51Did and fresh clone workflows compile with JDK 17 too, and the README and contributor guide say to build from source with JDK 17.
  • close() declares no checked exception on Pipeline, FlowData, FlowElement, FlowElementBase, CloseableIterable, CloseableIterableDefault and the iterables of both on-premise engines. A close failure is thrown as the new unchecked CloseException in fiftyone.pipeline.core.exceptions, an InterruptedException sets the interrupt status again, and a Pipeline closes every service even when one throws IOException.
  • javadoc runs with <doclint>all</doclint> and <failOnWarnings>true</failOnWarnings> in the four parent poms, and every public and protected member of the hand-written classes is documented. Three things are left out, each with its reason in the module's pom: the SWIG generated classes of the two on-premise engines, the missing comment check in device-detection.shared and ip-intelligence.shared (whose property accessors are generated), and the owid-java package in pipeline.did.
  • The Doxygen documentation is built from these sources, so @example and @include become \example and \include, and code blocks javadoc read as HTML become <pre>{@code ...}</pre>, checked with Doxygen 1.17.0 and javadoc 17 and 21.
  • 86 classes declare the constructor they had by default, with the same access.
  • The other try and serial warnings are fixed where they were. -endorseddirs leaves the Location servlet example, as javac refuses it with --release.

Before you upgrade

  • A class that overrides one of the close() methods above and declares throws Exception no longer compiles, and has to handle the exception itself. Callers that caught Exception from close() now get the unchecked CloseException.
  • Building from source needs JDK 17. The packages still run on Java 8.

Second commit

  • The examples build with no warning against the published packages, with each Pipeline, FlowData and CloseableIterable closed in a finally block (66 places, item 4 below), and the PMD resource rule accepts that form. The examples READMEs say to build them with JDK 17, as javac 21 refuses the Java 8 source level.
  • The IP Intelligence on-premise engine closes its native weighted value lists through a new useAndClose, as try-with-resources would, and no longer wraps their exceptions in RuntimeException.
  • The pool test closes its first FlowData in a finally block, BinaryWriter's javadoc says it writes to the byte array stream it is given, with a test, and javadoc builds on JDK 11.

At the second commit, on Linux: both examples trees, which failed against the published packages with the try warnings, build with no warning on JDK 17. The whole repository with -Pdev (66 modules, both examples trees, 39 javadoc jars and PMD) builds with no warning on JDK 17 and JDK 11. The pipeline.common and pipeline.core unit tests pass (228), and so do the 4 new useAndClose tests. Not run: JDK 8 and 21 tests, the native, cloud and data file tests, and the workflows on GitHub.

Tests

On Linux x64 with Maven 3.9.16, the native libraries built with gcc and CMake, the free Lite data files, and no keys:

  • mvn clean install -DskipTests -Pdev on JDK 17 builds everything, examples included, with no javac or javadoc warning.
  • javadoc on JDK 21 over those classes passes, 38 runs, with no warning.
  • An undocumented constant, and unknown HTML in a shared module, each fail the build.
  • The unit tests on JDK 8 (2,645, without the Selenium tests) and JDK 11, 17 and 21 (2,660 each): 0 failures and 61 skipped on each. The 4 errors on each are ValueCloudTests in IP Intelligence cloud, which needs a resource key.
  • The CI Pester tests pass, 232 of 232, and so does the environment variable name check.

Before this leaves draft

Not ready to merge until these are done.

  1. The Pull Requests workflow on every entry, with the keys, so the cloud and live tests run.
  2. The SWIG classes get javadoc, which depends on BUILD: Build the native libraries with every warning on and as an error #238 and on whether SWIG is told to write it. The property generator in 51Degrees/tools writes @return on the generated accessors, so the all,-missing settings can go. owid-java fixes its javadoc, so pipeline.did can include that package again.
  3. Each build still logs "Error fetching link" for pipeline/pipeline.aggregate, which has no sources.
  4. The examples now close each Pipeline, FlowData and CloseableIterable in a finally block in place of try-with-resources, in 66 places, so they build with no warning against the published 4.5.130 packages, whose close() still declares Exception. The documentation teaches try-with-resources, and with a finally block an exception from close() replaces one from the body, so a decision is needed before this merges: keep these finally blocks, or keep try-with-resources and build the examples against this tree's packages until a release with the new close() is published, then move them back.

Every package tree and both examples trees compile with -Xlint:all and
-Werror. The options and try lints were off in the package trees,
Location had -Werror commented out, and the examples trees had no lint.
The packages keep Java 8, with --release 8 on JDK 9 and later. javac 21
warns that Java 8 is obsolete and javac 17 does not, so CI compiles with
JDK 17 and still runs the tests on the JDK each entry names, 8, 11, 17
or 21.

Most try lint warnings came from close() throws Exception on Pipeline,
FlowData and FlowElement. close() on those interfaces, FlowElementBase,
CloseableIterable and the on-premise engines' iterables now declares no
checked exception. A close failure is thrown as the new unchecked
CloseException in fiftyone.pipeline.core.exceptions, an interrupt is
kept, and a Pipeline closes every service even when one throws
IOException.

javadoc runs every doclint check and fails the build on any warning,
and every public and protected member of the hand-written classes is
documented. The SWIG classes, the generated property accessors'
missing comments, and the owid-java package are left out, each with its
reason in the module's pom. The Doxygen @example and @include commands
become \example and \include, and code blocks javadoc read as HTML
become <pre>{@code ...}</pre>. 86 classes declare the constructor they
had by default, with the same access.
The examples build by default against the 4.5.130 packages on Maven
Central, where close() still declares Exception. javac's try lint then
warned at every try-with-resources of a Pipeline, a FlowData or a
CloseableIterable, and -Werror stopped the build. In 66 places in both
examples trees each one is now a local variable closed in a finally
block, and the PMD resource rule accepts that form. The examples READMEs
say to build them with JDK 17, as javac 21 refuses the Java 8 source
level.

The IP Intelligence engine closes its native weighted value lists
through a new useAndClose helper, as try-with-resources would, and no
longer wraps their exceptions in RuntimeException. The pool test closes
its first FlowData in a finally block, BinaryWriter's javadoc says which
stream it writes to, and javadoc now builds on JDK 11.
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