我有一个场景,我有针对库的版本 1 编写的代码,但我想发布库的版本 2。代码已发布,因此不可更改。我担心它可能会尝试访问 v1 中存在但已在 v2 中删除的类或库成员。
我认为可以编写一个工具来进行简单检查,看看代码是否会链接到库的较新版本。我很欣赏即使代码链接,代码仍然可能很糟糕。我正在从另一方面考虑这个问题 - 如果代码无法链接,那么我可以确定存在问题。
据我所知,我需要运行字节码检查对库类的引用、方法调用和字段访问,然后使用反射检查类/成员是否存在。
我有三个问题:
(1) 这样的工具已经存在了吗?
(2) 我有一种烦躁的感觉,它比我想象的要复杂得多,而且我错过了一些重要的东西 - 是这样吗?
(3) 您是否知道一个方便的库可以让我检查字节码以便找到方法调用、引用等?
谢谢!
最佳答案
我认为 Clirr - 二进制兼容性检查器 - 可以在这里提供帮助:
Clirr is a tool that checks Java libraries for binary and source compatibility with older releases. Basically you give it two sets of jar files and Clirr dumps out a list of changes in the public api. The Clirr Ant task can be configured to break the build if it detects incompatible api changes. In a continuous integration process Clirr can automatically prevent accidental introduction of binary or source compatibility problems.
关于java - 静态检查 Java 应用程序是否存在链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2904128/