Skip to content

Commit 55e6bb6

Browse files
archiecobbsVicente Romero
authored and
Vicente Romero
committedFeb 27, 2023
8302685: Some javac unit tests aren't reliably closing open files
Reviewed-by: darcy, vromero
1 parent f5a1276 commit 55e6bb6

File tree

58 files changed

+240
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+240
-391
lines changed
 

‎test/langtools/tools/javac/4241573/T4241573.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,11 @@ File createDir(File dir, String... entries) throws Exception {
131131

132132
/** Create a jar file containing one or more entries. */
133133
File createJar(File jar, String... entries) throws IOException {
134-
OutputStream out = new FileOutputStream(jar);
135-
try {
136-
JarOutputStream jos = new JarOutputStream(out);
134+
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jar))) {
137135
for (String e: entries) {
138136
jos.putNextEntry(new JarEntry(getPathForZipEntry(e)));
139137
jos.write(getBodyForEntry(e).getBytes());
140138
}
141-
jos.close();
142-
} finally {
143-
out.close();
144139
}
145140
return jar;
146141
}

‎test/langtools/tools/javac/6400872/T6400872.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ static void jar(File jar, Iterable<File> classPath, File base, File... files)
9191
mainAttrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
9292
mainAttrs.put(Attributes.Name.CLASS_PATH, join(classPath, " "));
9393
}
94-
OutputStream out = new BufferedOutputStream(new FileOutputStream(jar));
95-
JarOutputStream j = new JarOutputStream(out, m);
96-
add(j, base, files);
97-
j.close();
94+
try (JarOutputStream j = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jar)), m)) {
95+
add(j, base, files);
96+
}
9897
}
9998

10099
static void add(JarOutputStream j, File base, File... files) throws IOException {
@@ -124,15 +123,16 @@ static void add(JarOutputStream j, File base, File file) throws IOException {
124123

125124
static byte[] read(File f) throws IOException {
126125
byte[] buf = new byte[(int) f.length()];
127-
BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
128-
int offset = 0;
129-
while (offset < buf.length) {
130-
int n = in.read(buf, offset, buf.length - offset);
131-
if (n < 0)
132-
throw new EOFException();
133-
offset += n;
126+
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(f))) {
127+
int offset = 0;
128+
while (offset < buf.length) {
129+
int n = in.read(buf, offset, buf.length - offset);
130+
if (n < 0)
131+
throw new EOFException();
132+
offset += n;
133+
}
134+
return buf;
134135
}
135-
return buf;
136136
}
137137

138138
static <T> Iterable<T> iterable(T single) {

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Feb 27, 2023

@openjdk-notifier[bot]
Please sign in to comment.