title: Replacement or way of using ShellFolder.getShellFolder() on Java 11
body: <p>I'm currently using <em>ShellFolder.getShellFolder()</em> to determine if a particular path is on a local drive (directly connected to Windows machine) or a remote drive.</p>
  <pre><code>package com.jthink.songkong.analyse.analyser;
  
  import com.jthink.songkong.analyse.filename.WindowsFileSystem;
  import com.jthink.songkong.ui.MainWindow;
  import sun.awt.shell.ShellFolder;
  import sun.awt.shell.ShellFolderColumnInfo;
  
  import java.io.IOException;
  import java.nio.file.FileStore;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.util.logging.Level;
  
  /**
   * Only Windows can load these methods because of reliance on sun classes
   *
   */
  public class WindowsFilesystemType
  {
  
      public static final String WINDOWS_SHELL_ATTRIBUTES = &quot;Attributes&quot;;
      public static final String WINDOWS_SHELL_ITEM_TYPE = &quot;Item type&quot;;
      public static final String WINDOWS_SHELL_SIZE = &quot;Size&quot;;
      /**
       * Is Windows NTFS or FAT32
       *
       * @param newPath
       * @return
       */
      public static boolean isNTFSOrFAT32(String newPath)
      {
          Path root = Paths.get(newPath).getRoot();
          if (root == null)
          {
              return false;
          }
          try
          {
              FileStore fs = Files.getFileStore(root);
              if (fs.type().equals(WindowsFileSystem.NTFS)
                      || fs.type().equals(WindowsFileSystem.FAT)
                      || fs.type().equals(WindowsFileSystem.FAT32)
                      || fs.type().equals(WindowsFileSystem.EX_FAT))
              {
                  return true;
              }
              return false;
          }
          catch (IOException ex)
          {
              MainWindow.logger.log(Level.SEVERE, ex.getMessage(), ex);
              return false;
          }
      }
  
      /**
       * Is this a remote drive, only works for Windows because relies on underlying Windows code
       *
       * @param newPath
       *
       * @return true if this a remote (Network) drive
       */
      public static boolean isRemote(String newPath)
      {
          try
          {
              Path root = Paths.get(newPath).getRoot();
              ShellFolder shellFolder = ShellFolder.getShellFolder(root.toFile());
              ShellFolderColumnInfo[] cols = shellFolder.getFolderColumns();
              for (int i = 0; i &lt; cols.length; i++)
              {
                  if (cols[i].getTitle().equals(WINDOWS_SHELL_SIZE)
                          &amp;&amp;  ((String) shellFolder.getFolderColumnValue(i)).startsWith(WindowsShellFileSystemType.NETWORK_DRIVE))
                  {
                      return true;
                  }
                  else if (cols[i].getTitle().equals(WINDOWS_SHELL_ATTRIBUTES)
                          &amp;&amp;  ((String) shellFolder.getFolderColumnValue(i)).startsWith(&quot;\\&quot;))
                  {
                      return true;
                  }
              }
          }
          catch (Exception ex)
          {
              return false;
          }
          return false;
      }
  
      /**
       * Is this a local drive, only works for Windows because relies on underlying Windows code
       *
       * @param newPath
       *
       * @return true if this a local drive
       */
      public static boolean isLocal(String newPath)
      {
          try
          {
              Path root = Paths.get(newPath).getRoot();
              ShellFolder shellFolder = ShellFolder.getShellFolder(root.toFile());
              ShellFolderColumnInfo[] cols = shellFolder.getFolderColumns();
              for (int i = 0; i &lt; cols.length; i++)
              {
                  if (cols[i].getTitle().equals(WINDOWS_SHELL_SIZE)
                          &amp;&amp;  ((String) shellFolder.getFolderColumnValue(i)).startsWith(WindowsShellFileSystemType.LOCAL_DISK))
                  {
                      return true;
                  }
                  else if (cols[i].getTitle().equals(WINDOWS_SHELL_ATTRIBUTES)
                          &amp;&amp;  ((String) shellFolder.getFolderColumnValue(i)).startsWith(&quot;\\&quot;))
                  {
                      return false;
                  }
              }
          }
          catch (Exception ex)
          {
              return true;
          }
          return true;
      }
  
  }
  </code></pre>
  <p>This works fine on Java 8</p>
  <p>I am now moving to Java 11, I am using maven to compile the project and if I increase the <em>source</em> parameter for compiler from <strong>8</strong> to <strong>9</strong> (or above)</p>
  <pre><code>&lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.8.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;encoding&gt;UTF-8&lt;/encoding&gt;
                      &lt;compilerVersion&gt;11&lt;/compilerVersion&gt;
                      &lt;source&gt;8&lt;/source&gt;
                      &lt;target&gt;11&lt;/target&gt;
                      &lt;verbose&gt;true&lt;/verbose&gt;
                      &lt;fork&gt;true&lt;/fork&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  </code></pre>
  <p>I get compile failure (keeping at 8 and setting target to 11 is okay) because of the introduction of the module system</p>
  <pre><code>[ERROR] COMPILATION ERROR :
  [INFO] -------------------------------------------------------------
  [ERROR] c:\Code\jthink\SongKong\src\main\java\com\jthink\songkong\analyse\analyser\WindowsFilesystemType.java:[5,14] error: package sun.awt.shell is not visible
    (package sun.awt.shell is declared in module java.desktop, which does not export it)
  [ERROR] c:\Code\jthink\SongKong\src\main\java\com\jthink\songkong\analyse\analyser\WindowsFilesystemType.java:[6,14] error: package sun.awt.shell is not visible
    (package sun.awt.shell is declared in module java.desktop, which does not export it)
  [INFO] 2 errors
  </code></pre>
  <p>So I am looking for an alternative way to this, either:</p>
  <ol>
  <li>Is there way a way to set src to 11 and allow compile by utilising some module option</li>
  <li>Preferably can I reliably detect if local or remote drive using standard java libs</li>
  </ol>
  <p>The reason I need is isLocal() is my program renames files and there is an option for the user to restrict path length to 259 characters because longer lengths cause problems for Windows Explorer, but if they are modifying a remote drive then not usual to enforce this requirement, I will add more detail to question.</p>
  <p>For example the application renames music files if they are on local drive to be used by Windows then they may want to enforce that limit. But if it is a networked drive they probably will not because quite often the files are stored on a Nas and they are only accessing the files via Windows because my application can run on Windows but not on the Nas.</p>