geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [geode] branch develop updated: GEODE-4670: Removing unused reflection of JDK methods
Date Fri, 16 Feb 2018 17:39:05 GMT
This is an automated email from the ASF dual-hosted git repository.

upthewaterspout pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 41d63a5  GEODE-4670: Removing unused reflection of JDK methods
41d63a5 is described below

commit 41d63a58c70de59cc62dc362195a0319b06860b9
Author: Dan Smith <upthewaterspout@apache.org>
AuthorDate: Tue Feb 13 14:21:01 2018 -0800

    GEODE-4670: Removing unused reflection of JDK methods
    
    JDK9 logs a warning about doing reflection on these classes. The methods
    doing the reflection are not being used.
---
 .../apache/geode/internal/shared/NativeCalls.java  | 53 ----------------
 .../geode/internal/shared/NativeCallsJNAImpl.java  | 72 ----------------------
 2 files changed, 125 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCalls.java b/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCalls.java
index 6b9bf66..46524c9 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCalls.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCalls.java
@@ -80,30 +80,6 @@ public abstract class NativeCalls {
     return instance;
   }
 
-  @SuppressWarnings("unchecked")
-  protected static Map<String, String> getModifiableJavaEnv() {
-    final Map<String, String> env = System.getenv();
-    try {
-      final Field m = env.getClass().getDeclaredField("m");
-      m.setAccessible(true);
-      return (Map<String, String>) m.get(env);
-    } catch (Exception ex) {
-      return null;
-    }
-  }
-
-  @SuppressWarnings("unchecked")
-  protected static Map<String, String> getModifiableJavaEnvWIN() {
-    try {
-      final Field envField = Class.forName("java.lang.ProcessEnvironment")
-          .getDeclaredField("theCaseInsensitiveEnvironment");
-      envField.setAccessible(true);
-      return (Map<String, String>) envField.get(null);
-    } catch (Exception ex) {
-      return null;
-    }
-  }
-
   /**
    * Get the native kernel descriptor given the java Socket. This is a horribly implementation
    * dependent code checking various cases to get to the underlying kernel socket descriptor
but
@@ -263,17 +239,6 @@ public abstract class NativeCalls {
   public abstract String getEnvironment(String name);
 
   /**
-   * Set the value of an environment variable. This modifies both the value in the process,
and the
-   * cached static map maintained by JVM on the first call so further calls to
-   * {@link System#getenv(String)} will also return the modified value.
-   *
-   * @param name the name of the environment variable to be modified
-   * @param value the new value of the environment variable; a value of null clears the existing
-   *        value
-   */
-  public abstract void setEnvironment(String name, String value);
-
-  /**
    * Get the process ID of the current process.
    */
   public abstract int getProcessId();
@@ -479,13 +444,10 @@ public abstract class NativeCalls {
    */
   public static class NativeCallsGeneric extends NativeCalls {
 
-    private static final Map<String, String> javaEnv;
-
     private static final boolean isWin;
 
     static {
       isWin = System.getProperty("os.name").indexOf("Windows") >= 0;
-      javaEnv = isWin ? getModifiableJavaEnvWIN() : getModifiableJavaEnv();
     }
 
     /**
@@ -505,21 +467,6 @@ public abstract class NativeCalls {
     }
 
     /**
-     * @see NativeCalls#setEnvironment(String, String)
-     */
-    @Override
-    public void setEnvironment(final String name, final String value) {
-      // just change the cached map in java env if possible
-      if (javaEnv != null) {
-        if (value != null) {
-          javaEnv.put(name, value);
-        } else {
-          javaEnv.remove(name);
-        }
-      }
-    }
-
-    /**
      * @see NativeCalls#getProcessId()
      */
     @Override
diff --git a/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCallsJNAImpl.java
b/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCallsJNAImpl.java
index 441610e..67d4e07 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCallsJNAImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/shared/NativeCallsJNAImpl.java
@@ -132,8 +132,6 @@ public class NativeCallsJNAImpl {
     static final int EPERM = 1;
     static final int ENOSPC = 28;
 
-    static final Map<String, String> javaEnv = getModifiableJavaEnv();
-
     /** Signal callback handler for <code>signal</code> native call. */
     interface SignalHandler extends Callback {
       void callback(int signum);
@@ -160,39 +158,6 @@ public class NativeCallsJNAImpl {
     }
 
     /**
-     * @see NativeCalls#setEnvironment(String, String)
-     */
-    @Override
-    public synchronized void setEnvironment(final String name, final String value) {
-      if (name == null) {
-        throw new UnsupportedOperationException("setEnvironment() for name=NULL");
-      }
-      int res = -1;
-      Throwable cause = null;
-      try {
-        if (value != null) {
-          res = setenv(name, value, 1);
-        } else {
-          res = unsetenv(name);
-        }
-      } catch (LastErrorException le) {
-        cause = new NativeErrorException(le.getMessage(), le.getErrorCode(), le.getCause());
-      }
-      if (res != 0) {
-        throw new IllegalArgumentException(
-            "setEnvironment: given name=" + name + " (value=" + value + ')', cause);
-      }
-      // also change in java cached map
-      if (javaEnv != null) {
-        if (value != null) {
-          javaEnv.put(name, value);
-        } else {
-          javaEnv.remove(name);
-        }
-      }
-    }
-
-    /**
      * @see NativeCalls#getEnvironment(String)
      */
     @Override
@@ -948,8 +913,6 @@ public class NativeCallsJNAImpl {
       public static native boolean CloseHandle(Pointer handle) throws LastErrorException;
     }
 
-    private static final Map<String, String> javaEnv = getModifiableJavaEnvWIN();
-
     /**
      * @see NativeCalls#getOSType()
      */
@@ -959,41 +922,6 @@ public class NativeCallsJNAImpl {
     }
 
     /**
-     * @see NativeCalls#setEnvironment(String, String)
-     */
-    @Override
-    public synchronized void setEnvironment(final String name, final String value) {
-      if (name == null) {
-        throw new UnsupportedOperationException("setEnvironment() for name=NULL");
-      }
-      boolean res = false;
-      Throwable cause = null;
-      try {
-        res = Kernel32.SetEnvironmentVariableA(name, value);
-      } catch (LastErrorException le) {
-        // error code ERROR_ENVVAR_NOT_FOUND (203) indicates variable was not
-        // found so ignore
-        if (value == null && le.getErrorCode() == 203) {
-          res = true;
-        } else {
-          cause = new NativeErrorException(le.getMessage(), le.getErrorCode(), le.getCause());
-        }
-      }
-      if (!res) {
-        throw new IllegalArgumentException(
-            "setEnvironment: given name=" + name + " (value=" + value + ')', cause);
-      }
-      // also change in java cached map
-      if (javaEnv != null) {
-        if (value != null) {
-          javaEnv.put(name, value);
-        } else {
-          javaEnv.remove(name);
-        }
-      }
-    }
-
-    /**
      * @see NativeCalls#getEnvironment(String)
      */
     @Override

-- 
To stop receiving notification emails like this one, please contact
upthewaterspout@apache.org.

Mime
View raw message