This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 248367 - StringIndexOutOfBoundsException: String index out of range: -1
Summary: StringIndexOutOfBoundsException: String index out of range: -1
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-03 13:33 UTC by panica_11
Modified: 2015-09-30 01:20 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 213108


Attachments
stacktrace (2.68 KB, text/plain)
2014-11-03 13:33 UTC, panica_11
Details

Note You need to log in before you can comment on or make changes to this bug.
Description panica_11 2014-11-03 13:33:49 UTC
This issue was reported manually by panica_11.
It already has 2 duplicates 


Build: NetBeans IDE 8.0.1 (Build 201408251540)
VM: Java HotSpot(TM) 64-Bit Server VM, 25.20-b23, Java(TM) SE Runtime Environment, 1.8.0_20-b26
OS: Mac OS X

User Comments:
panica_11: public class Point {
	private int x;
	private int y;
}

when i try to create methods get and set i got this exception

GUEST: ff




Stacktrace: 
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
   at java.lang.AbstractStringBuilder.substring(AbstractStringBuilder.java:908)
   at java.lang.StringBuilder.substring(StringBuilder.java:76)
   at org.netbeans.api.java.source.CodeStyleUtils.removePrefixSuffix(CodeStyleUtils.java:126)
   at org.netbeans.api.java.source.CodeStyleUtils.removeFieldPrefixSuffix(CodeStyleUtils.java:222)
   at org.netbeans.api.java.source.CodeStyleUtils.computeGetterName(CodeStyleUtils.java:200)
   at org.netbeans.modules.java.editor.codegen.GeneratorUtils.hasGetter(GeneratorUtils.java:294)
Comment 1 panica_11 2014-11-03 13:33:52 UTC
Created attachment 150236 [details]
stacktrace
Comment 2 Svata Dedic 2015-09-16 14:24:19 UTC
I am not sure if I covered your specific situation, since I was not able to reproduce the defect using  panica_11's description. I'd need to look at the java formatting settings active at the time of the error.

However if BOTH prefix and suffix is defined for a field, and the actual field name matches both in a way that the prefix and suffix in the field's name overlap - the name generation algorithm will throw the exactly same SIOOBE.

Corner cases should be handled by jet-main#6803edc38fc2
Comment 3 Quality Engineering 2015-09-30 01:20:39 UTC
Integrated into 'main-silver', will be available in build *201509300002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/6803edc38fc2
User: Svata Dedic <sdedic@netbeans.org>
Log: #248367: do not strip prefix/suffix if they overlap or the basename is empty