• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • None

      Since Hudson 1.357 this function will fail:

      private String getFullPath(FilePath fp) {
      FilePath parent = fp;
      String path = "";
      try {
      while (parent.exists())

      { path = parent.getName() + File.separator + path; parent = parent.getParent(); path = File.separator + path; }

      } catch (IOException ex)

      { Logger.getLogger(UpdateMatrixProperty.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(UpdateMatrixProperty.class.getName()).log(Level.SEVERE, null, ex); }

      return path;
      }
      with this error on the "parent = parent.getParent();" line:

      FATAL: String index out of range: -1

          [JENKINS-6494] FilePath broken since 1.357

          Alan Harder added a comment -

          probably related to JENKINS-5951

          Alan Harder added a comment - probably related to JENKINS-5951

          emanuelez added a comment -

          I'm not sure about that. It was working fine up to version 1.356.
          Tomorrow I will try to debug and see what (and when) goes wrong.

          emanuelez added a comment - I'm not sure about that. It was working fine up to version 1.356. Tomorrow I will try to debug and see what (and when) goes wrong.

          Alan Harder added a comment -

          Here's what changed:
          before 1.357, the last getParent() call would end up with a FilePath for "" (empty string), and exists() would return false.
          in 1.357, the last getParent() call gets a FilePath for "." and exists() returns true.. so it tries one more getParent() call which gets the IndexOutOfBoundsException. getParent() has always had this problem that if you call it enough times you get IOOBE.

          So I'll fix getParent() to match what File.getParentFile() does.. parent of /foo should be "/" (not ".") and parent of "/" should be null, not IOOBE.

          But one question: why do you need this function? why not use fp.getRemote() or fp.absolutize().getRemote() ?

          Alan Harder added a comment - Here's what changed: before 1.357, the last getParent() call would end up with a FilePath for "" (empty string), and exists() would return false. in 1.357, the last getParent() call gets a FilePath for "." and exists() returns true.. so it tries one more getParent() call which gets the IndexOutOfBoundsException. getParent() has always had this problem that if you call it enough times you get IOOBE. So I'll fix getParent() to match what File.getParentFile() does.. parent of /foo should be "/" (not ".") and parent of "/" should be null, not IOOBE. But one question: why do you need this function? why not use fp.getRemote() or fp.absolutize().getRemote() ?

          Code changed in hudson
          User: : mindless
          Path:
          trunk/hudson/main/core/src/main/java/hudson/FilePath.java
          trunk/hudson/main/core/src/test/java/hudson/FilePathTest.java
          trunk/www/changelog.html
          http://jenkins-ci.org/commit/30917
          Log:
          [FIXED JENKINS-6494] fix FilePath.getParent() so parent of /foo is /
          (not "."), and handle edge case so path with no parent ("/" or "abc")
          returns null instead of getting IndexOutOfBoundsException.
          (returning null is consistent with File.getParentFile())

          SCM/JIRA link daemon added a comment - Code changed in hudson User: : mindless Path: trunk/hudson/main/core/src/main/java/hudson/FilePath.java trunk/hudson/main/core/src/test/java/hudson/FilePathTest.java trunk/www/changelog.html http://jenkins-ci.org/commit/30917 Log: [FIXED JENKINS-6494] fix FilePath.getParent() so parent of /foo is / (not "."), and handle edge case so path with no parent ("/" or "abc") returns null instead of getting IndexOutOfBoundsException. (returning null is consistent with File.getParentFile())

          Alan Harder added a comment -

          Note: I believe this is the correct fix, but your code above still will not work.. parent of "/foo" will be "/" and thus parent.exists() will still be true. The next getParent() will be null. I recommend using fp.getRemote() or fp.absolutize().getRemote(), or refactoring your code. Thanks!

          Alan Harder added a comment - Note: I believe this is the correct fix, but your code above still will not work.. parent of "/foo" will be "/" and thus parent.exists() will still be true. The next getParent() will be null. I recommend using fp.getRemote() or fp.absolutize().getRemote(), or refactoring your code. Thanks!

          emanuelez added a comment -

          That is more or less what I was asking to the person who wrote the function
          Thank you very much.

          emanuelez added a comment - That is more or less what I was asking to the person who wrote the function Thank you very much.

            mindless Alan Harder
            emanuelez emanuelez
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: