java.lang.StringIndexOutOfBoundsException

tip

Thrown by String methods to indicate that an index is either negative or greater than the size of the string. For some methods such as the charAt method, this exception also is thrown when the index is equal to the size of the string.


rafaelrafael

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • I'm using the Spring Framework libraries. -------------------------------------------------------------------------- 1. Spring Boot 1.1.8.RELEASE 1-1. org.springframework.boot:spring-boot-starter-amqp:jar:1.1.8.RELEASE 1-2. org.springframework.boot:spring-boot-starter-websocket:jar:1.1.8.RELEASE 2. org.springframework:spring-messaging:jar:4.0.7.RELEASE 3. org.projectreactor:reactor-net:jar:1.1.4.RELEASE (for StompBrokerRelay) -------------------------------------------------------------------------- I referneced http://assets.spring.io/wp/WebSocketBlogPost.html but I'm using the "Apache ActiveMQ 5.10.0" and configured Stomp Broker Relay. My Application publishing stomp messages to client 5 ~ 30 messages per second. each message has 300 ~ 700 bytes length of payload. I meet "StringIndexOutOfBoundsException" irregularly. and after connection is closed. stacktrace is below. -------------------------------------------------------------------------- java.lang.StringIndexOutOfBoundsException: String index out of range: 3 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) at org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:99) at org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:68) at org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:96) at org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:83) at reactor.net.AbstractNetChannel.read(AbstractNetChannel.java:214) at reactor.net.netty.NettyNetChannelInboundHandler.passToConnection(NettyNetChannelInboundHandler.java:105) at reactor.net.netty.NettyNetChannelInboundHandler.channelRead(NettyNetChannelInboundHandler.java:69) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:507) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:464) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at java.lang.Thread.run(Thread.java:745) -------------------------------------------------------------------------- so, I debug the StompDecoder.java (4.0.7.RELEASE source) and I found out the StompDecoder.unescape() method throws the StringIndexOutOfBoundsException when message header value end with "\". (in my case "message-id" value exactly) Messages that caused the exception are like below. CASE #1) ---------------------------------------------------- content-type:application/json;charset=UTF-8 message-id:ID\ 095041.588 ERROR 20569 --- [eactor-tcp-io-4] reactor.core.Reactor : String index out of range: 3 java.lang.StringIndexOutOfBoundsException: String index out of range: 3 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) ... same stack trace... CASE #2) ---------------------------------------------------- content-type:application/json;charset=UTF-8 message-id:ID\cktpdevGW-39005-1415095980735-2\c882\c-1\c1\ 095056.596 ERROR 20569 --- [eactor-tcp-io-3] reactor.core.Reactor : String index out of range: 47 java.lang.StringIndexOutOfBoundsException: String index out of range: 47 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) ... same stack trace... CASE #3) ---------------------------------------------------- content-type:application/json;charset=UTF-8 message-id:ID\cktpdevGW-39005-1415095980735-2\c882\ 101513.253 ERROR 20569 --- [eactor-tcp-io-4] reactor.core.Reactor : String index out of range: 40 java.lang.StringIndexOutOfBoundsException: String index out of range: 40 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) ... same stack trace... every case of messages are ended with "\" character. that messages are looks like incomplete message from the network. this exception happens on localhost (127.0.0.1 loopback)
    via by Sang-hyun Lee,
  • I'm using the Spring Framework libraries. -------------------------------------------------------------------------- 1. Spring Boot 1.1.8.RELEASE 1-1. org.springframework.boot:spring-boot-starter-amqp:jar:1.1.8.RELEASE 1-2. org.springframework.boot:spring-boot-starter-websocket:jar:1.1.8.RELEASE 2. org.springframework:spring-messaging:jar:4.0.7.RELEASE 3. org.projectreactor:reactor-net:jar:1.1.4.RELEASE (for StompBrokerRelay) -------------------------------------------------------------------------- I referneced http://assets.spring.io/wp/WebSocketBlogPost.html but I'm using the "Apache ActiveMQ 5.10.0" and configured Stomp Broker Relay. My Application publishing stomp messages to client 5 ~ 30 messages per second. each message has 300 ~ 700 bytes length of payload. I meet "StringIndexOutOfBoundsException" irregularly. and after connection is closed. stacktrace is below. -------------------------------------------------------------------------- java.lang.StringIndexOutOfBoundsException: String index out of range: 3 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) at org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:99) at org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:68) at org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:96) at org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:83) at reactor.net.AbstractNetChannel.read(AbstractNetChannel.java:214) at reactor.net.netty.NettyNetChannelInboundHandler.passToConnection(NettyNetChannelInboundHandler.java:105) at reactor.net.netty.NettyNetChannelInboundHandler.channelRead(NettyNetChannelInboundHandler.java:69) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:507) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:464) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at java.lang.Thread.run(Thread.java:745) -------------------------------------------------------------------------- so, I debug the StompDecoder.java (4.0.7.RELEASE source) and I found out the StompDecoder.unescape() method throws the StringIndexOutOfBoundsException when message header value end with "\". (in my case "message-id" value exactly) Messages that caused the exception are like below. CASE #1) ---------------------------------------------------- content-type:application/json;charset=UTF-8 message-id:ID\ 095041.588 ERROR 20569 --- [eactor-tcp-io-4] reactor.core.Reactor : String index out of range: 3 java.lang.StringIndexOutOfBoundsException: String index out of range: 3 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) ... same stack trace... CASE #2) ---------------------------------------------------- content-type:application/json;charset=UTF-8 message-id:ID\cktpdevGW-39005-1415095980735-2\c882\c-1\c1\ 095056.596 ERROR 20569 --- [eactor-tcp-io-3] reactor.core.Reactor : String index out of range: 47 java.lang.StringIndexOutOfBoundsException: String index out of range: 47 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) ... same stack trace... CASE #3) ---------------------------------------------------- content-type:application/json;charset=UTF-8 message-id:ID\cktpdevGW-39005-1415095980735-2\c882\ 101513.253 ERROR 20569 --- [eactor-tcp-io-4] reactor.core.Reactor : String index out of range: 40 java.lang.StringIndexOutOfBoundsException: String index out of range: 40 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123) ... same stack trace... every case of messages are ended with "\" character. that messages are looks like incomplete message from the network. this exception happens on localhost (127.0.0.1 loopback)
    via by Sang-hyun Lee,
  • IOOBE
    via GitHub by meysholdt
    ,
  • Exception error
    via GitHub by dawe
    ,
    • java.lang.StringIndexOutOfBoundsException: String index out of range: 47 at java.lang.String.charAt(String.java:658) at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221) at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197) at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123)

    Users with the same issue

    poroszdporoszd
    12 times, last one,
    olle.hallinolle.hallin
    1 times, last one,
    linxiaolonglinxiaolong
    1 times, last one,
    jokesterjokester
    1 times, last one,
    tyson925tyson925
    1 times, last one,
    30 more bugmates