mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Fabio Pistolesi
28.01.2015 8b6a544a11dee1f1b77151fb532fb1f06a7bbea6
OPENDJ-1972 CR-6777 Remove JDK6 compatibility layers

Eliminate reflection APIs for JDK7 specific code and use JDK7 language features directly.
11 files modified
704 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/admin/AdministrationConnector.java 3 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java 2 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java 6 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java 3 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/extensions/DiskSpaceMonitor.java 28 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/loggers/MultifileTextWriter.java 3 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java 3 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/FilePermission.java 520 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/Platform.java 128 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java 6 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/admin/AdministrationConnector.java
@@ -571,8 +571,6 @@
      }
      // Change the password file permission if possible
      if (FilePermission.canSetPermissions())
      {
        try
        {
          if (!FilePermission.setPermissions(new File(pinFilePath),
@@ -587,7 +585,6 @@
          // Log a warning that the permissions were not set.
          logger.warn(WARN_ADMIN_SET_PERMISSIONS_FAILED, pinFilePath);
        }
      }
      // Delete the exported certificate
      File f = new File(tempCertPath);
opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java
@@ -1478,7 +1478,6 @@
    out.flush();
    out.close();
    if(FilePermission.canSetPermissions()) {
      try {
        if (!FilePermission.setPermissions(new File(path),
                                           new FilePermission(0600)))
@@ -1491,7 +1490,6 @@
        logger.warn(WARN_TRUSTSTORE_SET_PERMISSIONS_FAILED, path);
      }
    }
  }
  /**
   * Generates a self-signed certificate with well-known alias if there is none.
opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java
@@ -165,8 +165,6 @@
    }
    // Get the backend database backendDirectory permissions and apply
    if(FilePermission.canSetPermissions())
    {
      try
      {
        if(!FilePermission.setPermissions(backendDirectory, backendPermission))
@@ -179,7 +177,6 @@
        // Log an warning that the permissions were not set.
        logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDirectory, e);
      }
    }
    // Open the database environment
    env = new Environment(backendDirectory,
@@ -830,8 +827,6 @@
        }
        // Get the backend database backendDirectory permissions and apply
        if(FilePermission.canSetPermissions())
        {
          File parentDirectory = getFileForPath(config.getDBDirectory());
          File backendDirectory = new File(parentDirectory, config.getBackendId());
          try
@@ -847,7 +842,6 @@
            logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDirectory, e);
          }
        }
      }
      getMonitorProvider().enableFilterUseStats(
          cfg.isIndexFilterAnalyzerEnabled());
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
@@ -1026,8 +1026,6 @@
    FilePermission backendPermission = decodeDBDirPermissions(curCfg);
    // Get the backend database backendDirectory permissions and apply
    if(FilePermission.canSetPermissions())
    {
      try
      {
        if(!FilePermission.setPermissions(backendDir, backendPermission))
@@ -1041,7 +1039,6 @@
        logger.warn(WARN_JEB_SET_PERMISSIONS_FAILED, backendDir, e);
      }
    }
  }
  private static FilePermission decodeDBDirPermissions(PersistitBackendCfg curCfg) throws ConfigException
  {
opendj-server-legacy/src/main/java/org/opends/server/extensions/DiskSpaceMonitor.java
@@ -35,6 +35,9 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -60,7 +63,6 @@
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.util.Platform;
/**
 * This class provides an application-wide disk space monitoring service.
@@ -270,7 +272,7 @@
    File fsMountPoint;
    try
    {
      fsMountPoint = Platform.getFilesystem(directory);
      fsMountPoint = getMountPoint(directory);
    }
    catch (IOException ioe)
    {
@@ -307,6 +309,28 @@
    }
  }
  private File getMountPoint(File directory) throws IOException
  {
    Path mountPoint = directory.getAbsoluteFile().toPath();
    Path parentDir = mountPoint.getParent();
    FileStore dirFileStore = Files.getFileStore(mountPoint);
    /*
     * Since there is no concept of mount point in the APIs, iterate on all parents of
     * the given directory until the FileSystem Store changes (hint of a different
     * device, hence a mount point) or we get to root, which works too.
     */
    while (parentDir != null)
    {
      if (!Files.getFileStore(parentDir).equals(dirFileStore))
      {
        return mountPoint.toFile();
      }
      mountPoint = mountPoint.getParent();
      parentDir = parentDir.getParent();
    }
    return mountPoint.toFile();
  }
  /**
   * Removes a directory from the set of monitored directories.
   *
opendj-server-legacy/src/main/java/org/opends/server/loggers/MultifileTextWriter.java
@@ -194,8 +194,6 @@
    // Try to apply file permissions.
    if(FilePermission.canSetPermissions())
    {
      try
      {
        if(!FilePermission.setPermissions(file, filePermissions))
@@ -209,7 +207,6 @@
        logger.warn(WARN_LOGGER_SET_PERMISSION_FAILED, file, stackTraceToSingleLineString(e));
      }
    }
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java
@@ -295,11 +295,8 @@
      w.close();
      if (FilePermission.canSetPermissions())
      {
        FilePermission.setPermissions(f, FilePermission.decodeUNIXMode("755"));
      }
    }
    catch (Exception e)
    {
      err.println(ERR_CREATERC_CANNOT_WRITE.get(getExceptionMessage(e)));
opendj-server-legacy/src/main/java/org/opends/server/types/FilePermission.java
@@ -28,15 +28,17 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.core.DirectoryServer;
import com.forgerock.opendj.util.OperatingSystem;
import static org.opends.messages.UtilityMessages.*;
@@ -56,11 +58,6 @@
     mayInvoke=true)
public class FilePermission
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /**
   * The bitmask that should be used for indicating whether a file is
   * readable by its owner.
@@ -133,175 +130,11 @@
  /**
   * Indicates if the Java 7 NIO features can be used, including
   * enhancements to Java 6 {@link java.io.File}.
   */
  private static boolean useNIO;
  /** The {@link java.io.File#toPath} method if it is available. */
  private static Method toPath;
  /**
   * The {@link java.nio.files.Files#setPosixFilePermissions} method if it is
   * available.
   */
  private static Method setPosixFilePermissions;
  /**
   * The {@link java.nio.file.Files#getFileAttributeView} method if it is
   * available.
   */
  private static Method getFileAttributeView;
  /**
   * The {@link java.nio.file.attribute.PosixFilePermissions#fromString} method
   * if it is available.
   */
  private static Method fromString;
  /**
   * The {@link java.nio.file.attribute.PosixFilePermissions#asFileAttribute}
   * method if is available.
   */
  private static Method asFileAttribute;
  /**
   * The {@link java.nio.file.attribute.PosixFileAttributeView} class if it is
   * available.
   */
  private static Class<?> posixView;
  /**
   * The {@link java.nio.file.attribute.AclFileAttributeView} class if it is
   * available.
   */
  private static Class<?> aclView;
  /** The {@link java.nio.file.LinkOption} class if it is available. */
  private static Class<?> linkOption;
  /** The encoded representation for this file permission. */
  private int encodedPermission;
  static
  {
    // Iterate through all the necessary methods and classes in Java 7
    // for dealing with permissions.
    try
    {
      useNIO = false;
      toPath = null;
      setPosixFilePermissions = null;
      getFileAttributeView = null;
      fromString = null;
      asFileAttribute = null;
      posixView = null;
      aclView = null;
      linkOption = null;
      Class<?> c = Class.forName("java.io.File");
      for (Method m : c.getMethods())
      {
        String name = m.getName();
        Class<?>[] argTypes = m.getParameterTypes();
        if (name.equals("toPath") && argTypes.length == 0)
        {
          toPath = m;
        }
      }
      if (toPath == null)
      {
        throw new NoSuchMethodException("java.io.File.toPath");
      }
      c = Class.forName("java.nio.file.attribute.PosixFilePermissions");
      for (Method m : c.getMethods())
      {
        String name = m.getName();
        Class<?>[] argTypes = m.getParameterTypes();
        if (name.equals("fromString") && argTypes.length == 1)
        {
          fromString = m;
        }
        if (name.equals("asFileAttribute") && argTypes.length == 1)
        {
          asFileAttribute = m;
        }
      }
      if (fromString == null)
      {
        throw new NoSuchMethodException(
            "java.nio.file.attribute.PosixFilePermissions.fromString");
      }
      if (asFileAttribute == null) {
        throw new NoSuchMethodException(
            "java.nio.file.attribute.PosixFilePermissions.asFileAttribute");
      }
      c = Class.forName("java.nio.file.Files");
      for (Method m : c.getMethods())
      {
        String name = m.getName();
        Class<?>[] argTypes = m.getParameterTypes();
        if (name.equals("setPosixFilePermissions") && argTypes.length == 2)
        {
          setPosixFilePermissions = m;
        }
        if (name.equals("getFileAttributeView") && argTypes.length == 3)
        {
          getFileAttributeView = m;
        }
      }
      if (setPosixFilePermissions == null)
      {
        throw new NoSuchMethodException(
            "java.nio.file.Files.setPosixFilePermissions");
      }
      if (getFileAttributeView == null)
      {
        throw new NoSuchMethodException(
            "java.nio.file.Files.getFileAttributeView");
      }
      posixView = Class.forName(
          "java.nio.file.attribute.PosixFileAttributeView");
      aclView = Class.forName("java.nio.file.attribute.AclFileAttributeView");
      linkOption = Class.forName("java.nio.file.LinkOption");
      // If we got here, then we have everything we need.
      useNIO = true;
    }
    catch (NoSuchMethodException e)
    {
      logger.traceException(e);
    }
    catch (ClassNotFoundException e)
    {
      logger.traceException(e);
    }
    finally
    {
      // Clean up if we only had partial success.
      if (useNIO == false)
      {
        toPath = null;
        setPosixFilePermissions = null;
        getFileAttributeView = null;
        fromString = null;
        asFileAttribute = null;
        posixView = null;
        aclView = null;
        linkOption = null;
      }
    }
  }
  /**
   * Creates a new file permission object with the provided encoded
   * representation.
@@ -561,32 +394,6 @@
  /**
   * Indicates whether the there is a mechanism available for setting
   * permissions in the underlying filesystem on the current platform.
   *
   * @return  <CODE>true</CODE> if there is a mechanism available for
   *          setting file permissions on the underlying system (e.g.,
   *          if the server is running in a Java 6 environment, or if
   *          this is a UNIX-based system and the use of exec is
   *          allowed), or <CODE>false</CODE> if no such mechanism is
   *          available.
   */
  public static boolean canSetPermissions()
  {
    if (useNIO)
    {
      // It's a Java 7 environment.
      return true;
    }
    // It's a Java 6 environment, so we can always use that
    // mechanism.
    return true;
  }
  /**
   * Attempts to set the given permissions on the specified file.  If
   * the underlying platform does not allow the full level of
   * granularity specified in the permissions, then an attempt will be
@@ -612,311 +419,26 @@
  {
    if (! f.exists())
    {
      LocalizableMessage message =
          ERR_FILEPERM_SET_NO_SUCH_FILE.get(f.getAbsolutePath());
      throw new FileNotFoundException(message.toString());
      throw new FileNotFoundException(ERR_FILEPERM_SET_NO_SUCH_FILE.get(f.getAbsolutePath()).toString());
    }
    // If we're running Java 7 and have NIO available, use that.
    if (useNIO)
    {
      return setUsingJava7(f, p);
    }
    // If we're running Java 6, then we'll use the methods that Java
    // provides.
    return setUsingJava6(f, p);
  }
  /**
   * Attempts to set the specified permissions for the given file or
   * directory using the Java 7 NIO API. This will set the full POSIX
   * permissions on systems supporting POSIX filesystem semantics.
   *
   * @param f The file or directory to which the permissions should be applied.
   * @param p The permissions to apply to the file or directory.
   *
   * @return <code>true</code> if the permissions were successfully updated, or
   *         <code>false</code> if not.
   *
   */
 private static boolean setUsingJava7(File f, FilePermission p)
 {
   try
   {
     // path = f.toPath();
     Object path = toPath.invoke(f);
     // posix = Files.getFileAttributeView(path, posixFileAttributeView.class);
     Object posix = getFileAttributeView.invoke(null, path, posixView,
         Array.newInstance(linkOption, 0));
     // If a POSIX view is available, then set the permissions.
     // NOTE:  Windows 2003, 2008 and 7 (and probably others) don't have POSIX
     //        views.
    Path filePath = f.toPath();
    PosixFileAttributeView posix = Files.getFileAttributeView(filePath, PosixFileAttributeView.class);
     if (posix != null)
     {
       // Build a string like "rwxr-x-w-" from p.
       StringBuilder posixMode = new StringBuilder();
       toPOSIXString(p, posixMode, "", "", "");
       // perms = PosixFilePermissions.fromString(posixMode.toString());
       Object perms = fromString.invoke(null, posixMode.toString());
       // Files.setPosixFilePermissions(path, perms);
       setPosixFilePermissions.invoke(null, path, perms);
      Set<PosixFilePermission> perms = PosixFilePermissions.fromString(posixMode.toString());
      try
      {
        Files.setPosixFilePermissions(filePath, perms);
      }
      catch (UnsupportedOperationException | ClassCastException | IOException | SecurityException ex)
      {
        throw new DirectoryException(ResultCode.OTHER, ERR_FILEPERM_SET_JAVA_EXCEPTION.get(f.getAbsolutePath()), ex);
      }
       return true;
     }
     // acl = Files.getFileAttributeView(path, aclFileAttributeView.class);
     Object acl = getFileAttributeView.invoke(null, path, aclView,
         Array.newInstance(linkOption, 0));
     // If an ACL view is available, then return successfully.
     // This is not ideal, but the intention is the administrator has set up
     // the inherited ACLs "appropriately" so we don't need to do anything.
     //
     // Also ideally we would check ACLs before checking POSIX, in case we have
     // a filesystem like ZFS that can support both.
     if (acl != null)
     {
       return true;
     }
   }
   catch (Exception e)
   {
     logger.traceException(e);
   }
   return false;
 }
  /**
   * Attempts to set the specified permissions for the given file
   * using the Java 6 <CODE>FILE</CODE> API.  Only the "owner" and
   * "other" permissions will be preserved, since Java 6 doesn't provide
   * a way to set the group permissions directly.
   *
   * @param  f  The file to which the permissions should be applied.
   * @param  p  The permissions to apply to the file.
   *
   * @return  <CODE>true</CODE> if the permissions were successfully
   *          updated, or <CODE>false</CODE> if not.
   *
   * @throws  DirectoryException  If a problem occurs while attempting
   *                              to update permissions.
   */
  private static boolean setUsingJava6(File f, FilePermission p)
          throws DirectoryException
  {
    // NOTE:  Due to a very nasty behavior of the Java 6 API, if you
    //        want to want to grant a permission for the owner but not
    //        for anyone else, then you *must* remove it for everyone
    //        first, and then add it only for the owner.  Otherwise,
    //        the other permissions will be left unchanged and if they
    //        had it before then they will still have it.
    boolean anySuccessful   = false;
    boolean anyFailed       = false;
    boolean exceptionThrown = false;
    // Take away read permission from everyone if necessary.
    if (p.isOwnerReadable() && (! p.isOtherReadable()))
    {
      try
      {
        if (f.setReadable(false, false))
        {
          anySuccessful = true;
        }
        else
        {
          if(!DirectoryServer.getOperatingSystem().equals(
              OperatingSystem.WINDOWS))
          {
            // On Windows platforms, file readability permissions
            // cannot be set to false. Do not consider this case
            // a failure. http://java.sun.com/developer/
            // technicalArticles/J2SE/Desktop/javase6/enhancements/
            anyFailed = true;
          }
        }
      }
      catch (Exception e)
      {
        logger.traceException(e);
        exceptionThrown = true;
      }
    }
    // Grant the appropriate read permission.
    try
    {
      boolean ownerOnly =
           (p.isOwnerReadable() != p.isOtherReadable());
      if (f.setReadable(p.isOwnerReadable(), ownerOnly))
      {
        anySuccessful = true;
      }
      else
      {
        if(!DirectoryServer.getOperatingSystem().equals(
            OperatingSystem.WINDOWS) || p.isOwnerReadable())
        {
          // On Windows platforms, file readability permissions
          // cannot be set to false. Do not consider this case
          // a failure. http://java.sun.com/developer/
          // technicalArticles/J2SE/Desktop/javase6/enhancements/
          anyFailed = true;
        }
      }
    }
    catch (Exception e)
    {
      logger.traceException(e);
      exceptionThrown = true;
    }
    // NOTE:  On Windows platforms attempting to call setWritable on a
    //        directory always fails, regardless of parameters. Ignore
    //        these failures.
    boolean ignoreSetWritableFailures =
        (DirectoryServer.getOperatingSystem().equals(
            OperatingSystem.WINDOWS) && f.isDirectory());
    // Take away write permission from everyone if necessary.
    if (p.isOwnerWritable() && (! p.isOtherWritable()))
    {
      try
      {
        if (f.setWritable(false, false))
        {
          anySuccessful = true;
        }
        else if (!ignoreSetWritableFailures)
        {
          anyFailed = true;
        }
      }
      catch (Exception e)
      {
        logger.traceException(e);
        exceptionThrown = true;
      }
    }
    // Grant the appropriate write permission.
    try
    {
      boolean ownerOnly =
           (p.isOwnerWritable() != p.isOtherWritable());
      if (f.setWritable(p.isOwnerWritable(), ownerOnly))
      {
        anySuccessful = true;
      }
      else if (!ignoreSetWritableFailures)
      {
        anyFailed = true;
      }
    }
    catch (Exception e)
    {
      logger.traceException(e);
      exceptionThrown = true;
    }
    // Take away execute permission from everyone if necessary.
    if (p.isOwnerExecutable() && (! p.isOtherExecutable()))
    {
      try
      {
        if (f.setExecutable(false, false))
        {
          anySuccessful = true;
        }
        else
        {
          if(!DirectoryServer.getOperatingSystem().equals(
              OperatingSystem.WINDOWS))
          {
            // On Windows platforms, file execute permissions
            // cannot be set to false. Do not consider this case
            // a failure. http://java.sun.com/developer/
            // technicalArticles/J2SE/Desktop/javase6/enhancements/
            anyFailed = true;
          }
        }
      }
      catch (Exception e)
      {
        logger.traceException(e);
        exceptionThrown = true;
      }
    }
    // Grant the appropriate execute permission.
    try
    {
      boolean ownerOnly =
           (p.isOwnerExecutable() != p.isOtherExecutable());
      if (f.setExecutable(p.isOwnerExecutable(), ownerOnly))
      {
        anySuccessful = true;
      }
      else
      {
        if(!DirectoryServer.getOperatingSystem().equals(
            OperatingSystem.WINDOWS) || p.isOwnerExecutable())
        {
          // On Windows platforms, file execute permissions
          // cannot be set to false. Do not consider this case
          // a failure. http://java.sun.com/developer/
          // technicalArticles/J2SE/Desktop/javase6/enhancements/
          anyFailed = true;
        }
      }
    }
    catch (Exception e)
    {
      logger.traceException(e);
      exceptionThrown = true;
    }
    if (exceptionThrown)
    {
      // If an exception was thrown, we can't be sure whether or not
      // any permissions were updated.
      LocalizableMessage message =
          ERR_FILEPERM_SET_JAVA_EXCEPTION.get(f.getAbsolutePath());
      throw new DirectoryException(ResultCode.OTHER, message);
    }
    else if (anyFailed)
    {
      if (anySuccessful)
      {
        // Some of the file permissions may have been altered.
        LocalizableMessage message = ERR_FILEPERM_SET_JAVA_FAILED_ALTERED.get(
            f.getAbsolutePath());
        throw new DirectoryException(ResultCode.OTHER, message);
      }
      else
      {
        // The file permissions should have been left intact.
        LocalizableMessage message = ERR_FILEPERM_SET_JAVA_FAILED_UNALTERED.get(
            f.getAbsolutePath());
        throw new DirectoryException(ResultCode.OTHER, message);
      }
    }
    else
    {
      return anySuccessful;
    }
    return Files.getFileAttributeView(filePath, AclFileAttributeView.class) != null;
  }
