java.lang.StringIndexOutOfBoundsException: String index out of range: 3

Spring JIRA | Sang-hyun Lee | 2 years ago
  1. 0

    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)

    Spring JIRA | 2 years ago | Sang-hyun Lee
    java.lang.StringIndexOutOfBoundsException: String index out of range: 3
  2. 0

    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)

    Spring JIRA | 2 years ago | Sang-hyun Lee
    java.lang.StringIndexOutOfBoundsException: String index out of range: 3
  3. 0

    To check if a given string is SuperAscii or Not - java.lang.StringIndexOutOfBoundsException

    Stack Overflow | 2 years ago | subham soni
    java.lang.StringIndexOutOfBoundsException: String index out of range: 3
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    exception thrown while using .txt in file name

    Stack Overflow | 1 year ago | kanika chauhan
    java.lang.StringIndexOutOfBoundsException: String index out of range: 3
  6. 0

    java.lang.StringIndexOutOfBoundsException [Solved] (Beginning Java forum at Coderanch)

    coderanch.com | 5 months ago
    java.lang.StringIndexOutOfBoundsException: String index out of range: 3

  1. harshg 2 times, last 3 months ago
  2. balintn 4 times, last 3 months ago
  3. poroszd 1 times, last 3 months ago
  4. Stefan Braune 1 times, last 5 months ago
  5. mauritius 1 times, last 5 months ago
6 more registered users
18 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: 3

    at java.lang.String.charAt()
  2. Java RT
    String.charAt
    1. java.lang.String.charAt(String.java:658)
    1 frame
  3. Spring Messaging
    Reactor11StompCodec$DecodingFunction.apply
    1. org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221)
    2. org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197)
    3. org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123)
    4. org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:99)
    5. org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:68)
    6. org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:96)
    7. org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:83)
    7 frames
  4. Reactor TCP components
    NettyNetChannelInboundHandler.channelRead
    1. reactor.net.AbstractNetChannel.read(AbstractNetChannel.java:214)
    2. reactor.net.netty.NettyNetChannelInboundHandler.passToConnection(NettyNetChannelInboundHandler.java:105)
    3. reactor.net.netty.NettyNetChannelInboundHandler.channelRead(NettyNetChannelInboundHandler.java:69)
    3 frames
  5. Netty
    SingleThreadEventExecutor$2.run
    1. io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332)
    2. io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318)
    3. io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
    4. io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125)
    5. io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:507)
    6. io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:464)
    7. io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378)
    8. io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350)
    9. io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    9 frames
  6. Java RT
    Thread.run
    1. java.lang.Thread.run(Thread.java:745)
    1 frame