8211765: JarFile constructor throws undocumented exception

Reviewed-by: lancea, sherman, alanb, chegar
This commit is contained in:
Jaikiran Pai 2018-10-07 14:35:00 -04:00 committed by Lance Andersen
parent 548eb6860a
commit 4cd9401815
2 changed files with 19 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,6 +35,7 @@ import java.io.UncheckedIOException;
import java.lang.ref.Cleaner.Cleanable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.Files;
import java.util.ArrayDeque;
@ -1218,8 +1219,13 @@ class ZipFile implements ZipConstants, Closeable {
static Source get(File file, boolean toDelete) throws IOException {
Key key = new Key(file,
Files.readAttributes(file.toPath(), BasicFileAttributes.class));
final Key key;
try {
key = new Key(file,
Files.readAttributes(file.toPath(), BasicFileAttributes.class));
} catch (InvalidPathException ipe) {
throw new IOException(ipe);
}
Source src;
synchronized (files) {
src = files.get(key);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2018 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/**
* @test
* @bug 4842702
* @bug 4842702 8211765
* @summary Check that constructors throw specified exceptions
* @author Martin Buchholz
*/
@ -63,5 +63,13 @@ public class Constructor {
try { Unreached (new JarFile (new File ("NoSuchJar.jar"))); }
catch (IOException e) {}
// Test that an IOExcception is thrown when an invalid charater
// is part of the path on Windows and Unix
final String invalidOSPath = System.getProperty("os.name")
.startsWith("Windows") ? "C:\\*" : "foo\u0000bar";
try { Unreached (new JarFile (invalidOSPath)); }
catch (IOException e) {}
}
}