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

Spring JIRA | Patchee | 4 years ago
  1. 0

    In certain cases where the value is similar to the delimiter with a length more than 1, the isDelimiter method may incorrectly detect the delimiter. For example having a delimiter "==-==" Here are the following outcomes Test1: "John==-==A==-==Doe" => [John, A, Doe] Test2: "John==-====-==Doe" => [John, , Doe] Test3: "John==-==-==-==Doe" => java.lang.StringIndexOutOfBoundsException: String index out of range: -2 at java.lang.String.<init>(String.java:197) at org.springframework.batch.item.file.transform.DelimitedLineTokenizer.doTokenize(DelimitedLineTokenizer.java:163) at org.springframework.batch.item.file.transform.AbstractLineTokenizer.tokenize(AbstractLineTokenizer.java:111) at BatchTest.test3(BatchTest.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) I have attached an not so glamorous JUnit file demonstrating this and a solution as well. I'm not sure if the solution has other consequences on other parts, so anyone wishing to use this YMMV. Love Spring Batch!! Keep up the great work guys!!

    Spring JIRA | 4 years ago | Patchee
    java.lang.StringIndexOutOfBoundsException: String index out of range: -2
  2. 0

    In certain cases where the value is similar to the delimiter with a length more than 1, the isDelimiter method may incorrectly detect the delimiter. For example having a delimiter "==-==" Here are the following outcomes Test1: "John==-==A==-==Doe" => [John, A, Doe] Test2: "John==-====-==Doe" => [John, , Doe] Test3: "John==-==-==-==Doe" => java.lang.StringIndexOutOfBoundsException: String index out of range: -2 at java.lang.String.<init>(String.java:197) at org.springframework.batch.item.file.transform.DelimitedLineTokenizer.doTokenize(DelimitedLineTokenizer.java:163) at org.springframework.batch.item.file.transform.AbstractLineTokenizer.tokenize(AbstractLineTokenizer.java:111) at BatchTest.test3(BatchTest.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) I have attached an not so glamorous JUnit file demonstrating this and a solution as well. I'm not sure if the solution has other consequences on other parts, so anyone wishing to use this YMMV. Love Spring Batch!! Keep up the great work guys!!

    Spring JIRA | 4 years ago | Patchee
    java.lang.StringIndexOutOfBoundsException: String index out of range: -2
  3. 0

    GitHub comment 9125#254231197

    GitHub | 2 months ago | Danny-Hazelcast
    com.hazelcast.nio.serialization.HazelcastSerializationException: Problem while reading DataSerializable, namespace: 0, id: 7, class: 'null', exception: String index out of range: -2
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    hz 3.8-SNAPSHOT members fail to form cluster / return from creating instance

    GitHub | 2 months ago | Danny-Hazelcast
    com.hazelcast.nio.serialization.HazelcastSerializationException: Problem while reading DataSerializable, namespace: 0, id: 7, class: 'null', exception: String index out of range: -2
  6. 0

    Hyperlink over line comments throws "StringIndexOutOfBoundsException"

    Eclipse Bugzilla | 2 years ago | michal.n
    java.lang.StringIndexOutOfBoundsException: String index out of range: -2

  1. adawolfs 2 times, last 5 months ago
  2. bpbhat77 1 times, last 7 months ago
3 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: -2

    at java.lang.String.<init>()
  2. Java RT
    String.<init>
    1. java.lang.String.<init>(String.java:197)
    1 frame
  3. Spring Batch Infrastructure
    AbstractLineTokenizer.tokenize
    1. org.springframework.batch.item.file.transform.DelimitedLineTokenizer.doTokenize(DelimitedLineTokenizer.java:163)
    2. org.springframework.batch.item.file.transform.AbstractLineTokenizer.tokenize(AbstractLineTokenizer.java:111)
    2 frames
  4. Unknown
    BatchTest.test3
    1. BatchTest.test3(BatchTest.java:36)
    1 frame
  5. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:601)
    4 frames
  6. JUnit
    ParentRunner.run
    1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    5. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    6. org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    7. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    8. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    9. org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    10. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    11. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    12. org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    13. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    14. org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    14 frames
  7. JUnit4 Runner
    JUnit4TestReference.run
    1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    1 frame
  8. JUnit3 Runner
    RemoteTestRunner.main
    1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    5 frames