简体   繁体   中英

How to fix a class in 3rd party library

I got a situation where I need to fix one class in 3rd party library, and I am looking for effective way to fix and to use it my application.

Here are the options which o am aware of

  1. Take the source code, fix the code and use it.
  2. Provide the fix to 3rd party open source library.

I remember in previous project we just fix a class and keep it under same package in my source code, not sure that is the way to fix this problem or it done for other reasons. if I do that will my fix get picked up? Also, if it is for other reasons may I know when do we use it.

basically correct way is to provide fix to 3rd party open source library via pull-request or any other way. But it will take time and you will have to wait till new version of that library. If you cannot wait then you can create class with the same full name in your project and make fix in source code of your class. Be cause of the way Java Classloader works it will use your fixed class instead of class with the same full name form 3rd party jar. But this way of fixing bug has its own disadvantage: when you upgrade version of that library you need to make sure that source code for your fixed class is up-to-date compared with the code for that class in new version of library.

Also please make sure that creating your own class with the same full name and making some changes there doesn't violate license for that 3rd party library.

另一个解决方法是在运行时中使用Aspectj进行拦截和替换

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM