Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 304468 - [DB] EEnum save in h2 db throws ClassCastException
Summary: [DB] EEnum save in h2 db throws ClassCastException
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Eike Stepper CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-03 03:23 EST by Erwin Betschart CLA
Modified: 2010-06-29 04:35 EDT (History)
2 users (show)

See Also:


Attachments
ClassCastException (2.69 KB, text/plain)
2010-03-03 03:25 EST, Erwin Betschart CLA
no flags Details
Proposed fix. (1.37 KB, patch)
2010-03-03 03:28 EST, Erwin Betschart CLA
no flags Details | Diff
proposed fix. (1.66 KB, patch)
2010-03-03 07:53 EST, Erwin Betschart CLA
no flags Details | Diff
Proposed fix. (1.67 KB, patch)
2010-03-05 03:19 EST, Erwin Betschart CLA
stepper: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erwin Betschart CLA 2010-03-03 03:23:20 EST
Build Identifier: 3.0.0

During commit of emf enum the attached exception occurred. Unfortunately I could not write a test case to reproduce the error. It has something to do with default values in EEnums. 
I was able to fix. The fix is attached.

Reproducible: Sometimes
Comment 1 Erwin Betschart CLA 2010-03-03 03:25:33 EST
Created attachment 160743 [details]
ClassCastException

Access is an emf enum.
Comment 2 Eike Stepper CLA 2010-03-03 03:26:18 EST
Martin, as the default value expert, can you please investigate this?
Comment 3 Erwin Betschart CLA 2010-03-03 03:28:48 EST
Created attachment 160745 [details]
Proposed fix.

Patch for project org.eclipse.emf.cdo.server.db
Comment 4 Erwin Betschart CLA 2010-03-03 03:42:01 EST
I just saw that there is a problem if no default value is set on the object using the enum.
Comment 5 Martin Fluegge CLA 2010-03-03 03:46:04 EST
@Eike 

All right. I'll have a look at it. Unfortunatelly I do not have the code in front of me right now but I remember having some trouble with Enums when creating the issSet tests. Could be related to this. ..

@Erwin

Thanks for the patch. I'll try to test it asap.
Comment 6 Stefan Winkler CLA 2010-03-03 04:01:59 EST
looks good to me.
If Martin agrees, this can be applied.
Comment 7 Erwin Betschart CLA 2010-03-03 06:18:49 EST
Don't check-in the patch. There is still a problem:

If there is no default set on the attribute using an enum a NPE is thrown (caused by getFeature().getDefaultValueLiteral() which is null). I don't know what value should be written to the db in this case.
Comment 8 Erwin Betschart CLA 2010-03-03 07:47:06 EST
After further investigation I found the following problem:

The enum itself has always a default value.

The InternalCDORevision holds a null value if an enum attribute was set to this default value.

The TypeMapping class then searches for the default value which can be defined directly on the enum attribute (which can be null) but not on default defined on the EEnum.
I assume that the method setDefaultValue(..) is only called if eIsSet returns true.

I'll attach another patch which fetches the default from the enumeration itself if the attribute does not define a default value.
Comment 9 Erwin Betschart CLA 2010-03-03 07:53:08 EST
Created attachment 160769 [details]
proposed fix.

Takes also the default on the enum itself into account.
Comment 10 Martin Fluegge CLA 2010-03-03 08:41:05 EST
Erwin,

I tried to reproduce the eror, nut unfortunatelly without success. I tried settable, not settable features with and without. Stored the enum attribute value and even the enums default. Nothing caused any problem in teh current implementation.

Actually your second patch looks good, it does not seem to break anything, but Iwould feel better if were somehow able to reproduce this. Could you provide some more information about your model or even attach the concerning parts of it?
Comment 11 Erwin Betschart CLA 2010-03-05 03:19:47 EST
Created attachment 161085 [details]
Proposed fix.

Found another bug in my patch. The EEnumLiteral was fetched by name not literal.
Comment 12 Erwin Betschart CLA 2010-03-05 03:26:06 EST
I'll try to write an cdo test case. Up to now I've only written test cases using MemStores. How do I run a cdo test case based on a db store? Are there any existing test cases I could use as a template?
Comment 13 Eike Stepper CLA 2010-03-05 03:44:50 EST
Hi Erwin, the test logic should usually be independent of the chosen backend (and other setup configuration details). With our cool test framework we run these test cases in several different scenarios.
Comment 14 Bjoern Sundin CLA 2010-03-05 08:21:20 EST
I also detected the same issue with an emf generated model, cdo 3 (head) and a derby database.

The patch handled the problem, thanks Erwin!
Comment 15 Martin Fluegge CLA 2010-03-05 09:11:59 EST
@Erwin
Thanks for your efforts. You can have a look at the org.eclispe.emf.cdo.test.db plugin. See e.g. AllTestsDBH2.java. You can add the following method to the class to run only your test case.

  protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses)
  {
    testClasses.add(MyTestCase.class);
  }
  
 If you run AllTestsDBH2.java only your test case will be executed on a H2 database. Ou rif you want you can write your own test config using AllTestsDBH2 as template.
  
 @Bjoern
  
 Thank for the info. That sounds promising. So I think we can apply the patch as soon as we have a test (making sure that any further development will not have a negative side effect on this repaired issue). Just a small question: What do you mean with "emf generated"? I hope you have converted to model to a CDO native one, because pure EMF is not yet supported in CDO.
Comment 16 Bjoern Sundin CLA 2010-03-05 09:29:54 EST
@Martin Fluegge: Yes, sorry for not expressing myself clear here. It has of course been converted to a CDO native one.
Comment 17 Eike Stepper CLA 2010-03-10 03:05:46 EST
Hi Erwin,

Thanks for your patch. I changed it slightly. Please confirm the following:

1) The number of lines that you changed is smaller than 250.
2) You are the only author of these changed lines.
3) You apply the EPL to these changed lines.
Comment 18 Erwin Betschart CLA 2010-03-11 03:16:24 EST
Hi Eike,

(In reply to comment #17)
> Hi Erwin,
> 
> Thanks for your patch. I changed it slightly. Please confirm the following:
> 
> 1) The number of lines that you changed is smaller than 250.
confirmed
> 2) You are the only author of these changed lines.
confirmed
> 3) You apply the EPL to these changed lines.
confirmed

@Martin: I have not had time to write a test case yet... ;-( Hope to do it next week.
Comment 19 Eike Stepper CLA 2010-03-11 03:47:05 EST
Committed to HEAD
Comment 20 Eike Stepper CLA 2010-06-29 04:35:22 EDT
Available in 3.0 GA:
http://download.eclipse.org/modeling/emf/cdo/updates/3.0-releases/