hello. i have an (external) library class that cra...
# announcements
hello. i have an (external) library class that crashes in some rare circumstances. so i want to override one method and yolo suppress the exception. the method is not public though. it seems that i can override it if i make a new file with the package of that class (
package library.package
). is there a reason i shouldn't do this?
perhaps this is a use case for reflection?
If you have a way to inject the instance where the override is missing (including with reflection), yes, you can have a wrapper using
from Java reflection to handle the missing override and delegate for the other ones.
i don't quite see why would I want to use reflection instead of simply having a class in a “fake” library package?
If you don't need reflection, don't use it, for sure
personally I've written quite a few bytecode transforms to fix up external libraries. can be done with Gradle (https://docs.gradle.org/current/userguide/artifact_transforms.html) or Android's build system (https://developer.android.com/reference/tools/gradle-api/7.1/com/android/build/api/transform/Transform)
although if you're on the desktop JVM and not Android, you could also perform the fixup in -javaagent (which is how I unit test my aforementioned transforms)