如何静态识别 JAR 中缺少的方法(二进制兼容性) [英] How to identify a missing method (Binary Compatibility) in a JAR statically

查看:27
本文介绍了如何静态识别 JAR 中缺少的方法(二进制兼容性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证 2 个 JAR 之间的二进制兼容性.

遵循此

sigtest - Oracle 的 SigTest 签名测试和 API 一致性工具

japitools - 测试 Java API 之间的兼容性

japi-checker - 在二进制级别工作的 Java API 向后兼容性检查器

revapi - API 分析和变更跟踪工具

或手动使用 javap 反编译器:

<前>javap OLD.class > OLD.txtjavap NEW.class > NEW.txtdiff -rNau OLD.txt NEW.txt > CHANGES.txt

I want to verify binary compatibility between 2 JARs.

Following the suggestions in this answer I used jboss tattletale but it can find only missing classes.

How can I find if there are missing methods? Is it possible at all?

E.g.

"Depends - on" class Foo depends on Bar (like many other middle class workers)

import org.overlyusedclassnames.Bar

public class Foo{
    public void someMethod(){
         Bar tender = new Bar();
         tender.getJohnnyRedLabel();
         tender.getJohnnyBlueLabel(); //this method is new in the Bar class
    }
}

"Compile time" class

package org.overlyusedclassnames;

/** 
 * @Since 1992
 * Changes: added blue and gold Johnny Walker labels
 */

public class Bar {
    public Drink getJohnnyRedLabel(){
         return new JohnyWalkerFactory.get(RedLabel.class);
    }

    public Drink getJohnnyBlackLabel(){
         return new JohnyWalkerFactory.get(BlackLabel.class);
    }

    public Drink getJohnnyGoldLabel(){
         return new JohnyWalkerFactory.get(GoldLabel.class);
    }

    public Drink getJohnnyBlueLabel(){
         return new JohnyWalkerFactory.get(BlueLabel.class);
    }

}

Now imagine an old Bar jar is accedently replacing the compiled time bar:

"Runtime time" class

package org.overlyusedclassnames;

/** 
 * @Since 1909
 * Changes: added red and black Johnny Walker labels
 */

public class Bar {
    public Drink getJohnnyRedLabel(){
         return new JohnyWalkerFactory.get(RedLabel.class);
    }

    public Drink getJohnnyBlackLabel(){
         return new JohnyWalkerFactory.get(BlackLabel.class);
    }
}

Is there a way to identify the missing method without running it and getting a NoSuchMethodError?


Disclaimer: This is a major rephrasing of my own related question, which is undeletable. I chose asking a new question because the rephrasing will render the current 2 answers as quite unrelated to the topic.

解决方案

japi-compliance-checker - backward API/ABI compatibility checker for a Java library:

japi-compliance-checker -lib NAME -old OLD.jar -new NEW.jar

sigtest - Oracle's SigTest signature testing and API conformance tool

japitools - test for compatibility between Java APIs

japi-checker - a java API backward compatibility checker which works at binary level

revapi - API analysis and change tracking tool

or manually using javap decompiler:

javap OLD.class > OLD.txt
javap NEW.class > NEW.txt
diff -rNau OLD.txt NEW.txt > CHANGES.txt

这篇关于如何静态识别 JAR 中缺少的方法(二进制兼容性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