[SPIGOT-6285] ChatPaginator#wordWrap throws StringIndexOutOfBoundsException Created: 22/Dec/20  Updated: 27/Dec/20

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: GhostTheWolf Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Attachments: File ChatPaginatorTester-1.0.0.jar    
Version: This server is running CraftBukkit version git-Spigot-628435a-878b437 (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

The wordWrap method is throwing StringIndexOutOfBoundsException when wraping:

  • raw string "&a" and length 1
  • raw string "&a&aa" and length 3
  • raw string "&a&a&a" and length 5

The problem seems to be related to colors, if I remove them it works normally.

From the tests, I get that if the color block has a length bigger than that passed on the method it throws the exception.

 

I wrote a simple plugin to test that; it has a command /cpt <length> <string>

So to reproduce, load the plugin and run any of:

  • /cpt 1 &a
  • /cpt 3 &a&aa
  • /cpt 5 &a&a&a

 

PS.: I'm using & because the test plugin translates this symbol.



 Comments   
Comment by GhostTheWolf [ 27/Dec/20 ]

Subtracting lineColorChars does fix the issues in those tests.

But I also found another problem:
When wraping "a&a" with length 1 it still throws the exception.
The problem is on splitting the string by the length. Here: split("(?<=
G.{" + lineLength + "})")
This results in:
Line 1: a
Line 2: &
Line 3: a
The color symbol is alone on the second line, so we can't get the color by using the index of & + 1.

 

Comment by GhostTheWolf [ 26/Dec/20 ]

@md_5

After reading the code, the problem seems to be on this line: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/util/ChatPaginator.java#96

It's not subtracting lineColorChars.

I will be testing that later.

Generated at Sat Apr 05 09:53:40 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.