java.lang.StringIndexOutOfBoundsException: String index out of range: -1

Jenkins JIRA | dmclaren | 7 years ago
  1. 0

    I am trying to use the M2Release plugin, but have encountered a problem which appears to be related to the format of my version strings which are of the form n-SNAPSHOT which result in a release number of 'n'. When I 'Perform Maven Release' I get as far as pushing the 'Schedule Maven Release Build' button after which nothing much happens. In the log I get the following exception: ================================================================================ ====================== 20-Jul-2009 11:10:48 hudson.ExpressionFactory2$JexlExpression evaluate WARNING: Caught exception evaluating: it.computeNextVersion(m.version). Reason: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1768) at org.jvnet.hudson.plugins.m2release.M2ReleaseAction.computeNextVersion (M2ReleaseAction.java:100) at sun.reflect.GeneratedMethodAccessor886.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.commons.jexl.util.introspection.UberspectImpl$VelMethodImpl.invoke (UberspectImpl.java:258) at org.apache.commons.jexl.parser.ASTMethod.execute(ASTMethod.java:104) at org.apache.commons.jexl.parser.ASTReference.execute (ASTReference.java:83) at org.apache.commons.jexl.parser.ASTReference.value (ASTReference.java:57) at org.apache.commons.jexl.parser.ASTReferenceExpression.value (ASTReferenceExpression.java:51) ================================================================================ ====================== I believe that line 100 in the following extract from the code from M2ReleaseAction.java is the point of failure, and is actually redundant. If I read this correctly then with a release version of the form 'n' the 'lastIndexOf' at line 88 will return -1. This will result in the 'else; path being taken and at line 100 substring will be called with the parameters 0 and -1 which throws the exception. Even if it did not thrown and exception the retVal returned from the the substring is ignored. I believe that the removal of line 100 would resolve the problem. 84 public String computeNextVersion(String version) { 85 /// XXX would be nice to use maven to do this... 86 String retVal = computeReleaseVersion(version); 87 // get the integer after the last "." 88 int dotIdx = retVal.lastIndexOf('.'); 89 if (dotIdx != -1) { 90 dotIdx++; 91 String ver = retVal.substring(dotIdx); 92 int intVer = Integer.parseInt(ver); 93 intVer += 1; 94 retVal = retVal.substring(0, dotIdx); 95 retVal = retVal + intVer; 96 } 97 else { 98 int intVer = Integer.parseInt(retVal); 99 intVer += 1; 100 retVal = retVal.substring(0, dotIdx); 101 retVal = Integer.toString(intVer); 102 } 103 return retVal + "-SNAPSHOT"; //$NON-NLS-1$ 104 }

    Jenkins JIRA | 7 years ago | dmclaren
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
  2. 0

    I am trying to use the M2Release plugin, but have encountered a problem which appears to be related to the format of my version strings which are of the form n-SNAPSHOT which result in a release number of 'n'. When I 'Perform Maven Release' I get as far as pushing the 'Schedule Maven Release Build' button after which nothing much happens. In the log I get the following exception: ================================================================================ ====================== 20-Jul-2009 11:10:48 hudson.ExpressionFactory2$JexlExpression evaluate WARNING: Caught exception evaluating: it.computeNextVersion(m.version). Reason: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1768) at org.jvnet.hudson.plugins.m2release.M2ReleaseAction.computeNextVersion (M2ReleaseAction.java:100) at sun.reflect.GeneratedMethodAccessor886.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.commons.jexl.util.introspection.UberspectImpl$VelMethodImpl.invoke (UberspectImpl.java:258) at org.apache.commons.jexl.parser.ASTMethod.execute(ASTMethod.java:104) at org.apache.commons.jexl.parser.ASTReference.execute (ASTReference.java:83) at org.apache.commons.jexl.parser.ASTReference.value (ASTReference.java:57) at org.apache.commons.jexl.parser.ASTReferenceExpression.value (ASTReferenceExpression.java:51) ================================================================================ ====================== I believe that line 100 in the following extract from the code from M2ReleaseAction.java is the point of failure, and is actually redundant. If I read this correctly then with a release version of the form 'n' the 'lastIndexOf' at line 88 will return -1. This will result in the 'else; path being taken and at line 100 substring will be called with the parameters 0 and -1 which throws the exception. Even if it did not thrown and exception the retVal returned from the the substring is ignored. I believe that the removal of line 100 would resolve the problem. 84 public String computeNextVersion(String version) { 85 /// XXX would be nice to use maven to do this... 86 String retVal = computeReleaseVersion(version); 87 // get the integer after the last "." 88 int dotIdx = retVal.lastIndexOf('.'); 89 if (dotIdx != -1) { 90 dotIdx++; 91 String ver = retVal.substring(dotIdx); 92 int intVer = Integer.parseInt(ver); 93 intVer += 1; 94 retVal = retVal.substring(0, dotIdx); 95 retVal = retVal + intVer; 96 } 97 else { 98 int intVer = Integer.parseInt(retVal); 99 intVer += 1; 100 retVal = retVal.substring(0, dotIdx); 101 retVal = Integer.toString(intVer); 102 } 103 return retVal + "-SNAPSHOT"; //$NON-NLS-1$ 104 }

    Jenkins JIRA | 7 years ago | dmclaren
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
  3. 0

    Getting StringIndexOutOfBounds exception with Progress Database

    Stack Overflow | 5 years ago | user954419
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    ArrayOutofBound Exception not caught

    Stack Overflow | 5 years ago | Monojeet Nayak
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
  6. 0

    How do i disable proxy injection (or hta?) mode using beta 2

    Google Groups | 8 years ago | Dubya
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1

  1. richard77 2 times, last 1 day ago
  2. kjhdofjosvs 2 times, last 5 days ago
  3. archenroot 17 times, last 2 weeks ago
  4. Alexandru Popa 2 times, last 3 weeks ago
  5. poroszd 3 times, last 4 weeks ago
18 more registered users
58 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.StringIndexOutOfBoundsException

    String index out of range: -1

    at java.lang.String.substring()
  2. Java RT
    String.substring
    1. java.lang.String.substring(String.java:1768)
    1 frame
  3. org.jvnet.hudson
    M2ReleaseAction.computeNextVersion
    1. org.jvnet.hudson.plugins.m2release.M2ReleaseAction.computeNextVersion(M2ReleaseAction.java:100)
    1 frame
  4. Java RT
    Method.invoke
    1. sun.reflect.GeneratedMethodAccessor886.invoke(Unknown Source)
    2. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    3. java.lang.reflect.Method.invoke(Method.java:585)
    3 frames