Closed slavap closed 7 years ago
Could you give me some more information, such as
So far I tested it with devTZ_main branch, and I get either no Exception (predefined schema) or a JDOUserException (auto-create schema). I don't see an NPE at the moment.
Also, I noticed that you are missing zooActivateWrite()
before setting the fields. This is usually done in the setter() methods. However, adding/removing zooActivateWrite()
doesn't seem to make a difference in terms of Exceptions or not...
Yes, I'm using schema-auto-creation. I will create test project for this bug. I'm working with zoodb 0.4.9 And I was under impression that it doesn't matter when f.zooActivateWrite() is called, so in my understanding before or after are doing the same thing.
Unfortunatelly, I cannot attach zip file in comments, so I've renamed zip to png. Download, rename back to zip, and execute runme.cmd, then you'll get NPE. Let me know if you need any additional info.
Thanks, I can reproduce it now. I'll have to investigate why it doesn't happen in my normal test environment.
zooActivateWrite()
has several purposes. On new objects, it probably does not matter when it is called. However, for example, for objects coming from the database (when their state is 'hollow'), calling zooActivateWrite()
will read the object from the database and overwrite any changes to the object that may have occurred since the last commit or rollback. The save option is to call zooActivateWrite()
in the beginning of each method that modifies an object, for example in every setter method. The method has very little overhead once the object is loaded and flagged as 'dirty'.
Just in case, a simple workaround is to define the schema manually, at least for the Property
class by doing the following before the main transaction:
pm.currentTransaction().begin();
ZooSchema schema = ZooJdoHelper.schema(pm);
schema.addClass(Property.class);
pm.currentTransaction().commit();
Also, with schema.getClass(...)
allows you to check whether a schema is already defined.
This qualifies for the ongoing bug bounty. If you are interested, could you contact me via zoodb(AT)gmx(DOT)de to organize the bounty?
@tzaeschke Thanks. I've workaround this problem by just storing fake StringProperty with my main/root folder, after that following empty Property arrays are stored just fine. But your workaround looks good to me as well. Will send you email for organizing the bounty, really surprised by this fact.
Should be fixed now on devTZ_main branch. I'll look at the other issue tomorrow. Thanks for reporting!
The following code fails with NPE exception:
The problem in DataSerializer.writeClassInfo(Class<?> cls, Object val) method: