Skip to content

Commit abfab03

Browse files
committedJun 30, 2023
8228403: SignTwice.java failed with java.io.FileNotFoundException: File name too long
Backport-of: 804e840856d7593eb64faa7c84a4b02397af0bc7
1 parent 142d467 commit abfab03

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed
 

‎test/jdk/sun/security/tools/jarsigner/compatibility/Compatibility.java

+36-19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
* @run main/manual/othervm Compatibility
3636
*/
3737

38+
import static java.nio.charset.StandardCharsets.UTF_8;
39+
3840
import java.io.BufferedReader;
3941
import java.io.File;
4042
import java.io.FileOutputStream;
@@ -43,12 +45,12 @@
4345
import java.io.IOException;
4446
import java.io.OutputStream;
4547
import java.io.PrintStream;
46-
import java.nio.file.Path;
4748
import java.nio.file.Files;
49+
import java.nio.file.Path;
4850
import java.text.DateFormat;
4951
import java.text.SimpleDateFormat;
50-
import java.util.Arrays;
5152
import java.util.ArrayList;
53+
import java.util.Arrays;
5254
import java.util.Calendar;
5355
import java.util.Date;
5456
import java.util.HashMap;
@@ -57,19 +59,18 @@
5759
import java.util.Locale;
5860
import java.util.Map;
5961
import java.util.Set;
62+
import java.util.concurrent.TimeUnit;
6063
import java.util.function.Consumer;
6164
import java.util.function.Function;
62-
import java.util.jar.Manifest;
6365
import java.util.jar.Attributes.Name;
64-
import java.util.concurrent.TimeUnit;
66+
import java.util.jar.Manifest;
6567
import java.util.stream.Collectors;
6668
import java.util.stream.IntStream;
69+
6770
import jdk.test.lib.process.OutputAnalyzer;
6871
import jdk.test.lib.process.ProcessTools;
6972
import jdk.test.lib.util.JarUtils;
7073

71-
import static java.nio.charset.StandardCharsets.UTF_8;
72-
7374
public class Compatibility {
7475

7576
private static final String TEST_SRC = System.getProperty("test.src");
@@ -179,7 +180,7 @@ public static void main(String... args) throws Throwable {
179180
List<SignItem> signItems =
180181
test(jdkInfoList, tsaList, certList, createJars());
181182

182-
boolean failed = generateReport(tsaList, signItems);
183+
boolean failed = generateReport(jdkInfoList, tsaList, signItems);
183184

184185
// Restores the original stdout and stderr.
185186
System.setOut(origStdOut);
@@ -415,11 +416,15 @@ private static List<JdkInfo> jdkInfoList() throws Throwable {
415416
}
416417

417418
List<JdkInfo> jdkInfoList = new ArrayList<>();
419+
int index = 0;
418420
for (String jdkPath : jdkList) {
419421
JdkInfo jdkInfo = "TEST_JDK".equalsIgnoreCase(jdkPath) ?
420422
TEST_JDK_INFO : new JdkInfo(jdkPath);
421423
// The JDK version must be unique.
422424
if (!jdkInfoList.contains(jdkInfo)) {
425+
jdkInfo.index = index++;
426+
jdkInfo.version = String.format(
427+
"%s(%d)", jdkInfo.version, jdkInfo.index);
423428
jdkInfoList.add(jdkInfo);
424429
} else {
425430
System.out.println("The JDK version is duplicate: " + jdkPath);
@@ -908,13 +913,22 @@ private static OutputAnalyzer verifyJar(String jarsignerPath,
908913
}
909914

910915
// Generates the test result report.
911-
private static boolean generateReport(List<TsaInfo> tsaList,
916+
private static boolean generateReport(List<JdkInfo> jdkList, List<TsaInfo> tsaList,
912917
List<SignItem> signItems) throws IOException {
913918
System.out.println("Report is being generated...");
914919

915920
StringBuilder report = new StringBuilder();
916921
report.append(HtmlHelper.startHtml());
917922
report.append(HtmlHelper.startPre());
923+
924+
// Generates JDK list
925+
report.append("JDK list:\n");
926+
for(JdkInfo jdkInfo : jdkList) {
927+
report.append(String.format("%d=%s%n",
928+
jdkInfo.index,
929+
jdkInfo.runtimeVersion));
930+
}
931+
918932
// Generates TSA URLs
919933
report.append("TSA list:\n");
920934
for(TsaInfo tsaInfo : tsaList) {
@@ -1024,24 +1038,27 @@ private static OutputAnalyzer execTool(String toolPath, String... args)
10241038

10251039
private static class JdkInfo {
10261040

1041+
private int index;
10271042
private final String jdkPath;
10281043
private final String jarsignerPath;
1029-
private final String version;
1044+
private final String runtimeVersion;
1045+
private String version;
10301046
private final int majorVersion;
10311047
private final boolean supportsTsadigestalg;
10321048

10331049
private Map<String, Boolean> sigalgMap = new HashMap<>();
10341050

10351051
private JdkInfo(String jdkPath) throws Throwable {
10361052
this.jdkPath = jdkPath;
1037-
version = execJdkUtils(jdkPath, JdkUtils.M_JAVA_RUNTIME_VERSION);
1038-
if (version == null || version.isBlank()) {
1053+
jarsignerPath = jarsignerPath(jdkPath);
1054+
runtimeVersion = execJdkUtils(jdkPath, JdkUtils.M_JAVA_RUNTIME_VERSION);
1055+
if (runtimeVersion == null || runtimeVersion.isBlank()) {
10391056
throw new RuntimeException(
10401057
"Cannot determine the JDK version: " + jdkPath);
10411058
}
1042-
majorVersion = Integer.parseInt((version.matches("^1[.].*") ?
1043-
version.substring(2) : version).replaceAll("[^0-9].*$", ""));
1044-
jarsignerPath = jarsignerPath(jdkPath);
1059+
version = execJdkUtils(jdkPath, JdkUtils.M_JAVA_VERSION);
1060+
majorVersion = Integer.parseInt((runtimeVersion.matches("^1[.].*") ?
1061+
runtimeVersion.substring(2) : runtimeVersion).replaceAll("[^0-9].*$", ""));
10451062
supportsTsadigestalg = execTool(jarsignerPath, "-help")
10461063
.getOutput().contains("-tsadigestalg");
10471064
}
@@ -1073,7 +1090,7 @@ public int hashCode() {
10731090
final int prime = 31;
10741091
int result = 1;
10751092
result = prime * result
1076-
+ ((version == null) ? 0 : version.hashCode());
1093+
+ ((runtimeVersion == null) ? 0 : runtimeVersion.hashCode());
10771094
return result;
10781095
}
10791096

@@ -1086,17 +1103,17 @@ public boolean equals(Object obj) {
10861103
if (getClass() != obj.getClass())
10871104
return false;
10881105
JdkInfo other = (JdkInfo) obj;
1089-
if (version == null) {
1090-
if (other.version != null)
1106+
if (runtimeVersion == null) {
1107+
if (other.runtimeVersion != null)
10911108
return false;
1092-
} else if (!version.equals(other.version))
1109+
} else if (!runtimeVersion.equals(other.runtimeVersion))
10931110
return false;
10941111
return true;
10951112
}
10961113

10971114
@Override
10981115
public String toString() {
1099-
return "JdkInfo[" + version + ", " + jdkPath + "]";
1116+
return "JdkInfo[" + runtimeVersion + ", " + jdkPath + "]";
11001117
}
11011118
}
11021119

‎test/jdk/sun/security/tools/jarsigner/compatibility/JdkUtils.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ private enum Alg {
3636
KEY, SIG, DIGEST;
3737
}
3838

39+
static final String M_JAVA_VERSION = "javaVersion";
3940
static final String M_JAVA_RUNTIME_VERSION = "javaRuntimeVersion";
4041
static final String M_IS_SUPPORTED_KEYALG = "isSupportedKeyalg";
4142
static final String M_IS_SUPPORTED_SIGALG = "isSupportedSigalg";
4243
static final String M_IS_SUPPORTED_DIGESTALG = "isSupportedDigestalg";
4344

4445
// Returns the JDK build version.
46+
static String javaVersion() {
47+
return System.getProperty("java.version");
48+
}
49+
50+
// Returns the JDK build runtime version.
4551
static String javaRuntimeVersion() {
4652
return System.getProperty("java.runtime.version");
4753
}
@@ -63,7 +69,9 @@ static boolean isSupportedAlg(Alg algType, String algName) {
6369
}
6470

6571
public static void main(String[] args) {
66-
if (M_JAVA_RUNTIME_VERSION.equals(args[0])) {
72+
if (M_JAVA_VERSION.equals(args[0])) {
73+
System.out.print(javaVersion());
74+
} else if (M_JAVA_RUNTIME_VERSION.equals(args[0])) {
6775
System.out.print(javaRuntimeVersion());
6876
} else if (M_IS_SUPPORTED_KEYALG.equals(args[0])) {
6977
System.out.print(isSupportedAlg(Alg.KEY, args[1]));

0 commit comments

Comments
 (0)
Please sign in to comment.