我的雇主有一项业务需求,以使Java构建逐字节可重复。我知道使JAR文件可再现的困难(由于归档顺序和时间戳),但是在这一点上,我正在谈论类文件。
在Mac和Linux上,我都使用Java 8u65构建了相同的代码。类文件在二进制方面有所不同。这两个类都反编译回相同的源。要查看差异,需要使用javap反汇编程序。
源代码似乎是:
final TrustStrategy acceptingTrustStrategy =
(X509Certificate[] chain, String authType) -> true;
Run Code Online (Sandbox Code Playgroud)
在一个版本中,结果是:
private static boolean lambda$restTemplate$38(java.security.cert.X509Certificate[], java.lang.String) throws java.security.cert.CertificateException;
Code:
0: iconst_1
1: ireturn?
Run Code Online (Sandbox Code Playgroud)
另一方面,它是:
private static boolean lambda$restTemplate$15(java.security.cert.X509Certificate[], java.lang.String) throws java.security.cert.CertificateException;
Code:
0: iconst_1
1: ireturn
Run Code Online (Sandbox Code Playgroud)
匿名lambda会在其中获得带有不同数字的名称(lambda$restTemplate$15与lambda$restTemplate$38)。
看来,当我在同一主机上重建时,我得到了相同的字节。当主机不同时,数字也会改变;两台Linux主机产生了不同的字节。
是什么决定这些数字?有没有办法强迫每个编译在该位置使用相同的数字,从而产生相同的类文件?还是Java 8类文件编译不确定?