Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] ClassCastException when setting transaction on a new branch
[CDO] ClassCastException when setting transaction on a new branch [message #1755356] Thu, 02 March 2017 15:38 Go to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 366
Registered: May 2011
Senior Member
Hello Eike,

I am updating our framework dependencies from CDO 4.4 to CDO 4.6. I now have some ClassCastExceptions on a JUnit manipulating CDO branches. I have not been able to reproduce the issue on a CDO JUnit so far. However, I have a fix but I would like to know if you see any issue with it. If the fix is acceptable to you, I will open a bugzilla and push it to gerrit.
The ClassCastException happens because the transaction.setBranch call end up creating a notification using CDONotificationBuilder.createPrimitiveNotification(int, EStructuralFeature, Class<?>, Object, Object) and the oldValue is not a Boolean or a Number as expected but CDOFeatureDelta.UNKNOWN_VALUE instead (I do not know why). This causes ClassCastException obviously.

However, If I add the 2 following instructions I do not have the exception anymore:
- In CDONotificationBuilder.createPrimitiveNotification(int, EStructuralFeature, Class<?>, Object, Object) start the method by
if(CDOFeatureDelta.UNKNOWN_VALUE.equals(oldValue)){
return new CDODeltaNotificationImpl(object, eventType, feature, oldValue, newValue);
}
- In createNotification(int, EStructuralFeature, Object, Object, int) update the third "if instruction" from "if (oldValue != null)" to
"if (oldValue != null && !CDOFeatureDelta.UNKNOWN_VALUE.equals(oldValue))"

So far I have not been able to reproduce the scenario in a CDO JUnit, because with our framework when setBranch is called, in the method CDOViewImpl.doInvalidateSynced(ViewInvalidationData), "deltas" is not empty and then it calls sendDeltaNotifications. I do not know why I have deltas in my case.

Do you have an opinion? Should I open a bugzilla even if I do not have a JUnit to reproduce the issue?

Regards,
Steve


Steve Monnier - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: [CDO] ClassCastException when setting transaction on a new branch [message #1755359 is a reply to message #1755356] Thu, 02 March 2017 16:03 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 366
Registered: May 2011
Senior Member
Here is the stack trace for a Boolean value (I have the same for a Number also):
java.lang.ClassCastException: org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta$1 cannot be cast to java.lang.Boolean
at org.eclipse.emf.internal.cdo.object.CDONotificationBuilder.createPrimitiveNotification(CDONotificationBuilder.java:348)
at org.eclipse.emf.internal.cdo.object.CDONotificationBuilder.createNotification(CDONotificationBuilder.java:336)
at org.eclipse.emf.internal.cdo.object.CDONotificationBuilder.visit(CDONotificationBuilder.java:174)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDOSetFeatureDeltaImpl.accept(CDOSetFeatureDeltaImpl.java:92)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.accept(CDORevisionDeltaImpl.java:360)
at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.accept(CDORevisionDeltaImpl.java:350)
at org.eclipse.emf.internal.cdo.object.CDONotificationBuilder.buildNotification(CDONotificationBuilder.java:94)
at org.eclipse.emf.internal.cdo.view.CDOViewImpl.sendDeltaNotifications(CDOViewImpl.java:1358)
at org.eclipse.emf.internal.cdo.view.CDOViewImpl.doInvalidateSynced(CDOViewImpl.java:1238)
at org.eclipse.emf.internal.cdo.view.CDOViewImpl.doInvalidate(CDOViewImpl.java:1184)
at org.eclipse.emf.internal.cdo.view.CDOViewImpl.setBranchPoint(CDOViewImpl.java:293)
at org.eclipse.emf.internal.cdo.view.AbstractCDOView.setBranchPoint(AbstractCDOView.java:842)
at org.eclipse.emf.internal.cdo.view.AbstractCDOView.setBranch(AbstractCDOView.java:774)
...


Steve Monnier - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: [CDO] ClassCastException when setting transaction on a new branch [message #1755391 is a reply to message #1755359] Thu, 02 March 2017 18:26 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6394
Registered: July 2009
Senior Member
Thanks, Steve. Please note that 4.6 is effectively out-of-maintenance. Can you run your test on the master branch?
Re: [CDO] ClassCastException when setting transaction on a new branch [message #1755422 is a reply to message #1755391] Fri, 03 March 2017 08:47 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 366
Registered: May 2011
Senior Member
Hello Eike,

Indeed, I tried with a JUnit on the master branch, I have seen no 4.6-maintenance branch yet.

Regards,
Steve


Steve Monnier - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: [CDO] ClassCastException when setting transaction on a new branch [message #1755430 is a reply to message #1755422] Fri, 03 March 2017 10:27 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6394
Registered: July 2009
Senior Member
Sorry, I mistyped the version. I meant to say that there will be no 4.5 maintenance builds/releases!
Re: [CDO] ClassCastException when setting transaction on a new branch [message #1756222 is a reply to message #1755430] Tue, 14 March 2017 09:42 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 429
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Eike, Steve,

This seems to come from
http://git.eclipse.org/c/cdo/cdo.git/commit/?id=de192b0abbde6c721f376da4c747cd74f2a053c9 done for
https://bugs.eclipse.org/bugs/show_bug.cgi?id=503564

I will take one of the failing objects in our case as a sample: we have an EClass Car with an EAttribute brokenDown (default value: false).

On my current branch, I have a car CarOne with brokenDown=false.
When I call setBranch(myOtherBranch):
- I have a CDOFeatureDelta[brokendown, SET, value=false, index=0, oldValue=UNSPECIFIED]
- the old revision values are [4, [OID10], [], [], null, [], car1, null, null, [], [], []] , null correspond to brokenDown=false: default value so no value in the revision

In CDO 4.4:
- CDONotificationBuilder.getOldValue(feature) : null
- CDONotificationBuilder.createNotification: isPrimitive: oldValue==null > defaultValue

In CDO 4.6:
- ClassCasstException in CDONotificationBuilder.createNotification > CDONotificationBuilder. createPrimitiveNotification > oldValue == org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta.UNKNOWN_VALUE, it cannot be cast in Boolean.

Looking at the code here is the difference:

In CDO 4.4:
org.eclipse.emf.internal.cdo.object.CDONotificationBuilder.visit(CDOSetFeatureDelta) {
   EStructuralFeature feature = delta.getFeature();
    Object oldValue = getOldValue(feature);
  ...


org.eclipse.emf.internal.cdo.object.CDONotificationBuilder.visit(CDOSetFeatureDelta) {
  EStructuralFeature feature = delta.getFeature();
  Object oldValue = delta.getOldValue();
  if (oldValue == null)
  {
    oldValue = getOldValue(feature);
  }
  ...


Second difference between CDO 4.4 and 4.6: UNSPECIFIED -> UNKNOWN_VALUE, but this seems to have no impact here.

I will try to create a JUnit.

Regards

Re: [CDO] ClassCastException when setting transaction on a new branch [message #1756249 is a reply to message #1756222] Tue, 14 March 2017 14:12 Go to previous message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 429
Registered: July 2009
Location: Nantes, France
Senior Member
Eike,

I submitted a draft tests which show the ClassCastException: https://git.eclipse.org/r/#/c/93011/

Note that:
- The ClassCastException occurs with CDO native and legacy metamodels (the second test use Ecore as the branching test suite are configured to use the NATIVE model config)
- There is no Exception with MEMStore (AllTestMEMBranches) as only the resource appears to be changed.
- The ClassCastException occurs at least with AllTestDBH2Branching
- The ClassCastException does not occur with CDO 4.4.

The difference between MEMStore and DBStore is that DBStore seems to indicate that all attributes with default value have been changed (see allChangedObjects list after the call to sessionProtocol.switchTarget in CDOViewImpl.setBranchPoint)

Eike, I let you see if you want to reopen Bug 503564 or to create a new Bugzilla.

Regards
Previous Topic:Containment references are not shown in the ecore diagram
Next Topic:[XCore] xcore andChe
Goto Forum:
  


Current Time: Wed Sep 19 08:36:04 GMT 2018

Powered by FUDForum. Page generated in 0.05947 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top