From 5185a9734df920f600615500faf153847bcc7d39 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 23 Dec 2016 18:14:36 -0500 Subject: [PATCH] Add comment clarifying property setting in client This commit adds a comment clarifying why we do not catch a security exception in the pre-built transport client. --- .../client/PreBuiltTransportClient.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java b/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java index a173d43a96c..3233470a253 100644 --- a/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java +++ b/client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java @@ -37,13 +37,12 @@ import java.util.Collections; import java.util.concurrent.TimeUnit; /** - * A builder to create an instance of {@link TransportClient} - * This class pre-installs the + * A builder to create an instance of {@link TransportClient}. This class pre-installs the * {@link Netty4Plugin}, * {@link ReindexPlugin}, * {@link PercolatorPlugin}, * and {@link MustachePlugin} - * for the client. These plugins are all elasticsearch core modules required. + * plugins for the client. These plugins are all the required modules for Elasticsearch. */ @SuppressWarnings({"unchecked","varargs"}) public class PreBuiltTransportClient extends TransportClient { @@ -63,6 +62,8 @@ public class PreBuiltTransportClient extends TransportClient { final String noUnsafe = System.getProperty(noUnsafeKey); if (noUnsafe == null) { // disable Netty from using unsafe + // while permissions are needed to set this, if a security exception is thrown the permission needed can either be granted or + // the system property can be set directly before starting the JVM; therefore, we do not catch a security exception here System.setProperty(noUnsafeKey, Boolean.toString(true)); } @@ -70,34 +71,36 @@ public class PreBuiltTransportClient extends TransportClient { final String noKeySetOptimization = System.getProperty(noKeySetOptimizationKey); if (noKeySetOptimization == null) { // disable Netty from replacing the selector key set + // while permissions are needed to set this, if a security exception is thrown the permission needed can either be granted or + // the system property can be set directly before starting the JVM; therefore, we do not catch a security exception here System.setProperty(noKeySetOptimizationKey, Boolean.toString(true)); } } private static final Collection> PRE_INSTALLED_PLUGINS = - Collections.unmodifiableList( - Arrays.asList( - Netty4Plugin.class, - ReindexPlugin.class, - PercolatorPlugin.class, - MustachePlugin.class)); - + Collections.unmodifiableList( + Arrays.asList( + Netty4Plugin.class, + ReindexPlugin.class, + PercolatorPlugin.class, + MustachePlugin.class)); /** * Creates a new transport client with pre-installed plugins. + * * @param settings the settings passed to this transport client - * @param plugins an optional array of additional plugins to run with this client + * @param plugins an optional array of additional plugins to run with this client */ @SafeVarargs public PreBuiltTransportClient(Settings settings, Class... plugins) { this(settings, Arrays.asList(plugins)); } - /** * Creates a new transport client with pre-installed plugins. + * * @param settings the settings passed to this transport client - * @param plugins a collection of additional plugins to run with this client + * @param plugins a collection of additional plugins to run with this client */ public PreBuiltTransportClient(Settings settings, Collection> plugins) { this(settings, plugins, null); @@ -105,12 +108,15 @@ public class PreBuiltTransportClient extends TransportClient { /** * Creates a new transport client with pre-installed plugins. - * @param settings the settings passed to this transport client - * @param plugins a collection of additional plugins to run with this client - * @param hostFailureListener a failure listener that is invoked if a node is disconnected. This can be null + * + * @param settings the settings passed to this transport client + * @param plugins a collection of additional plugins to run with this client + * @param hostFailureListener a failure listener that is invoked if a node is disconnected; this can be null */ - public PreBuiltTransportClient(Settings settings, Collection> plugins, - HostFailureListener hostFailureListener) { + public PreBuiltTransportClient( + Settings settings, + Collection> plugins, + HostFailureListener hostFailureListener) { super(settings, Settings.EMPTY, addPlugins(plugins, PRE_INSTALLED_PLUGINS), hostFailureListener); }