opendj-server-legacy/src/main/java/org/opends/server/util/Platform.java
@@ -36,10 +36,8 @@
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
@@ -48,7 +46,6 @@
import java.lang.reflect.Method;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import static org.opends.messages.UtilityMessages.*;
@@ -114,28 +111,10 @@
    private static Constructor<?> certKeyGenCons, X500NameCons;
    /** Filesystem APIs */
    private static Method FILESYSTEMS_GETSTORES;
    private static Method FILESYSTEMS_PATHSGET;
    private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
    static
    {
      try
      {
        // FileSystem and FileStores APIs were introduced in JDK 7.
        FILESYSTEMS_PATHSGET = Class.forName("java.nio.file.Paths").getMethod("get", String.class, String[].class);
        FILESYSTEMS_GETSTORES = Class.forName("java.nio.file.Files").getMethod(
            "getFileStore", Class.forName("java.nio.file.Path"));
      }
      catch (Exception e)
      {
        FILESYSTEMS_GETSTORES = null;
        FILESYSTEMS_PATHSGET = null;
        logger.warn(WARN_UNABLE_TO_USE_FILESYSTEM_API.get());
      }
      String x509pkg = pkgPrefix + ".x509";
      String certAndKeyGen;
      if (pkgPrefix.equals(IBM_SEC)
@@ -331,16 +310,6 @@
    /**
     * Normalize the data in the specified buffer.
     *
     * @param buffer
     *          The buffer to normalize.
     */
    public abstract void normalize(StringBuilder buffer);
    private long getUsableMemoryForCaching()
    {
      long youngGenSize = 0;
@@ -397,40 +366,6 @@
            .totalMemory())) * 40 / 100;
      }
    }
    private File getFilesystem(File directory) throws IOException
    {
      if (FILESYSTEMS_GETSTORES != null)
      {
        try
        {
          Object dirFStore = FILESYSTEMS_GETSTORES.invoke(null,
              FILESYSTEMS_PATHSGET.invoke(null, directory.getAbsolutePath(), new String[0]));
          File parentDir = directory.getParentFile();
          /*
           * Since there is no concept of mount point in the APIs, iterate on all parents of
           * the given directory until the FileSystem Store changes (hint of a different
           * device, hence a mount point) or we get to root, which works too.
           */
          while (parentDir != null)
          {
            Object parentFStore = FILESYSTEMS_GETSTORES.invoke(null,
                FILESYSTEMS_PATHSGET.invoke(null, parentDir.getAbsolutePath(), new String[0]));
            if (!parentFStore.equals(dirFStore))
            {
              return directory;
            }
            directory = directory.getParentFile();
            parentDir = directory.getParentFile();
          }
        }
        catch (Exception e)
        {
          throw new IOException(e);
        }
      }
      return directory;
    }
  }
@@ -528,57 +463,6 @@
   */
  private static class DefaultPlatformIMPL extends PlatformIMPL
  {
    /** Normalize method. */
    private static final Method NORMALIZE;
    /** Normalized form method. */
    private static final Object FORM_NFKC;
    static
    {
      Method normalize = null;
      Object formNFKC = null;
      try
      {
        Class<?> normalizer = Class.forName("java.text.Normalizer");
        Class<?> normalizerForm = Class.forName("java.text.Normalizer$Form");
        normalize = normalizer.getMethod("normalize", CharSequence.class,
            normalizerForm);
        formNFKC = normalizerForm.getField("NFKD").get(null);
      }
      catch (Exception ex)
      {
        // Do not use Normalizer. The values are already set to null.
      }
      NORMALIZE = normalize;
      FORM_NFKC = formNFKC;
    }
    @Override
    public void normalize(StringBuilder buffer)
    {
      try
      {
        String normal = (String) NORMALIZE.invoke(null, buffer, FORM_NFKC);
        buffer.replace(0, buffer.length(), normal);
      }
      catch (Exception ex)
      {
        // Don't do anything. buffer should be used.
      }
    }
  }
  /**
   * Normalize the specified buffer.
   *
   * @param buffer
   *          The buffer to normalize.
   */
  public static void normalize(StringBuilder buffer)
  {
    IMPL.normalize(buffer);
  }
@@ -625,16 +509,4 @@
  {
    return IMPL.getUsableMemoryForCaching();
  }
  /**
   * Returns the filesystem on which the given directory resides by its mountpoint.
   *
   * @param directory the directory whose filesystem is required
   * @return the filesystem on which the given directory resides
   * @throws IOException The exception in case information on filesystem/storage cannot be found
   */
  public static File getFilesystem(File directory) throws IOException
  {
    return IMPL.getFilesystem(directory);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
@@ -394,7 +394,7 @@
        }
        // Make the shell scripts in the bin directory executable, if possible.
        if (OperatingSystem.isUnixBased() && FilePermission.canSetPermissions())
        if (OperatingSystem.isUnixBased())
        {
          try
          {
opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java
@@ -34,7 +34,6 @@
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.util.Platform;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -240,10 +239,7 @@
  @Test(dataProvider = "testRDNs")
  public void testNormalizationToSafeUrlString(String rawRDN, String normRDN, String stringRDN) throws Exception {
    RDN rdn = RDN.decode(rawRDN);
    StringBuilder buffer = new StringBuilder();
    buffer.append(normRDN);
    Platform.normalize(buffer);
    assertEquals(rdn.toNormalizedUrlSafeString(), buffer.toString());
    assertEquals(rdn.toNormalizedUrlSafeString(), normRDN);
  }