You don't even need to patch any files - you can patch classes at runtime using a "-javaagent" library.
There are plenty of libraries out there to facilitate this such as Javassist or Apache BCEL, and lots of legitimate uses (AOP, instrumentation, etc).