After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 597488 - Initializing an ArrayList in the member declaration causes G_IS_OBJECT errors
Initializing an ArrayList in the member declaration causes G_IS_OBJECT errors
Status: RESOLVED NOTABUG
Product: vala
Classification: Core
Component: general
0.7.x
Other Linux
: Urgent normal
: ---
Assigned To: Vala maintainers
Vala maintainers
wrong-code
Depends on:
Blocks:
 
 
Reported: 2009-10-05 22:56 UTC by Matthijs De Smedt
Modified: 2017-02-17 21:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase showing problem and work-around (564 bytes, text/x-vala)
2009-10-05 22:57 UTC, Matthijs De Smedt
Details
Backtrace from gdb (1.25 KB, application/octet-stream)
2009-10-05 22:58 UTC, Matthijs De Smedt
Details

Description Matthijs De Smedt 2009-10-05 22:56:44 UTC
Vala 0.7.7 with libgee 0.5.0.

If I run the attached code then I get the following error:
GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed

This happens when retrieving objects from the array.

Frederik @ #vala remarked that moving the initializer from the class body to the constructor causes the errors to disappear.
Comment 1 Matthijs De Smedt 2009-10-05 22:57:21 UTC
Created attachment 144858 [details]
Testcase showing problem and work-around
Comment 2 Matthijs De Smedt 2009-10-05 22:58:11 UTC
Created attachment 144859 [details]
Backtrace from gdb
Comment 3 Luca Bruno 2012-12-12 20:58:12 UTC
This happens because new ArrayList<T>() is done in the instance_init. Unfortunately, the generic type information is given after instance_init.
Would passing generic type information as properties through g_object_new solve the problem or start a new era of bugs due to property overriding?
Maybe we should simply forbid using initializers that refer type parameters?
Comment 4 geert jordaens 2013-05-13 11:04:32 UTC
duplicate of bug 597488
Comment 5 Luca Bruno 2013-05-13 12:42:09 UTC
(In reply to comment #4)
> duplicate of bug 597488

It's this bug :-)
Comment 6 geert jordaens 2013-05-13 16:59:43 UTC
Should have been:

Bug 523767 - Generics don't work in field initializers 

however comment 4 describes the same problem.
Comment 7 Daniel Espinosa 2017-02-17 21:01:20 UTC
W
hen using Gee and Vala generics as properties, you should consider to initialize them first, both using a default or in construct block.

public class MyClass : Object {
    public ArrayList<Object> { get; set: default = new ArrayList<Object> (); }
}

Generics types are unknown at class initialization, but at instantiation time, then you should instantiate it and know generic type first.

This was done at GXml for SerializableArrayList<G>, where any object with this property type is initalized at declration using defaulto = new SerializableArrayList<Object>(); this avoids types unknowns.

In GXml Serializable, added an interface to declare it is a Collection Container then after create an object's instance using Object.new(), it calls a method implemented in interface to initialize all its generic property members.