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 204178 - "New Wizard" code of "New File" type fails cryptically when invoked incorrectly
Summary: "New Wizard" code of "New File" type fails cryptically when invoked incorrectly
Status: RESOLVED FIXED
Alias: None
Product: apisupport
Classification: Unclassified
Component: Templates (show other bugs)
Version: 7.1
Hardware: All All
: P4 normal (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-24 19:53 UTC by jasondrums
Modified: 2011-10-26 14:24 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Fix for this bug. Instantiates a string array with a size of 1 instead of 0. (5.35 KB, patch)
2011-10-24 19:53 UTC, jasondrums
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jasondrums 2011-10-24 19:53:24 UTC
Created attachment 112383 [details]
Fix for this bug. Instantiates a string array with a size of 1 instead of 0.

The template code that is output from using the "New Wizard" wizard contains a bug that is only discovered during runtime. It produces a string array of size zero which is indexed by another piece of auto-generated code and causes an ArrayIndexOutOfBoundsException.

Steps to reproduce the problem:
1. Right click on a java package within a module
2. Click on New
3. Click on Other...
4. Select "Module Development" in the Categories panel.
5. Select "Wizard" in the File Types panel.
6. Click the "Next" button.
7. Set Registration Type to "New File" (this is very important!)
8. Set "Number of Wizard Panels" to 1 (this number doesn't matter)
9. On the "Name and Location" step put in any class name prefix, display name, category and package.
10. Click on the "Finish" button.
11. Create an action that displays the wizard that was created in steps 1 through 10.
11a (Sample action):
    @Override
    public void actionPerformed(ActionEvent e)
    {
        WizardDescriptor wizardDescriptor = new WizardDescriptor(new NewAPIWizardIterator());
        // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
        wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
        wizardDescriptor.setTitle("New Thing");

        Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
        dialog.setVisible(true);
        dialog.toFront();
    }
12. When this action is invoked the following exception is incurred due to indexing the zero array at 0:
java.lang.ArrayIndexOutOfBoundsException: 0
	at com.datasoft.diva.gui.TestWizardIterator.getPanels(TestWizardIterator.java:36)
	at com.datasoft.diva.gui.TestWizardIterator.current(TestWizardIterator.java:80)
	at org.openide.WizardDescriptor.updateStateOpen(WizardDescriptor.java:858)
	at org.openide.WizardDescriptor.updateState(WizardDescriptor.java:832)
	at org.openide.WizardDescriptor.initialize(WizardDescriptor.java:512)
	at org.openide.NotifyDescriptor.getterCalled(NotifyDescriptor.java:290)
	at org.openide.DialogDescriptor.isModal(DialogDescriptor.java:322)
	at org.netbeans.core.windows.services.NbDialog.<init>(NbDialog.java:67)
	at org.netbeans.core.windows.services.DialogDisplayerImpl$1.run(DialogDisplayerImpl.java:144)
	at org.netbeans.core.windows.services.DialogDisplayerImpl$1.run(DialogDisplayerImpl.java:110)
	at org.openide.util.Mutex.doEventAccess(Mutex.java:1361)
	at org.openide.util.Mutex.readAccess(Mutex.java:271)
	at org.netbeans.core.windows.services.DialogDisplayerImpl.createDialog(DialogDisplayerImpl.java:110)
	at com.datasoft.diva.gui.api.wizard.NewAPIAction.actionPerformed(NewAPIAction.java:37)

I've attached the updated file (instantiatingIterator.javx) that resolves this problem. It goes in "apisupport.project\src\org\netbeans\modules\apisupport\project\ui\wizard\wizard"
Comment 1 Jesse Glick 2011-10-25 14:03:03 UTC
(In reply to comment #0)
> 7. Set Registration Type to "New File" (this is very important!)
> 11. Create an action that displays the wizard that was created in steps 1
> through 10.

Here is where you went wrong. "New File"-type wizards are meant to be displayed _embedded_ in the New File wizard; the IDE's metawizard generates the template registration you need (you would not explicitly create an instantiating iterator). To run a wizard standalone with a custom action, use the Custom option, which generates different code (no createSteps method).

> I've attached the updated file (instantiatingIterator.javx) that resolves this
> problem. It goes in ...

In the future please attach patches (hg diff --git format preferred), not complete files - it is difficult to see what you have changed, especially since that file has been edited since you made a copy of it. I think you modified just

            beforeSteps = new String[0];

I will replace the null handling, which is pointless, with an assertion so the code fails earlier and more clearly when used incorrectly.
Comment 2 Jesse Glick 2011-10-25 14:04:19 UTC
core-main #41004ae62da9
Comment 3 Quality Engineering 2011-10-26 14:24:17 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/41004ae62da9
User: Jesse Glick <jglick@netbeans.org>
Log: #204178: "New Wizard" code of "New File" type fails cryptically when invoked incorrectly