A Java library for safely accessing private fields and methods


LegalAccess is a small Java library that wraps some commonly used reflection code for fetching / modifying private variables and methods. This library is adapted from some internal unit test code I wrote for frc5024/lib5k which had to make direct calls into a hidden hardware access layer. I now use this library mainly for writing Minecraft mods where I am calling into other mods' code when mod authors do not provide a public API.

This library is free to use and modify. In my experience, the reflection calls are very reliable as long as you get your data types correct. LegalAccess makes heavy use of exceptions to sanity-check developer code as best as possible without pre-processing. These checks cause a small amount of overhead as Java reflection involves a fair amount of work with strings.


Step 1. Add the RetryLife maven server to your build.gradle file:

repositories {
    maven { url 'https://maven.retrylife.ca' }

Step 1. Add this library as a dependency:

dependencies {
    implementation 'ca.retrylife:legalaccess:v1.+'


The LegalAccess library mainly revolves around the Accessor and MethodAccessor classes. The idea is that you construct them once (this is where most of the overhead lays), then call on their methods whenever needed.

Repo Not Found