# Java API Compliance Checker

Java API Compliance Checker (Java ACC) 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 include 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 maintainers of operating system who are interested in ensuring backward compatibility, i.e. allow old clients to run or to be recompiled with newer library versions.

See also:

- Upstream Tracker
- PkgDiff

## Downloads

The tool can be downloaded from github.com.

## License

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

## Supported Platforms

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

## System Requirements

- Linux, FreeBSD, Mac OS X
  - JDK (javap, javac)
  - Perl 5 (5.8 or newer)

- MS Windows
  - JDK (javap, javac)
  - Active Perl 5 (5.8 or newer)

## Detectable Compatibility Problems

The tool searches for the following list of changes in the API that may break binary/source-level compatibility. See this list of articles 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

You can see detailed problem descriptions in the visual interactive HTML-format compatibility report (see this example) generated by the tool.

## Limitations

The tool cannot check compatibility problems related to changes in code annotations.

## 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 perl Makefile.pl -install --prefix=PREFIX [/usr, /usr/local, ...]`

This command will install a `japi-compliance-checker` program in the `PREFIX/bin` system directory.

To verify that the tool is installed correctly and it works on your host run:
`cd tmp/`
`japi-compliance-checker -test`

## Usage

### Compare Java ARchives

Command to compare two java archives:
`japi-compliance-checker V1.jar V2.jar`

The compatibility report will be generated to:
`compat_reports/NAME/V1_to_V2/compat_report.html`

### Compare Libraries

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 (1.0.xml):

     <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`

### Check Clients Portability

Command to check a client portability to a newer version of a Java library API:
`japi-compliance-checker -lib NAME -old V1.xml -new V2.xml -client CLIENT.jar`

### Dump Library API to TXT file

Command to dump a Java library API to gzipped TXT format file:
`japi-compliance-checker -lib NAME -dump VER.xml`
The API dump will be generated to:
`api_dumps/NAME/NAME_VER.api.tar.gz`

### Command-Line Options

See the list of all options on this page.

### Examples

Check the JDO library API versions for compatibility:
`japi-compliance-checker jdo-api-2.0.jar jdo-api-3.0.jar`
The report will be generated to:
`compat_reports/jdo/2.0_to_3.0/compat_report.html`
Dump library API:
`japi-compliance-checker -l jdo -dump jdo-api-2.0.jar`
The API dump will be generated to:
`api_dumps/jdo/jdo_2.0.api.tar.gz`
Check client application portability between JDO versions:
`japi-compliance-checker -l jdo -old jdo-api-2.0.jar -new jdo-api-3.0.jar -client Teller.jar`

## Report Format

The HTML-format compatibility report consists of:

- Test Info - The library name and compared version numbers.
- Summary - 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;

Examples of HTML-format report:

- JDO: 2.2 to 3.0 API compatibility report
- SLF4J: 1.5.11 to 1.6.0 binary compatibility report
- Struts: 2.1.6 to 2.1.8 source compatibility report

## 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

1. SigTest - Oracle's SigTest signature testing and API conformance tool
2. Clirr - checks Java libraries for binary and source compatibility with older releases
3. Japitools - test for compatibility between Java APIs
4. Jour - Java API compatibility testing tools
5. Japi-checker - a java API backward compatibility checker which works at binary level

## Bugs

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

## Maintainers

The tool is developed by Andrey Ponomarenko.

## Articles

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