From e6eefcb1429e66dc23b49267e04bba1b4d33ec14 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 21 Mar 2016 10:16:02 -0400 Subject: [PATCH] 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. --- .../plugins/InstallPluginCommand.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java index e822021e0b6..ce589acf844 100644 --- a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java +++ b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java @@ -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