title: Is it ever possible for the getPath method of a java.net.URI object to return null? (If so, when?)
body: <p>According to the <a href="http://docs.oracle.com/javase/7/docs/api/java/net/URI.html#getPath%28%29">URI javadoc</a> the <code>getPath</code> method returns "the decoded path component of this URI, <strong>or null if the path is undefined</strong>" (emphasis added). This would lead me to believe that if my application relies on the return value of <code>getPath</code>, I might need to check if it is <code>null</code>. However, it seems that this can never happen. </p>
  
  <p>The following code shows my attempts to construct a <code>URI</code> object for which <code>getPath</code> returns null, but as you can see, I have not yet found such a case. Could someone please explain how this might happen?</p>
  
  <p><strong>EDIT: It has come to my attention that a <code>mailto</code> URI does not have a path.</strong> However, what I am really asking is: Can there be a URI that uses http, https, ftp, or file scheme that has an undefined/null path?</p>
  
  <pre><code>import java.net.URI;
  import java.net.URISyntaxException;
  
  public class URIGetPathNullTest {
  
      public static void main(String []args) throws Exception {
          test1();
          test2();
          test3();
          test4();
          test5();
          test6();
          test7();
      }
  
  
      public static void test1() throws URISyntaxException {
          String urlString = "";
          URI uri = new URI(urlString);
          printUri(uri); 
          // Output:
          //  toString() --&gt; 
          //  getPath --&gt; 
          //  getPath null? false         
      }
  
      public static void test2() throws URISyntaxException{
          String scheme = null;
          String ssp = null;
          String fragment = null;
          URI uri = new URI(
                  scheme,
                  ssp,
                  fragment
              );
          printUri(uri);       
          // Output:
          //  toString() --&gt; 
          //  getPath --&gt; 
          //  getPath null? false
      }
  
      public static void test3() throws URISyntaxException {
          String scheme = null;
          String userInfo = null;
          String host = null;
          int port = -1;
          String path = null;
          String query = null;
          String fragment = null;
          URI uri = new URI(
                  scheme,
                  userInfo,
                  host,
                  port,
                  path,
                  query,
                  fragment             
              );
          printUri(uri);       
          // Output:
          //  toString() --&gt; 
          //  getPath --&gt; 
          //  getPath null? false
  
      }
  
      public static void test4() throws URISyntaxException {
          String scheme = null;
          String host = null;
          String path = null;
          String fragment = null;
          URI uri = new URI(
                  scheme,
                  host,
                  path,
                  fragment             
              );
          printUri(uri);       
          // Output:
          //  toString() --&gt; 
          //  getPath --&gt; 
          //  getPath null? false
      }
  
      public static void test5() throws URISyntaxException {
          String scheme = null;
          String authority = null;
          String path = null;
          String query = null;
          String fragment = null;
          URI uri = new URI(
                  scheme,
                  authority,
                  path,
                  query,
                  fragment             
              );
          printUri(uri);       
          // Output:
          //  toString() --&gt; 
          //  getPath --&gt; 
          //  getPath null? false
      }
  
      public static void test6() throws URISyntaxException {
          String urlString = "?some-query";
          URI uri = new URI(urlString);
          printUri(uri); 
          // Output:
          //  toString() --&gt; ?some-query
          //  getPath --&gt; 
          //  getPath null? false         
      }
  
      public static void test7() throws URISyntaxException {
          String urlString = "#some-fragment";
          URI uri = new URI(urlString);
          printUri(uri); 
          // Output:
          //  toString() --&gt; #some-fragment
          //  getPath --&gt; 
          //  getPath null? false         
      }
  
      public static void printUri(URI uri) {
          System.out.println("toString() --&gt; " + uri.toString());
          System.out.println("getPath --&gt; " + uri.getPath());
          System.out.println("getPath null? " + (uri.getPath() == null));
      }
  }
  </code></pre>