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.
Summary: | InstantiatingIterator takes a type parameter but it can only be WizardDescriptor | ||
---|---|---|---|
Product: | platform | Reporter: | Jesse Glick <jglick> |
Component: | Dialogs&Wizards | Assignee: | Jesse Glick <jglick> |
Status: | RESOLVED FIXED | ||
Severity: | blocker | CC: | jtulach |
Priority: | P4 | Keywords: | API |
Version: | 6.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | DEFECT | Exception Reporter: | |
Bug Depends on: | |||
Bug Blocks: | 92762 | ||
Attachments: |
Suggested patch
Usage of InstantiatingIterator<StringBuilder> java.lang.ClassCastException: org.netbeans.modules.project.ui.NewProjectWizard cannot be cast to java.util.concurrent.atomic.AtomicReference at test154776.brokenWizardPanel.readSettings(brokenWizardPanel.java:12) at org.openide.WizardDesc |
Description
Jesse Glick
2008-12-05 15:41:35 UTC
Problem introduced in 6.0. Created attachment 74619 [details]
Suggested patch
BTW assigning to you simply because you introduced the original generification and may want to comment on this. Feel free to reassign to default owner. Created attachment 77962 [details]
Usage of InstantiatingIterator<StringBuilder>
I think the types are not bad. I can write InstantiatingIterator<StringBuilder> and everything compiles OK and seems to work. I suggest "won'tfix". Maybe you did not read the opening sentences of the original description. Yes your test compiles OK, but it is not "working" because it is not actually running a wizard. If you tried to connect this WD.II to an actual New wizard, which is the only purpose of a WD.II, it would throw a CCE. Created attachment 77987 [details]
java.lang.ClassCastException: org.netbeans.modules.project.ui.NewProjectWizard cannot be cast to java.util.concurrent.atomic.AtomicReference at test154776.brokenWizardPanel.readSettings(brokenWizardPanel.java:12) at org.openide.WizardDesc
Oh, New Wizard. Yes, TemplateWizard requires Iterator<WizardIterator>, but it reads it from disk, and as such there is nothing to type check in this situation. But it is not reason for restricting InstantiatingIterator, I am quite sure my test is OK - one can use InstantiatingIterator<Anything> with regular WizardDescriptor without any problems. If you can think of a way to early detect that Iterator<?> loaded from "templateWizardIterator" is not of the right type, feel free to add the check there. Otherwise, I do not think there is anything to fix in the signatures. "one can use InstantiatingIterator<Anything> with regular WizardDescriptor without any problems" - you could, though this seems to be very rare. I think I found an example in php.rt. There seems to be no purpose in doing so; while instantiate() will be called, php.rt does not call getInstantiatedObjects, it just expects the side-effect of instantiate() to be its purpose and the return value is irrelevant. You could more simply just do this action when the wizard returns FINISH, without using II at all. The whole point of creating II (or, originally, TW.I) was to serve as a means of communication by which an iterator implemented in one module could return some objects back to the wizard invoker implemented in another module. For this case it is senseless to let the II freely choose its Data type, because the iterator is not in control of the creation of the wizard - it is passively bound to the wizard by foreign code which must choose a generic data type, which in practice is the WD itself. That is why I still think the signature of II is a mistake. The Javadoc at least needs to clarify that the type parameter must be WizardDescriptor for the expected use case. Type-checking the iterator at load time is impossible because we neglected to include RTTI in the interface, i.e. an abstract Class<Data> type() method. Improving Javadoc at least, not sure what else can be done now: core-main #6343aff04895 Integrated into 'main-golden', will be available in build *200903111543* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/6343aff04895 User: Jesse Glick <jglick@netbeans.org> Log: #154776: documenting that Data = WizardDescriptor on an instantiating iterator. Well, I am not fully comfortable with the new javadoc. Maybe instead of "in practice" you should say that "if used from layer as template attribute". Or something like that. It's not just for file and project templates, but also for Java platforms, etc. |