Lab 02 — API Compatibility Checker

What You'll Build

A diffing engine that compares two API snapshots (sets of MethodSignature) and classifies each change as REMOVED, ADDED, or MODIFIED — then reports which changes are binary-breaking.

Concepts

Change typeBinary-breaking?Explanation
REMOVEDYesCallers compiled against the old API get NoSuchMethodError at runtime
MODIFIED (return type changed)YesThe JVM encodes return type in the method descriptor
ADDEDNoCallers compiled against the old API still link correctly

This is exactly what japicmp does — this lab reimplements the core classification logic from scratch.

Running

mvn test

Expected: 9 tests, 0 failures.

Key Classes

ClassRole
MethodSignatureclassName + methodName + returnType + parameterTypes; methodKey() is the identity key
ChangeTypeEnum: REMOVED, ADDED, MODIFIED
CompatibilityIssueOne change: method + changeType + isBinaryBreaking()
CompatibilityReportAggregated result with helpers for binary-breaking issues vs. compatible additions
ApiCompatibilityCheckercheck(oldApi, newApi) — the diffing algorithm

Algorithm

  1. Build Map<methodKey, MethodSignature> for each snapshot.
  2. Key in old, absent in new → REMOVED.
  3. Key in both, return type differs → MODIFIED.
  4. Key in new, absent in old → ADDED.

Interview Angle

Explain why method return type is part of the JVM method descriptor (§4.3.3 of the JVM spec), and why changing it is binary-breaking even though Java source code only cares about the method name and parameter types.