Commons Validator
  1. Commons Validator
  2. VALIDATOR-202

URL Validator isValid method fails with java.lang.ArrayIndexOutOfBoundsException at org.apache.commons.validator.UrlValidator.isValidAuthority(UrlValidator.java:367)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.1 Release
    • Component/s: None
    • Labels:
      None
    • Environment:

      JBOSS Running on Linux

      Description

      Validating the following URL will throw an ArrayIndexOutOfBoundsException exception

      http://www.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.log

      Code:

      String[] schemes =

      {"http","https"}

      .
      UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS) ;
      urlValidator.isValid("http://www.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.log") ;

      1. 202-fix.patch
        0.9 kB
        Henri Yandell
      2. 202-test.patch
        1 kB
        Henri Yandell

        Issue Links

          Activity

          Hide
          Henri Yandell added a comment -

          svn ci -m "Fixing ArrayOutOfBoundsException bug reported in #VALIDATOR-202. This fix is pretty simple - 'Create an array of size # of .s plus one', but the implementation of that isn't very beautiful. "

          Sending src/share/org/apache/commons/validator/UrlValidator.java
          Sending src/test/org/apache/commons/validator/UrlTest.java
          Transmitting file data ..
          Committed revision 453308.

          Show
          Henri Yandell added a comment - svn ci -m "Fixing ArrayOutOfBoundsException bug reported in # VALIDATOR-202 . This fix is pretty simple - 'Create an array of size # of .s plus one', but the implementation of that isn't very beautiful. " Sending src/share/org/apache/commons/validator/UrlValidator.java Sending src/test/org/apache/commons/validator/UrlTest.java Transmitting file data .. Committed revision 453308.
          Hide
          Henri Yandell added a comment -

          See VALIDATOR-203 for Jira issue to RECODE ME.

          Show
          Henri Yandell added a comment - See VALIDATOR-203 for Jira issue to RECODE ME.
          Hide
          Henri Yandell added a comment -

          ArrayList seemed like a 'doh' moment, but digging into it it's a bit of a pain to code.
          You can't use set as you have to use add the first time in an ArrayList; so the code would need a large change.

          When I was looking at this class there were a number of bits that were jumping up and down saying "RECODE ME!",
          so I'm going to apply the two patches above to get the bug fixed in the nightly build tonight and then I'll look into rewriting things a bit.
          ArrayList would work fine if the code was changed from set(..) to add(..) semantics, but I also think the whole thing could be simplified.

          Show
          Henri Yandell added a comment - ArrayList seemed like a 'doh' moment, but digging into it it's a bit of a pain to code. You can't use set as you have to use add the first time in an ArrayList; so the code would need a large change. When I was looking at this class there were a number of bits that were jumping up and down saying "RECODE ME!", so I'm going to apply the two patches above to get the bug fixed in the nightly build tonight and then I'll look into rewriting things a bit. ArrayList would work fine if the code was changed from set(..) to add(..) semantics, but I also think the whole thing could be simplified.
          Hide
          Ben added a comment -

          Please ignore the previous comment as to where I can get the fix. I did not see the attached patch file.

          Show
          Ben added a comment - Please ignore the previous comment as to where I can get the fix. I did not see the attached patch file.
          Hide
          Ben added a comment -

          How can I get your fix?

          Also you can always use an ArrayList instead of fixed size array so it wont seem so hacky.

          Show
          Ben added a comment - How can I get your fix? Also you can always use an ArrayList instead of fixed size array so it wont seem so hacky.
          Hide
          Henri Yandell added a comment -

          Problem is that in that method an array of fixed size 10 is created. The patch resolves this by making the size of the array be the number of '.'s in the hostIP + 1.

          Seems hacky

          Show
          Henri Yandell added a comment - Problem is that in that method an array of fixed size 10 is created. The patch resolves this by making the size of the array be the number of '.'s in the hostIP + 1. Seems hacky
          Hide
          Henri Yandell added a comment -

          Unit test.

          Show
          Henri Yandell added a comment - Unit test.
          Hide
          Ben added a comment -

          Using commons-validator-1.3.0.jar - Version 1.3.0 of commons validator

          Show
          Ben added a comment - Using commons-validator-1.3.0.jar - Version 1.3.0 of commons validator

            People

            • Assignee:
              Henri Yandell
              Reporter:
              Ben
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development