Skip to content

build: Enforce Java 8 API floor on presto-spark module closure#27785

Open
kevintang2022 wants to merge 1 commit into
prestodb:masterfrom
kevintang2022:export-D104913960
Open

build: Enforce Java 8 API floor on presto-spark module closure#27785
kevintang2022 wants to merge 1 commit into
prestodb:masterfrom
kevintang2022:export-D104913960

Conversation

@kevintang2022
Copy link
Copy Markdown
Contributor

@kevintang2022 kevintang2022 commented May 13, 2026

Summary:

Description

Adds animal-sniffer-maven-plugin to presto-spark and the modules it transitively depends on, configured against the Java 8 signature DB. The plugin scans bytecode at the process-classes phase and fails the build on references to JDK APIs that do not exist in Java 8.

Also fixes one pre-existing leak surfaced by the new check: TimestampOperators.java:140 was calling Math.floorDiv(long, int) (added in Java 9). Cast the second argument to long to use the Java 8 (long, long) overload.

Motivation and Context

presto-spark is consumed by Apache Spark 2.x deployments, which require Java 8. There is no compile-time enforcement of this floor today: <project.build.targetJdk>8</project.build.targetJdk> in the affected modules is a hint read by maven-pmd-plugin, not by javac, and <air.check.skip-modernizer>true</air.check.skip-modernizer> disables the only existing related check. As a result, contributors can introduce Java 9+ APIs (e.g. Optional.or(Supplier), Math.floorDiv(long, int), Stream.toList()) that compile and pass tests on the Java 17 CI matrix but throw NoSuchMethodError at runtime on a Java 8 driver/executor.

Impact

  • No public API changes.
  • New process-classes check fails the build on Java 9+ API references in opted-in modules.
  • Polymorphic-signature MethodHandle.invoke/invokeExact calls are globally ignored — animal-sniffer cannot statically resolve them, and they are not real violations.

Differential Revision: D104913960

Release Notes

== NO RELEASE NOTE ==

@kevintang2022 kevintang2022 requested review from a team, elharo and shrinidhijoshi as code owners May 13, 2026 00:14
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label May 13, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 13, 2026

Reviewer's Guide

Adds an Animal Sniffer–based Java 8 API compatibility check for presto-spark and its dependency closure, and fixes a single Java 9-only Math.floorDiv call to use the Java 8 overload instead.

File-Level Changes

Change Details Files
Introduce a centrally configured Animal Sniffer Java 8 API check and bind it into the build lifecycle.
  • Add animal-sniffer-maven-plugin to the root pom with Java 8 signature configuration.
  • Configure the plugin to run the check goal in the process-classes phase via a dedicated execution.
  • Ignore java.lang.invoke.MethodHandle in the plugin configuration to avoid false positives on polymorphic signatures.
pom.xml
Opt presto-spark and its transitive dependency modules into the Java 8 API check.
  • Add a minimal animal-sniffer-maven-plugin reference under for a set of core modules used by presto-spark (analyzer, common, expressions, internal-communication, matching, memory-context, plugin-toolkit, spark-classloader-interface, spark-classloader-spark2, spark-common, spi, bytecode, client, geospatial-toolkit, main-base, parser, spark-base, spark-launcher, presto-spark).
  • Ensure these modules now inherit and run the centrally defined Java 8 signature check during Maven builds.
presto-analyzer/pom.xml
presto-common/pom.xml
presto-expressions/pom.xml
presto-internal-communication/pom.xml
presto-matching/pom.xml
presto-memory-context/pom.xml
presto-plugin-toolkit/pom.xml
presto-spark-classloader-interface/pom.xml
presto-spark-classloader-spark2/pom.xml
presto-spark-common/pom.xml
presto-spi/pom.xml
presto-bytecode/pom.xml
presto-client/pom.xml
presto-geospatial-toolkit/pom.xml
presto-main-base/pom.xml
presto-parser/pom.xml
presto-spark-base/pom.xml
presto-spark-launcher/pom.xml
presto-spark/pom.xml
Fix a Java 9-only Math.floorDiv overload usage to be Java 8 compatible.
  • Change Math.floorDiv call to use the (long, long) overload by casting the constant divisor from int to long to avoid using the Java 9-only (long, int) overload.
presto-main-base/src/main/java/com/facebook/presto/type/TimestampOperators.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

jja725
jja725 previously approved these changes May 13, 2026
Copy link
Copy Markdown
Contributor

@jja725 jja725 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this compile time check

Comment thread pom.xml Outdated

<!--
Modules consumed by presto-spark must remain runnable on a Java 8 JVM
(Sapphire / Presto-on-Spark 2.x runs Spark 2.4 driver and executors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sapphire seems to be meta specific so should not in OSS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i will remove the comments

Summary:

Adds `animal-sniffer-maven-plugin` to `presto-spark` and the modules it transitively depends on, configured against the Java 8 signature DB. The plugin scans bytecode at the `process-classes` phase and fails the build on references to JDK APIs that do not exist in Java 8.

Also fixes one pre-existing leak surfaced by the new check: `TimestampOperators.java:140` was calling `Math.floorDiv(long, int)` (added in Java 9). Cast the second argument to `long` to use the Java 8 `(long, long)` overload.

`presto-spark` is consumed by Apache Spark 2.x deployments, which require Java 8. There is no compile-time enforcement of this floor today: `<project.build.targetJdk>8</project.build.targetJdk>` in the affected modules is a hint read by maven-pmd-plugin, not by `javac`, and `<air.check.skip-modernizer>true</air.check.skip-modernizer>` disables the only existing related check. As a result, contributors can introduce Java 9+ APIs (e.g. `Optional.or(Supplier)`, `Math.floorDiv(long, int)`, `Stream.toList()`) that compile and pass tests on the Java 17 CI matrix but throw `NoSuchMethodError` at runtime on a Java 8 driver/executor.

- No public API changes.
- New `process-classes` check fails the build on Java 9+ API references in opted-in modules.
- Polymorphic-signature `MethodHandle.invoke`/`invokeExact` calls are globally ignored — animal-sniffer cannot statically resolve them, and they are not real violations.

Differential Revision: D104913960
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants