问题
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