sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1734383 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/geometry/ sis-referencing/src/main/java/org/apache/sis/referencing/factory/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ si...
Date Thu, 10 Mar 2016 11:15:15 GMT
Author: desruisseaux
Date: Thu Mar 10 11:15:12 2016
New Revision: 1734383

URL: http://svn.apache.org/viewvc?rev=1734383&view=rev
Log:
Add or review AccessController.doPrivileged(...) calls.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java?rev=1734383&r1=1734382&r2=1734383&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
[UTF-8] Thu Mar 10 11:15:12 2016
@@ -24,6 +24,8 @@ package org.apache.sis.geometry;
 import java.util.Arrays;
 import java.io.Serializable;
 import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.geometry.MismatchedDimensionException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -65,6 +67,12 @@ public class GeneralDirectPosition exten
     private static final long serialVersionUID = -5524426558018300122L;
 
     /**
+     * Used for setting the {@link #ordinates} field during a {@link #clone()} operation
only.
+     * Will be fetch when first needed.
+     */
+    private static volatile Field ordinatesField;
+
+    /**
      * The ordinates of the direct position. The length of this array is the
      * {@linkplain #getDimension() dimension} of this direct position.
      */
@@ -273,6 +281,19 @@ public class GeneralDirectPosition exten
     }
 
     /**
+     * Returns the {@code "ordinates"} field of the given class and gives write permission
to it.
+     * This method should be invoked only from {@link #clone()} method.
+     */
+    static Field getOrdinatesField(final Class<?> type) throws NoSuchFieldException
{
+        final Field field = type.getDeclaredField("ordinates");
+        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+            field.setAccessible(true);
+            return null;
+        });
+        return field;
+    }
+
+    /**
      * Returns a deep copy of this position.
      *
      * @return A copy of this direct position.
@@ -280,9 +301,11 @@ public class GeneralDirectPosition exten
     @Override
     public GeneralDirectPosition clone() {
         try {
+            Field field = ordinatesField;
+            if (field == null) {
+                ordinatesField = field = getOrdinatesField(GeneralDirectPosition.class);
+            }
             GeneralDirectPosition e = (GeneralDirectPosition) super.clone();
-            final Field field = GeneralDirectPosition.class.getDeclaredField("ordinates");
-            field.setAccessible(true);
             field.set(e, ordinates.clone());
             return e;
         } catch (ReflectiveOperationException | CloneNotSupportedException exception) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java?rev=1734383&r1=1734382&r2=1734383&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] Thu Mar 10 11:15:12 2016
@@ -1034,9 +1034,7 @@ public class GeneralEnvelope extends Arr
         try {
             Field field = ordinatesField;
             if (field == null) {
-                field = ArrayEnvelope.class.getDeclaredField("ordinates");
-                field.setAccessible(true);
-                ordinatesField = field;
+                ordinatesField = field = GeneralDirectPosition.getOrdinatesField(ArrayEnvelope.class);
             }
             GeneralEnvelope e = (GeneralEnvelope) super.clone();
             field.set(e, ordinates.clone());

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java?rev=1734383&r1=1734382&r2=1734383&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] Thu Mar 10 11:15:12 2016
@@ -1527,7 +1527,7 @@ public class GeodeticObjectFactory exten
             if (c == null) {
                 c = Class.forName("org.apache.sis.io.wkt.GeodeticObjectParser").asSubclass(Parser.class)
                          .getConstructor(Map.class, ObjectFactory.class, MathTransformFactory.class);
-                final Constructor<? extends Parser> cp = c;     // For allowing use
in inner class.
+                final Constructor<?> cp = c;     // For allowing use in inner class
or lambda expression.
                 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
                     cp.setAccessible(true);
                     return null;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java?rev=1734383&r1=1734382&r2=1734383&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] Thu Mar 10 11:15:12 2016
@@ -1244,7 +1244,7 @@ public class DefaultMathTransformFactory
             if (c == null) {
                 c = Class.forName("org.apache.sis.io.wkt.MathTransformParser").asSubclass(Parser.class)
                          .getConstructor(MathTransformFactory.class);
-                final Constructor<? extends Parser> cp = c;     // For allowing use
in inner class.
+                final Constructor<?> cp = c;     // For allowing use in inner class
or lambda expression.
                 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
                     cp.setAccessible(true);
                     return null;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java?rev=1734383&r1=1734382&r2=1734383&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
[UTF-8] Thu Mar 10 11:15:12 2016
@@ -19,6 +19,8 @@ package org.apache.sis.internal.system;
 import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Messages;
 
@@ -113,7 +115,9 @@ public enum DataDirectory {
      */
     public static synchronized Path getRootDirectory() {
         if (rootDirectory == null) try {
-            final String dir = System.getenv(ENV);
+            final String dir = AccessController.doPrivileged((PrivilegedAction<String>)
() -> {
+                return System.getenv(ENV);
+            });
             if (dir == null || dir.isEmpty()) {
                 warning("getRootDirectory", null, Messages.Keys.DataDirectoryNotSpecified_1,
ENV);
             } else try {

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1734383&r1=1734382&r2=1734383&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Thu Mar 10 11:15:12 2016
@@ -103,7 +103,7 @@ public final class DefaultFactories exte
                     }
                 }
                 return (prefered != null) ? prefered : fallback;
-            }, null, new FilePermission("<<ALL FILES>>", "read"));       // For
reading META-INF/services/ files.
+            }, null, new FilePermission("<<ALL FILES>>", "read"));      // For
reading META-INF/services/* files.
             /*
              * Verifies if the factory that we just selected is the same implementation than
an existing instance.
              * The main case for this test is org.apache.sis.referencing.factory.GeodeticObjectFactory,
where the

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java?rev=1734383&r1=1734382&r2=1734383&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8]
Thu Mar 10 11:15:12 2016
@@ -38,6 +38,8 @@ import java.text.Format;
 import java.text.DateFormat;
 import java.text.FieldPosition;
 import java.nio.charset.Charset;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Version;
@@ -352,7 +354,13 @@ fill:   for (int i=0; ; i++) {
                 case 13: {
                     if (sections.contains(PATHS)) {
                         nameKey = Vocabulary.Keys.DataDirectory;
-                        value = System.getenv(DataDirectory.ENV);
+                        try {
+                            value = AccessController.doPrivileged((PrivilegedAction<String>)
() -> {
+                                return System.getenv(DataDirectory.ENV);
+                            });
+                        } catch (SecurityException e) {
+                            value = e.toString();
+                        }
                         if (value == null) {
                             value = Messages.getResources(locale).getString(Messages.Keys.DataDirectoryNotSpecified_1,
DataDirectory.ENV);
                         } else {



Mime
View raw message