History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2817
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Russel Winder
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

Off by one error on string indexing error reporting

Created: 10/May/08 06:41 AM   Updated: 12/May/08 12:50 AM
Component/s: None
Affects Version/s: 1.6-beta-2
Fix Version/s: 1.5.7, 1.6-beta-2

Time Tracking:
Not Specified

Environment: Ubuntu 8.04 Hardy Heron


 Description  « Hide
The following says it all really :
|> groovy -e "println ( 'ab'[4] )"
Caught: java.lang.StringIndexOutOfBoundsException: String index out of range: 5
	at script_from_command_line.$cs$2(script_from_command_line)
	at script_from_command_line.run(script_from_command_line:1)
	at script_from_command_line.main(script_from_command_line)


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King - 12/May/08 12:50 AM
This is kind of Java behavior kicking in but certainly not obvious:
String bar = "bar";

// this produces: java.lang.StringIndexOutOfBoundsException: String index out of range: 3
bar.charAt(3));

// these produce: java.lang.StringIndexOutOfBoundsException: String index out of range: 4
bar.substring(3,4));
bar.subSequence(3,4));

Even more confusing:

// this produces: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
bar.substring(3,2));