Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Binary serialization broken with UML2 Kepler ?
icon4.gif  Binary serialization broken with UML2 Kepler ? [message #1165949] Fri, 01 November 2013 17:11 Go to next message
Alexis Muller is currently offline Alexis Muller
Messages: 2
Registered: November 2013
Junior Member
Hi,

UML2 binary serialization seems broken with the last version of Kepler.

The follow simple Junit test shows the issue:

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.UMLFactory;
import org.junit.Assert;
import org.junit.Test;


public class BinarySaveLoadTests
{
	private byte[] data;
	
	@Test
	public void saveAnLoad() throws IOException
	{
		final ResourceSet resourceSet = new ResourceSetImpl();
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
			.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new ResourceFactoryImpl() {
				@Override
				public Resource createResource(URI uri)
				{
					return new BinaryResourceImpl(uri);
				}
			});
		
		Resource resource = resourceSet.createResource(URI.createURI("binresource"));
		
		Model model = UMLFactory.eINSTANCE.createModel();
		model.setName("model");
		
		Enumeration en = model.createOwnedEnumeration("enum");
		en.createOwnedLiteral("lit1");
		
		resource.getContents().add(model);
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		resource.save(out, null);
		data = out.toByteArray();

		ResourceImpl resource2 = (ResourceImpl) resourceSet.createResource(URI.createURI("binresource2"));
		resource2.load(new ByteArrayInputStream(data), null);
		
		Model model2 = (Model) resource2.getContents().get(0);
		
		assertNotNull(model2);
		assertEquals(model2.getName(), "model");
		Assert.assertFalse(model.getOwnedElements().isEmpty());
	}
}


Its execution raises the following exception:

java.lang.UnsupportedOperationException
	at org.eclipse.emf.common.util.BasicEList$UnmodifiableEList.grow(BasicEList.java:1029)
	at org.eclipse.emf.common.util.BasicEList.addAllUnique(BasicEList.java:495)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObjects(BinaryResourceImpl.java:2232)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadFeatureValue(BinaryResourceImpl.java:2555)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObject(BinaryResourceImpl.java:2522)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObjects(BinaryResourceImpl.java:2222)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadFeatureValue(BinaryResourceImpl.java:2555)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObject(BinaryResourceImpl.java:2522)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObjects(BinaryResourceImpl.java:2222)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadFeatureValue(BinaryResourceImpl.java:2555)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObject(BinaryResourceImpl.java:2522)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadResource(BinaryResourceImpl.java:2205)
	at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl.doLoad(BinaryResourceImpl.java:264)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
	at testumlbinary.BinarySaveLoadTests.saveAnLoad(BinarySaveLoadTests.java:55)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



Maybe I am doing something wrong, if so, please let me know. But the same code is working perfectly with previous UML2 Juno implementations.

Could you help me to fix this issue?
Thank you.
Re: Binary serialization broken with UML2 Kepler ? [message #1166974 is a reply to message #1165949] Sat, 02 November 2013 09:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4094
Registered: July 2009
Senior Member
Hi

Please raise a Bugzilla attaching the example as a zipped project rather
than a file to avoid misunderstandings over classpaths etc.

Regards

Ed Willink

On 01/11/2013 21:11, Alexis Muller wrote:
> Hi,
>
> UML2 binary serialization seems broken with the last version of Kepler.
>
> The follow simple Junit test shows the issue:
>
>
> import static org.junit.Assert.assertEquals;
> import static org.junit.Assert.assertNotNull;
>
> import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl;
> import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
> import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.uml2.uml.Enumeration;
> import org.eclipse.uml2.uml.Model;
> import org.eclipse.uml2.uml.UMLFactory;
> import org.junit.Assert;
> import org.junit.Test;
>
>
> public class BinarySaveLoadTests
> {
> private byte[] data;
>
> @Test
> public void saveAnLoad() throws IOException
> {
> final ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new
> ResourceFactoryImpl() {
> @Override
> public Resource createResource(URI uri)
> {
> return new BinaryResourceImpl(uri);
> }
> });
>
> Resource resource =
> resourceSet.createResource(URI.createURI("binresource"));
>
> Model model = UMLFactory.eINSTANCE.createModel();
> model.setName("model");
>
> Enumeration en = model.createOwnedEnumeration("enum");
> en.createOwnedLiteral("lit1");
>
> resource.getContents().add(model);
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> resource.save(out, null);
> data = out.toByteArray();
>
> ResourceImpl resource2 = (ResourceImpl)
> resourceSet.createResource(URI.createURI("binresource2"));
> resource2.load(new ByteArrayInputStream(data), null);
>
> Model model2 = (Model) resource2.getContents().get(0);
>
> assertNotNull(model2);
> assertEquals(model2.getName(), "model");
> Assert.assertFalse(model.getOwnedElements().isEmpty());
> }
> }
>
>
> Its execution raises the following exception:
>
>
> java.lang.UnsupportedOperationException
> at
> org.eclipse.emf.common.util.BasicEList$UnmodifiableEList.grow(BasicEList.java:1029)
> at
> org.eclipse.emf.common.util.BasicEList.addAllUnique(BasicEList.java:495)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObjects(BinaryResourceImpl.java:2232)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadFeatureValue(BinaryResourceImpl.java:2555)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObject(BinaryResourceImpl.java:2522)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObjects(BinaryResourceImpl.java:2222)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadFeatureValue(BinaryResourceImpl.java:2555)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObject(BinaryResourceImpl.java:2522)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObjects(BinaryResourceImpl.java:2222)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadFeatureValue(BinaryResourceImpl.java:2555)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadEObject(BinaryResourceImpl.java:2522)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectInputStream.loadResource(BinaryResourceImpl.java:2205)
> at
> org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl.doLoad(BinaryResourceImpl.java:264)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
> at
> testumlbinary.BinarySaveLoadTests.saveAnLoad(BinarySaveLoadTests.java:55)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>
>
> Maybe I am doing something wrong, if so, please let me know. But the
> same code is working perfectly with previous UML2 Juno implementations.
>
> Could you help me to fix this issue?
> Thank you.
Re: Binary serialization broken with UML2 Kepler ? [message #1167242 is a reply to message #1166974] Sat, 02 November 2013 14:06 Go to previous messageGo to next message
Alexis Muller is currently offline Alexis Muller
Messages: 2
Registered: November 2013
Junior Member
Hi Ed,

Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=420938

Thank you,
Alexis
Re: Binary serialization broken with UML2 Kepler ? [message #1188246 is a reply to message #1167242] Fri, 15 November 2013 14:30 Go to previous message
Kenn Hussey is currently offline Kenn Hussey
Messages: 1618
Registered: July 2009
Senior Member
On 13-11-02 10:06 AM, Alexis Muller wrote:
> Hi Ed,
>
> Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=420938
>
> Thank you,
> Alexis

.... and fixed. This will be released in Kepler SR2 (February) and Luna
(June).

Kenn
Previous Topic:inheritance of stereotypes in subclasses
Next Topic:OCL expression
Goto Forum:
  


Current Time: Thu Oct 23 09:27:59 GMT 2014

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

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