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 227050 - Add support to Singleton TopComponents - @FactoryMethod
Summary: Add support to Singleton TopComponents - @FactoryMethod
Alias: None
Product: platform
Classification: Unclassified
Component: Options&Settings (show other bugs)
Version: 7.3
Hardware: All All
: P1 normal (vote)
Assignee: Jaroslav Tulach
Depends on:
Reported: 2013-03-05 15:25 UTC by AngeloD
Modified: 2013-05-07 00:19 UTC (History)
2 users (show)

See Also:
Exception Reporter:

Introducing @FactoryMethod runtime annotation (11.75 KB, patch)
2013-03-05 20:43 UTC, Jaroslav Tulach
Details | Diff
To be applied tomorrow (22.25 KB, patch)
2013-03-14 11:28 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description AngeloD 2013-03-05 15:25:07 UTC
For TopComponents that should be singletons the platform breaks the invariant that, at any time, there should be only one instance of the singleton object.

For example, at start-up, XMLPropertiesConvertor creates a new instance of the TopComponent (see defaultInstanceCreate).

Adding support for factory methods creating the instance would solve this problem.
The @ConvertAsProperties annotation could be expanded to indicate the name of a factory method (e.g. getDefault).

In defaultInstanceCreate it would possible to check for the existence of the factory method and invoke it instead of newInstance...

The same applies to other places like XMLSettingsSupport, in the instanceCreate method.
Comment 1 Jaroslav Tulach 2013-03-05 19:58:53 UTC
(Invalid) thought #1: I hoped that adding new attribute to @ConvertAsProperties will be enough:

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -92,4 +92,13 @@
      * @return array of property names or {@link #IGNORE_ALL_CHANGES} to ignore all properties
     String[] ignoreChanges() default {};
+    /** Factory method to use instead of default constructor. Sometimes,
+     * for example when dealing with singletons, it may be desirable to
+     * control how an instance of given class is created. In such case
+     * one can create a factory method (takes no arguments and returns
+     * instance of desired type) in the class annotated by {@link ConvertAsProperties}
+     * annotation.
+     */
+    String factoryMethod();

but that is unlikely. The information is needed during runtime and it is complicated to encode it from @ConvertAsProperties processor, so runtime classes can use it.
Comment 2 Jaroslav Tulach 2013-03-05 20:43:03 UTC
Created attachment 132222 [details]
Introducing @FactoryMethod runtime annotation
Comment 3 Jaroslav Tulach 2013-03-12 14:10:51 UTC
Angelo, can you confirm this change works for you? If so, I will:

Y01 write apichanges.xml
Y02 write annotation processor to verify "value" represents real method name
Comment 4 AngeloD 2013-03-12 15:56:29 UTC
I confirm the patch we applied works perfectly.
Comment 5 Jaroslav Tulach 2013-03-14 11:28:06 UTC
Created attachment 132599 [details]
To be applied tomorrow
Comment 6 Jaroslav Tulach 2013-03-15 08:54:19 UTC
ergonomics#e7e9a8f3cea7 - when backporting to release73 don't forget to make sure the apichanges.xml matches the actual version of the module in release73 branch.
Comment 7 Jaroslav Tulach 2013-03-15 12:22:22 UTC
Correction: 65cc8a1d6e39 is better changeset
Comment 8 Quality Engineering 2013-03-16 01:50:05 UTC
Integrated into 'main-golden', will be available in build *201303152300* on (upload may still be in progress)
User: Jaroslav Tulach <>
Log: #227050: @FactoryMethod allows alternative creation, caching, singletonization of deserialized objects
Comment 9 Alexander Simon 2013-03-16 07:40:21 UTC
see regression in bug #227547
Comment 10 Jaroslav Tulach 2013-05-02 14:03:35 UTC
Integrated to release73 as 29ea29419c34
Comment 11 Jaroslav Tulach 2013-05-06 10:10:43 UTC
Looks like the release73 repository is messed up. "hg merge" does not work. Doing manual backport:

$ hg up -C release73
$ hg diff -r release73_base:65cc8a1d6e39 | patch -p1 
# modify versioning
$ hg add .
$ hg ci 
$ hg tip
changeset:   9f7631d9947d
branch:      release73
tag:         tip
user:        Jaroslav Tulach <>
date:        Mon May 06 12:09:53 2013 +0200
summary:     Manual backport of #227050 into 7.3.1
Comment 12 Quality Engineering 2013-05-07 00:19:16 UTC
Integrated into 'releases', will be available in build *201305062200* or newer. Wait for official and publicly available build.
User: Jaroslav Tulach <>
Log: Manual backport of #227050 into 7.3.1