You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by st...@apache.org on 2015/10/05 11:39:11 UTC

svn commit: r1706775 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java

Author: stefanegli
Date: Mon Oct  5 09:39:11 2015
New Revision: 1706775

URL: http://svn.apache.org/viewvc?rev=1706775&view=rev
Log:
OAK-3471 : replace hacky setFinalStatic - which uses reflection - with a direct access to the now-protected WORKING_DIR

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java?rev=1706775&r1=1706774&r2=1706775&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java Mon Oct  5 09:39:11 2015
@@ -150,8 +150,9 @@ public class ClusterNodeInfo {
 
     /**
      * The current working directory.
+     * Note: marked protected non-final for testing purpose only.
      */
-    private static final String WORKING_DIR = System.getProperty("user.dir", "");
+    protected static String WORKING_DIR = System.getProperty("user.dir", "");
 
     /**
      * <b>Only Used For Testing</b>

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java?rev=1706775&r1=1706774&r2=1706775&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentDiscoveryLiteServiceTest.java Mon Oct  5 09:39:11 2015
@@ -597,30 +597,13 @@ public class DocumentDiscoveryLiteServic
         discoveryLite.deactivate();
     }
 
-    /**
-     * Borrowed from
-     * http://stackoverflow.com/questions/3301635/change-private-static-final-
-     * field-using-java-reflection
-     */
-    static Object setFinalStatic(Field field, Object newValue) throws Exception {
-        field.setAccessible(true);
-
-        Field modifiersField = Field.class.getDeclaredField("modifiers");
-        modifiersField.setAccessible(true);
-        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
-
-        Object prev = field.get(null);
-        field.set(null, newValue);
-        return prev;
-    }
-
     // subsequent tests should get a DocumentDiscoveryLiteService setup from the
     // start
     private DocumentNodeStore createNodeStore(String workingDir) throws SecurityException, Exception {
-        Object prevWorkingDir = System.getProperty("user.dir", "");
+        String prevWorkingDir = ClusterNodeInfo.WORKING_DIR;
         try {
             // ensure that we always get a fresh cluster[node]id
-            prevWorkingDir = setFinalStatic(ClusterNodeInfo.class.getDeclaredField("WORKING_DIR"), workingDir);
+            ClusterNodeInfo.WORKING_DIR = workingDir;
 
             // then create the DocumentNodeStore
             DocumentMK mk1 = createMK(
@@ -632,7 +615,7 @@ public class DocumentDiscoveryLiteServic
             return mk1.nodeStore;
         }
         finally {
-            setFinalStatic(ClusterNodeInfo.class.getDeclaredField("WORKING_DIR"), prevWorkingDir);
+            ClusterNodeInfo.WORKING_DIR = prevWorkingDir;
         }
     }