Uploaded image for project: 'Commons Validator'
  1. Commons Validator
  2. VALIDATOR-391

UrlValidator.isValid throws exception for FILEURLs

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.0
    • 1.6
    • Routines

    Description

      In UrlValidator.java from v1.5.0, there is the following section which generates a null pointer exception, rendering isValid unusable for FILE URLs.

      org/apache/commons/validator/routines/UrlValidator.java
      if ("file".equals(scheme)) {// Special case - file: allows an empty authority
                  if (!"".equals(authority)) {
                      if (authority.contains(":")) { // but cannot allow trailing :
                          return false;
                      }
                  }
                  // drop through to continue validation
              }
      

      In the case of a file URL given in my example below, authority is null, and thusly doesn't equal a blank string, so it drops down and calls authority.contains, which generates a NullPointerException.

      Example to generate exception
      File localFile = new File("c:\\path\\to\\dir\\");
      URL localURL = localFile.toURI().toURL();
      String urlString = localURL.toString(); // "file:/C:/path/to/dir/"
      String[] schemes = {"file"};
      UrlValidator urlValidator = new UrlValidator(schemes);
      
      urlValidator.isValid(urlString); // null pointer exception
      

      Attachments

        1. UrlValidator.java.patch
          0.7 kB
          Jason Loomis
        2. UrlValidatorTest.java.patch
          0.8 kB
          Jason Loomis

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            mark_scott_jr Mark E. Scott, Jr.
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment