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.
Build: NetBeans IDE Dev (Build 200811011401) VM: Java HotSpot(TM) Client VM, 11.0-b15, Java(TM) SE Runtime Environment, 1.6.0_10-rc-b28 OS: Windows XP, 5.1, x86 User Comments: pribyl: I tried to create JUnit test on a package (in SVN versioned project, but I am not sure whether that was the main problem) Stacktrace: java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at java.lang.String.substring(String.java:1935) at org.netbeans.modules.junit.TestUtil.convertPackage2SuiteName(TestUtil.java:148) at org.netbeans.modules.junit.DefaultPlugin.createSuiteTest(DefaultPlugin.java:1853) at org.netbeans.modules.junit.DefaultPlugin.createTests(DefaultPlugin.java:1804) at org.netbeans.modules.junit.DefaultPlugin.createTests(DefaultPlugin.java:1786) at org.netbeans.modules.junit.DefaultPlugin.createTests(DefaultPlugin.java:902)
Created attachment 73184 [details] stacktrace
Product Version: NetBeans IDE Dev (Build 200811011401) Java: 1.6.0_10-rc; Java HotSpot(TM) Client VM 11.0-b15 System: Windows XP version 5.1 running on x86; Cp1250; cs_CZ (nb) It is really problem of project versioned with Subversion Steps to reproduce: 1, Create new sample java project 2, Import it into SVN repository 3, On the package node invoke Tools - Create JUnit Tests (and confirm all dialogs) -> Warnings and Exceptions begin to pop up, test suite with multiple errors is created (can be accesed via clicking on errors in TODO list, but it does not show in Project or Files view) Can be reproduced easily, automatic creation of JUnit test is not possible -> increasing priority to P1
If project is under hg control then NPE is thrown.
Created attachment 73191 [details] NPE
This happens while the JUnit module is generating a test suite for a folder whose name consists of an initial dot (.), followed by a series of alphabet characters, such as ".svn". The critical situation happens when method DefaultPlugin.createSuiteTest(...) is called and a folder named as described above is passed as its first argument. For example, if the folder (the argument) is <projectroot>/src/package/.svn then the following happens inside the method: String pkg = cp.getResourceName(folder, '/', false); Value of 'folder' is "<projectroot>/src/package/.svn" The result is "package/" because ".svn" is stripped as it is considered to be an extension. String dotPkg = pkg.replace('/', '.'); Transforms string "package/" to "package." String fullSuiteName = (suiteName != null) ? pkg + '/' + suiteName : TestUtil.convertPackage2SuiteName(pkg); Calls method TestUtil.convertPackage2SuiteName("package/"). Method convertPackage2SuiteName("package/") is called and does the following: int index = packageFileName.lastIndexOf('/'); Return a non-negative index pointing to the position of '/'. String pkg = index > -1 ? packageFileName.substring(index+1) : packageFileName; Returns an empty string because there is nothing after the slash. pkg = pkg.substring(0, 1).toUpperCase() + pkg.substring(1); Throws an StringIndexOutOfBoundsException because we are calling substring(0, 1) on an empty string.
Fixed. When test are being created for a folder, the folder is traversed and tests a test suites are created recursively. To fix this issue, I adding a check for visibility such that invisible folders and files are skipped by the routine. Changeset Id: 5819cc3a82a7 (http://hg.netbeans.org/main/rev/5819cc3a82a7)
Created attachment 73205 [details] source code patch for branch (clone) "release65"
Created attachment 73207 [details] source code patch for branch (clone) "release65" - with increased spec. version
Code reviewed, the change should fix the problem and is safe.
I forgot to increase the spec. version when I introduced a new dependency (by the fix). So I increased it now. Changeset Id: c1ce5883edb0 (http://hg.netbeans.org/main/rev/c1ce5883edb0)
Verified on RC2 with fixed nbm.
I just applied the patch for branch (clone) 'release65' and pushed it - so it is now fixed in 'release65', too. Changed the target milestone to '6.5'. Changeset Id: c88bf112ac6e (http://hg.netbeans.org/release65/rev/c88bf112ac6e)
Integrated into 'main-golden', will be available in build *200811050201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/5819cc3a82a7 User: Marian Petras <mpetras@netbeans.org> Log: fixed bug #152274 - "Creating JUnit test in SVN controlled project is not possible"