hello. i have an (external) library class that cra...
# announcements
l
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?
c
perhaps this is a use case for reflection?
l
If you have a way to inject the instance where the override is missing (including with reflection), yes, you can have a wrapper using
Proxy
from Java reflection to handle the missing override and delegate for the other ones.
l
i don't quite see why would I want to use reflection instead of simply having a class in a “fake” library package?
l
If you don't need reflection, don't use it, for sure
e
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)