This is a backport to JDK 17 of the new classfile API found in JDK 21 and later.
Bugs in this project should be reported to the GitHub issue tracker first. Bugs in this project are likely to be a result of backporting. Some bugs might be relayed upstream by the project maintainer(s), subject to testing and verification; in this case, the upstream bug will be linked for easier tracking.
Releases of the project roughly track releases of the corresponding JDK from which it is backported. This means that version 24.x of this project corresponds to the state of the upstream classfile API in JDK 24, and so on.
Binary compatibility is maintained with a strictness corresponding to that of the upstream API.
It is currently planned to continue to backport features indefinitely. The major version of this project will continue to correspond to the JDK from which the changes were backported. When planning a transition from this library to the official API, be sure that the major version of this library corresponds to the target JDK to avoid a situation where you start using features which are not available in the JDK version you want to target, causing difficulties when migrating.
The release schedule is fairly ad-hoc and irregular, but will generally align with that of the upstream JDK. If you encounter a bug which has been fixed in this project but not yet released, feel free to open an issue to request a release.
After adding the appropriate Maven dependency (see the Maven release badge above), the easiest entry points are:
For parsing a class:
byte[] b = Files.readAllBytes(Path.of("some/file.class"));
ClassModel model = ClassFile.of().parse(b);
// now, do something with `model`...
Or for writing a class:
byte[] b = ClassFile.of().build(classDesc, classBuilder -> {
// ... build the class here ...
});
For more information on this API, see: