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 152274 - Creating JUnit test in SVN controlled project is not possible
Summary: Creating JUnit test in SVN controlled project is not possible
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: JUnit (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Marian Petras
URL: http://statistics.netbeans.org/except...
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-04 09:23 UTC by pribyl
Modified: 2009-02-19 21:21 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 135829


Attachments
stacktrace (72 bytes, text/plain)
2008-11-04 09:23 UTC, pribyl
Details
NPE (1.68 KB, text/plain)
2008-11-04 11:04 UTC, Peter Pis
Details
source code patch for branch (clone) "release65" (2.00 KB, patch)
2008-11-04 16:53 UTC, Marian Petras
Details | Diff
source code patch for branch (clone) "release65" - with increased spec. version (2.53 KB, patch)
2008-11-04 17:16 UTC, Marian Petras
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pribyl 2008-11-04 09:23:24 UTC
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)
Comment 1 pribyl 2008-11-04 09:23:30 UTC
Created attachment 73184 [details]
stacktrace
Comment 2 pribyl 2008-11-04 09:58:02 UTC
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
Comment 3 Peter Pis 2008-11-04 11:02:36 UTC
If project is under hg control then NPE is thrown.
Comment 4 Peter Pis 2008-11-04 11:04:13 UTC
Created attachment 73191 [details]
NPE
Comment 5 Marian Petras 2008-11-04 14:53:51 UTC
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.
Comment 6 Marian Petras 2008-11-04 15:46:07 UTC
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)
Comment 7 Marian Petras 2008-11-04 16:53:14 UTC
Created attachment 73205 [details]
source code patch for branch (clone) "release65"
Comment 8 Marian Petras 2008-11-04 17:16:24 UTC
Created attachment 73207 [details]
source code patch for branch (clone) "release65" - with increased spec. version
Comment 9 Martin Entlicher 2008-11-04 17:41:02 UTC
Code reviewed, the change should fix the problem and is safe.
Comment 10 Marian Petras 2008-11-04 18:06:21 UTC
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)
Comment 11 Peter Pis 2008-11-04 20:03:36 UTC
Verified on RC2 with fixed nbm.
Comment 12 Marian Petras 2008-11-04 23:00:44 UTC
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)
Comment 13 Quality Engineering 2008-11-05 04:34:26 UTC
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"