# Java API Compliance Checker

A tool for checking backward API/ABI compatibility of a Java library

Java API Compliance Checker (JAPICC) is a tool for checking backward binary and source-level compatibility of a Java library API. The tool checks classes declarations of old and new versions and analyzes changes that may break compatibility: removed methods, removed class fields, added abstract methods, etc. The HTML compatibility report generated by this tool includes separate sections for both source and binary compatibility analysis and exact error messages of the jvm and the compiler for each break found in the API.

Binary incompatibility may result in crashing or incorrect behavior of existing clients built with an old version of a library when they are running with a new one. Source incompatibility may result in recompilation errors with a new library version. The tool is intended for developers of software libraries and Linux maintainers who are interested in ensuring backward compatibility, i.e. allow old clients to run or to be recompiled with newer library versions.

The Scala language is supported since 1.7 version of the tool.

The tool is a core of the Java API Tracker project.

Table of Contents Downloads License Supported Platforms Dependencies Installation Usage Adv. Usage (Multiple Archives) Examples Detectable Compatibility Problems Test Suite API Dumps Report Format Verdict on Compatibility Error Codes Similar Tools Bugs Maintainers Changes Articles

## Downloads

The latest release can be downloaded from this page.

Read-only access to the latest development version:

`git clone https://github.com/lvc/japi-compliance-checker.git`

## License

This program is free software. You may use, redistribute and/or modify it under the terms of the GNU GPL or GNU LGPL

## Supported Platforms

GNU/Linux, FreeBSD, Mac OS X, MS Windows.

## Dependencies

- JDK or OpenJDK - development files (javap, javac)
- Perl 5

## Installation

The tool is ready-to-use after extracting the archive.

You can also use a Makefile to install the tool into the system:

`cd japi-compliance-checker-x.y.z/`

`sudo make install prefix=PREFIX [/usr, /usr/local, ...]`

This command will install the `japi-compliance-checker` program into the `PREFIX/bin` system directory and private modules into the `PREFIX/share`.

To verify that the tool is installed correctly and it works on your host run:

`cd tmp/`

`japi-compliance-checker -test`

## Usage

Use the following command to compare two Java archives:

`japi-compliance-checker -lib NAME V1.jar V2.jar`

The compatibility report will be generated to:

`compat_reports/NAME/V1_to_V2/compat_report.html`

## Usage (Multiple Archives)

To compare different versions of a library that consists of many JARs you should create XML descriptors for two library versions: v1.xml and v2.xml files. Library descriptor is a simple XML-file that specifies version number, paths to Java archives and other optional information. An example of the descriptor is the following:

    <version>
        1.0
    </version>

    <archives>
        /path1/to/JAR(s)/
        /path2/to/JAR(s)/
           ...
    </archives>

Command to compare two versions of a library:

`japi-compliance-checker -lib NAME -old V1.xml -new V2.xml`

The compatibility report will be generated to:

`compat_reports/NAME/V1_to_V2/compat_report.html`

## Examples

Library | Versions | Report
--- | --- | ---
Guava | 18.0 vs 19.0 | report
SLF4J | 1.5.11 vs 1.6.0 | report
ICU4J | 56_1 vs 57_1 | report

See more report examples at https://abi-laboratory.pro/java/tracker/.

## Detectable Compatibility Problems

The tool searches for the following list of changes in the API that may break binary/source-level compatibility. See “Evolving Java-based APIs: Achieving API Binary Compatibility” for more info.

- Problems with Data Types
  - Classes and Interfaces
    - removed classes or interfaces
    - removed fields
    - removed methods
    - change of a field type
    - change of a field access level
    - change of a field attributes (final, static, etc.)
    - change of a constant field value
    - changes in fields (recursive analysis)
    - added/removed abstract methods
    - added/removed super-interfaces
  - Classes
    - added/removed super-classes
    - moving a method up class hierarchy
    - overridden methods
- Problems with Methods
  - changed attributes (static, final, synchronized, abstract, etc.)
  - changed access level
  - added/removed exceptions
- Problems with Annotations
  - removed annotations

## Test Suite

The tool is tested properly in the Java API Tracker project, by the community and by the internal test suite:

`japi-compliance-checker -test`

There are about 80 basic tests in the test suite.

## API Dumps

The API dump is a dump of the API model used in the tool. You can create API dump by the `-dump` option and use it instead of the Java archive.

The API dump consists of:

- Types Information
  - Attributes (name, package, access, base types, etc.)
  - Fields (name, type, access, specifiers, etc.)
  - Etc.
- Symbols Information
  - Attributes (name, mangled name, package, access, specifiers, etc.)
  - Parameters (name, type, position, etc.)
  - Etc.
- Etc.

To create an API dump use `-dump` option:

`japi-compliance-checker -lib NAME -dump LIB.jar -dump-path ./API.dump`

To compare API dumps pass them instead Java archives:

`japi-compliance-checker -lib NAME -old API-0.dump -new API-1.dump`

## Report Format

The HTML-format compatibility report consists of:

- Test Info - The library name and compared version numbers.
- Test Results - Verdict on compatibility. Number of archives, classes and methods checked by the tool.
- Problem Summary - Classification of compatibility problems.
- Added Methods - The list of added methods.
- Removed Methods - The list of removed methods.
- Problems with Data Types - List of compatibility problems caused by changes in data types (divided by the severity level: High, Medium, Low). List of affected methods.
- Problems with Methods - The list of compatibility problems caused by changes in method parameters and attributes (divided by the severity level).
- Other Changes in Data Types - The list of compatible changes in data types.
- Other Changes in Methods - The list of compatible changes in methods.

## Verdict on Compatibility

If the tool detected problems with high or medium level of severity or at least one removed method then the compatibility verdict is incompatible (otherwise compatible). Low-severity problems can be considered as warnings and don't affect the compatibility verdict unless the `-strict` option is specified.

## Error Codes

Code | Meaning
--- | ---
0 | Compatible. The tool has run without any errors.
1 | Incompatible. The tool has run without any errors.
2 | Common error code (undifferentiated).
3 | A system command is not found.
4 | Cannot access input files.
7 | Invalid input API dump.
8 | Unsupported version of input API dump.
9 | Cannot find a module.

## Similar Tools

- Clirr - checks Java libraries for binary and source compatibility with older releases
- Revapi - API analysis and change tracking tool
- Japicmp - a tool to compare two versions of a jar archive
- Japitools - test for compatibility between Java APIs
- Jour - Java API compatibility testing tools
- Japi-checker - a java API backward compatibility checker which works at binary level
- SigTest - Oracle's SigTest signature testing and API conformance tool

## Bugs

Please post bug reports, feature requests and questions to the issue tracker.

## Maintainers

The tool is developed by Andrey Ponomarenko.

## Changes

You can find changelog here.

## Articles

- “Evolving Java-based APIs: Achieving API Binary Compatibility”, Jim des Rivières
- “Binary Compatibility”, Java Language Specification
- “Kinds of Compatibility: Source, Binary, and Behavioral”, Joseph D. Darcy's Oracle Weblog