Can FindBugs be used to flag code that uses a method that's been blacklisted?

☆樱花仙子☆ 提交于 2019-12-12 10:47:10

问题


We're trying to move our very large codebase from Guava 11 to Guava 14 and would like to catch uses of removed or deprecated APIs. Can FindBugs perform such checking? If so, how?


回答1:


One solution would be to just use Oracle's Java compiler javac to do this.

Removed methods in the API would result in compiler errors if they are used so it should be possible to find these by compiling the code.

Deprecated methods can be found using the javac -deprecation option. More on -deprecation here: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html




回答2:


You could also use PMD Sourceforge for this task. There are rules out there that let you find deprecated methods




回答3:


One aspect that I believe javac will not cover is if you cannot change the 3rd party code to add @Deprecated annotations. If you just want to avoid a method which has not been marked as deprecated, you can use this plugin I wrote for FindBugs:

https://github.com/Grundlefleck/FindBugs4Deprecating3rdParty

There's very little documentation, so you may need to explore a little yourself. It allows configuring methods and classes to avoid in a properties file. I use it to deprecate org.junit.Assert.assertThat.



来源:https://stackoverflow.com/questions/15395736/can-findbugs-be-used-to-flag-code-that-uses-a-method-thats-been-blacklisted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!