Jimfs throws IAE when it should throw UOE
This commit adds a hack to detect when Jimfs throws an IAE where it should be throwing an UOE. Namely, the method FileSystemProvider#createDirectory should be throwing an UOE if an attempt is made to set attributes that the filesystem does not support, but instead Jimfs violates this and throws an IAE.
This commit is contained in:
parent
6db6c15d06
commit
e6eefcb142
|
@ -56,7 +56,6 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
@ -307,11 +306,28 @@ class InstallPluginCommand extends Command {
|
|||
perms.add(PosixFilePermission.OTHERS_READ);
|
||||
perms.add(PosixFilePermission.OTHERS_EXECUTE);
|
||||
return Files.createTempDirectory(pluginsDir, ".installing-", PosixFilePermissions.asFileAttribute(perms));
|
||||
} catch (IllegalArgumentException | UnsupportedOperationException e) {
|
||||
return Files.createTempDirectory(pluginsDir, ".installing-");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Jimfs throws an IAE where it should throw an UOE
|
||||
// remove when google/jimfs#30 is integrated into Jimfs
|
||||
// and the Jimfs test dependency is upgraded to include
|
||||
// this pull request
|
||||
final StackTraceElement[] elements = e.getStackTrace();
|
||||
if (elements.length >= 1 &&
|
||||
elements[0].getClassName().equals("com.google.common.jimfs.AttributeService") &&
|
||||
elements[0].getMethodName().equals("setAttributeInternal")) {
|
||||
return stagingDirectoryWithoutPosixPermissions(pluginsDir);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} catch (UnsupportedOperationException e) {
|
||||
return stagingDirectoryWithoutPosixPermissions(pluginsDir);
|
||||
}
|
||||
}
|
||||
|
||||
private Path stagingDirectoryWithoutPosixPermissions(Path pluginsDir) throws IOException {
|
||||
return Files.createTempDirectory(pluginsDir, ".installing-");
|
||||
}
|
||||
|
||||
/** Load information about the plugin, and verify it can be installed with no errors. */
|
||||
private PluginInfo verify(Terminal terminal, Path pluginRoot, boolean isBatch) throws Exception {
|
||||
// read and validate the plugin descriptor
|
||||
|
|
Loading…
Reference in New Issue