Skip to content

Detect and prevent PublicApi leakage#35972

Open
gjoranv wants to merge 4 commits intomasterfrom
detect-PublicApi-leakage
Open

Detect and prevent PublicApi leakage#35972
gjoranv wants to merge 4 commits intomasterfrom
detect-PublicApi-leakage

Conversation

@gjoranv
Copy link
Member

@gjoranv gjoranv commented Feb 19, 2026

Summary

  • Add leakagecheck goal to abi-check-plugin that detects when @PublicApi classes expose types from non-@PublicApi packages in their public signatures
  • Scan module JAR and all dependency JARs (including provided scope) to build the full @PublicApi package set
  • Extract referenced types from method signatures, fields, supertypes, and generic type parameters using ASM
  • Compare detected leakages against leakage-spec.json (same pattern as abi-spec.json); fail on new leakages and stale entries
  • Grandfather existing leakages in 16 modules via checked-in leakage-spec.json files
  • Existing leakages are tracked in a per-module spec file rather than annotated in source code, because the leakage is a property of the module's public API surface rather than the individual class, and a single file gives a better overview when the number of leakages is large
  • Leakage of third party packages will be solved in a later PR.

Test plan

  • mvn test -f abi-check-plugin/pom.xml passes (30 tests)
  • Full build passes: mvn package -DskipTests --threads 1C
  • Introducing a deliberate leakage fails the build with clear error message
  • Verify stale entries scenario end-to-end

LeakageSignatureCollector is an ASM ClassVisitor that collects all types
referenced in the public API surface of public classes: superclass,
interfaces, method signatures, field types, thrown exceptions, and
generic type parameters.

TypeCollectorSignatureVisitor is an ASM SignatureVisitor that extracts
class types from generic type signatures (e.g. List<InternalType>),
catching leakages that would be invisible from erased descriptors alone.
New Maven goal 'leakagecheck' that detects when @publicapi classes
expose types from non-@publicapi packages in their public signatures.

The mojo scans all dependency JARs to build the full @publicapi package
set, then checks each public class in @publicapi packages for references
to Vespa types (com.yahoo.*, ai.vespa.*) that are not in @publicapi
packages. Detected leakages are compared against a leakage-spec.json
file; both new leakages and stale spec entries fail the build.

Use -Dleakage.writeSpec to generate or update the spec file.
Add the leakagecheck execution alongside the existing abicheck execution
in the abi-check-plugin configuration. Both goals share the same
publicApiAnnotation configuration and run at the package phase.
Generated by running `mvn package -Dleakage.writeSpec` across all
modules. These spec files grandfather existing leakages so the build
can enforce that no new leakages are introduced going forward.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new leakagecheck goal in the abi-check-plugin to detect and prevent @PublicApi classes from exposing types from non-@PublicApi packages in their public signatures. The check scans the module JAR and all dependencies to build a complete set of @PublicApi packages, then uses ASM to extract referenced types from method signatures, fields, supertypes, and generic type parameters. Detected leakages are compared against per-module leakage-spec.json files (following the same pattern as abi-spec.json), and the build fails on new leakages or stale entries.

Changes:

  • Added leakagecheck goal to the Maven build lifecycle in parent/pom.xml
  • Implemented LeakageChecker mojo and LeakageSignatureCollector for detecting API leakages
  • Grandfathered existing leakages in 16 modules via checked-in leakage-spec.json files

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
parent/pom.xml Adds leakagecheck execution to the abi-check-plugin configuration
abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/LeakageChecker.java Main mojo implementation for detecting and validating PublicApi leakages
abi-check-plugin/src/main/java/com/yahoo/abicheck/collector/LeakageSignatureCollector.java ASM visitor that collects types from public API surfaces
abi-check-plugin/src/main/java/com/yahoo/abicheck/collector/TypeCollectorSignatureVisitor.java ASM signature visitor for extracting generic type parameters
abi-check-plugin/src/test/java/com/yahoo/abicheck/mojo/LeakageCheckerTest.java Unit tests for leakage filtering and comparison logic
abi-check-plugin/src/test/java/com/yahoo/abicheck/LeakageSignatureCollectorTest.java Unit tests for type collection from class files
*/leakage-spec.json (16 files) Per-module specification files documenting grandfathered API leakages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gjoranv gjoranv requested review from bjorncs and hmusum February 19, 2026 18:39
Copy link
Member

@hmusum hmusum left a comment

Choose a reason for hiding this comment

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

Nice

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.

2 participants

Comments