How do you access protected Java method in thirdparty library?

As per the Java access modifiers, besides extending the object (which you can't if you receive the object) is to access it from an object in the same package as the object you received. So your option is to create a wrapper class in the same package which retrieves the attribute via the protected method for you.


You can subclass the method, create a public method that calls the protected method and returns the result.

If you can't do that (if the class is final), then setAccessible is pretty much your only way.