Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » IndexOutOfBoundsException
IndexOutOfBoundsException [message #426585] Wed, 14 January 2009 20:31 Go to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Hello,
Maybe I'm doing something wrong, but I get an index out of bounds on the following code (last
line). Here is my unit test (session and LOCATION are created in the setup() function):

// Create a view and fail to get something
CDOView view = session.openView();

// Load the autoSubmitter Roots
Resource resource;
try
{
resource = view.getResource(LOCATION);
}
catch(Exception e) //TODO Catch something better than exception
{
// We think this means that there is no resource and nothing in the resource
// so we'll fix that
CDOTransaction transaction = session.openTransaction();
resource = transaction.getOrCreateResource(LOCATION);
resource.getContents().add(DirectoryFactory.eINSTANCE.create Folder());
transaction.commit();
transaction.close();
resource = view.getResource(LOCATION);
}
Folder folder = (Folder) resource.getContents().get(0);

The resource.getResource(LOCATION) throws an exception since the repository has no resources in it
(it is brand new everytime I run the test). The last line (resource.getContents().get(0)) throws
this exception, even though the contents of the catch block execute successfully:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:572)
at java.util.ArrayList.get(ArrayList.java:347)
at org.eclipse.emf.cdo.spi.common.AbstractCDORevision.get(Abstr actCDORevision.java:360)
at org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:174)
at
org.eclipse.emf.ecore.impl.EStoreEObjectImpl$BasicEStoreELis t.delegateGet(EStoreEObjectImpl.java:225)
at org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
at com.ibm.hdwb.jobs.server.cdo.junit.TestCDO.testTransactionsA ndView(TestCDO.java:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:195)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:366)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 550)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:505)
at org.eclipse.equinox.launcher.Main.run(Main.java:1237)
at org.eclipse.equinox.launcher.Main.main(Main.java:1213)

If you remove the try/catch block (and the view.getResource(LOCATION) line) then it works fine.

Any thoughts on what I might be doing wrong? Thanks!

--Stephen
Re: [CDO] IndexOutOfBoundsException [message #426586 is a reply to message #426585] Wed, 14 January 2009 20:59 Go to previous messageGo to next message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Oops.. I forgot to mark this thread as CDO specific.
--Stephen

Stephen McCants wrote:
> Hello,
> Maybe I'm doing something wrong, but I get an index out of bounds on
> the following code (last line). Here is my unit test (session and
> LOCATION are created in the setup() function):
>
> // Create a view and fail to get something
> CDOView view = session.openView();
>
> // Load the autoSubmitter Roots
> Resource resource;
> try
> {
> resource = view.getResource(LOCATION);
> }
> catch(Exception e) //TODO Catch something better than exception
> {
> // We think this means that there is no resource and nothing in
> the resource
> // so we'll fix that
> CDOTransaction transaction = session.openTransaction();
> resource = transaction.getOrCreateResource(LOCATION);
>
> resource.getContents().add(DirectoryFactory.eINSTANCE.create Folder());
> transaction.commit();
> transaction.close();
> resource = view.getResource(LOCATION);
> }
> Folder folder = (Folder) resource.getContents().get(0);
>
> The resource.getResource(LOCATION) throws an exception since the
> repository has no resources in it (it is brand new everytime I run the
> test). The last line (resource.getContents().get(0)) throws this
> exception, even though the contents of the catch block execute
> successfully:
>
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> at java.util.ArrayList.RangeCheck(ArrayList.java:572)
> at java.util.ArrayList.get(ArrayList.java:347)
> at
> org.eclipse.emf.cdo.spi.common.AbstractCDORevision.get(Abstr actCDORevision.java:360)
>
> at org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:174)
> at
> org.eclipse.emf.ecore.impl.EStoreEObjectImpl$BasicEStoreELis t.delegateGet(EStoreEObjectImpl.java:225)
>
> at
> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
> at
> com.ibm.hdwb.jobs.server.cdo.junit.TestCDO.testTransactionsA ndView(TestCDO.java:174)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:618)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>
> at
> org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>
> at
> org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:618)
> at
> org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:195)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:366)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:618)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 550)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:505)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1237)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1213)
>
> If you remove the try/catch block (and the view.getResource(LOCATION)
> line) then it works fine.
>
> Any thoughts on what I might be doing wrong? Thanks!
>
> --Stephen
Re: IndexOutOfBoundsException [message #426587 is a reply to message #426585] Wed, 14 January 2009 21:13 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
HI Stephen,

The problems seems to be the following:

// The following throw an exception(like you already know) but.. the
// resource is added to the resourceset with getErrors
resource = view.getResource(LOCATION);

At the end when you are doing the following:

> transaction.close();
> resource = view.getResource(LOCATION); <<<<<<<<<<<<<<<
> }
> Folder folder = (Folder) resource.getContents().get(0);

It grabs the TRANSIENT Object that isn't related at all with what you
have in your view.

I'm not sure if it is a problem since adding EMF does add resource to
the resourceset even if it has errors at load time. It is the normal
behavior.
Maybe you could do the following:

if (!view.hasResource(LOCATION))
{
CDOTransaction transaction = session.openTransaction();
Resource resource = transaction.getOrCreateResource(LOCATION);
resource.getContents().add(getModel1Factory().createCategory ());
transaction.commit();
transaction.close();
}
Resource resource = view.getResource(LOCATION);

Category folder = (Category)resource.getContents().get(0);

Does it make sense ?

Simon


Stephen McCants wrote:
> Hello,
> Maybe I'm doing something wrong, but I get an index out of bounds on
> the following code (last line). Here is my unit test (session and
> LOCATION are created in the setup() function):
>
> // Create a view and fail to get something
> CDOView view = session.openView();
>
> // Load the autoSubmitter Roots
> Resource resource;
> try
> {
> resource = view.getResource(LOCATION);
> }
> catch(Exception e) //TODO Catch something better than exception
> {
> // We think this means that there is no resource and nothing in
> the resource
> // so we'll fix that
> CDOTransaction transaction = session.openTransaction();
> resource = transaction.getOrCreateResource(LOCATION);
>
> resource.getContents().add(DirectoryFactory.eINSTANCE.create Folder());
> transaction.commit();
> transaction.close();
> resource = view.getResource(LOCATION);
> }
> Folder folder = (Folder) resource.getContents().get(0);
>
> The resource.getResource(LOCATION) throws an exception since the
> repository has no resources in it (it is brand new everytime I run the
> test). The last line (resource.getContents().get(0)) throws this
> exception, even though the contents of the catch block execute
> successfully:
>
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> at java.util.ArrayList.RangeCheck(ArrayList.java:572)
> at java.util.ArrayList.get(ArrayList.java:347)
> at
> org.eclipse.emf.cdo.spi.common.AbstractCDORevision.get(Abstr actCDORevision.java:360)
>
> at org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:174)
> at
> org.eclipse.emf.ecore.impl.EStoreEObjectImpl$BasicEStoreELis t.delegateGet(EStoreEObjectImpl.java:225)
>
> at
> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
> at
> com.ibm.hdwb.jobs.server.cdo.junit.TestCDO.testTransactionsA ndView(TestCDO.java:174)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:618)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>
> at
> org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>
> at
> org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:618)
> at
> org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:195)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:366)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:618)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 550)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:505)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1237)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1213)
>
> If you remove the try/catch block (and the view.getResource(LOCATION)
> line) then it works fine.
>
> Any thoughts on what I might be doing wrong? Thanks!
>
> --Stephen
Re: [CDO] IndexOutOfBoundsException [message #426588 is a reply to message #426586] Wed, 14 January 2009 21:14 Go to previous messageGo to next message
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
I knew... I recognized your name!! :-)

Simon


Stephen McCants wrote:
> Oops.. I forgot to mark this thread as CDO specific.
> --Stephen
>
> Stephen McCants wrote:
>> Hello,
>> Maybe I'm doing something wrong, but I get an index out of bounds
>> on the following code (last line). Here is my unit test (session and
>> LOCATION are created in the setup() function):
>>
>> // Create a view and fail to get something
>> CDOView view = session.openView();
>>
>> // Load the autoSubmitter Roots
>> Resource resource;
>> try
>> {
>> resource = view.getResource(LOCATION);
>> }
>> catch(Exception e) //TODO Catch something better than exception
>> {
>> // We think this means that there is no resource and nothing
>> in the resource
>> // so we'll fix that
>> CDOTransaction transaction = session.openTransaction();
>> resource = transaction.getOrCreateResource(LOCATION);
>>
>> resource.getContents().add(DirectoryFactory.eINSTANCE.create Folder());
>> transaction.commit();
>> transaction.close();
>> resource = view.getResource(LOCATION);
>> }
>> Folder folder = (Folder) resource.getContents().get(0);
>>
>> The resource.getResource(LOCATION) throws an exception since the
>> repository has no resources in it (it is brand new everytime I run the
>> test). The last line (resource.getContents().get(0)) throws this
>> exception, even though the contents of the catch block execute
>> successfully:
>>
>> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>> at java.util.ArrayList.RangeCheck(ArrayList.java:572)
>> at java.util.ArrayList.get(ArrayList.java:347)
>> at
>> org.eclipse.emf.cdo.spi.common.AbstractCDORevision.get(Abstr actCDORevision.java:360)
>>
>> at org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:174)
>> at
>> org.eclipse.emf.ecore.impl.EStoreEObjectImpl$BasicEStoreELis t.delegateGet(EStoreEObjectImpl.java:225)
>>
>> at
>> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
>> at
>> com.ibm.hdwb.jobs.server.cdo.junit.TestCDO.testTransactionsA ndView(TestCDO.java:174)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:618)
>> at
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>>
>> at
>> org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>>
>> at
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>>
>> at
>> org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>>
>> at
>> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>
>> at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>>
>> at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>>
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at
>> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>>
>> at
>> org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>>
>> at
>> org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:618)
>> at
>> org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>>
>> at
>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:195)
>>
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>>
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>>
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:366)
>>
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:618)
>> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 550)
>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:505)
>> at org.eclipse.equinox.launcher.Main.run(Main.java:1237)
>> at org.eclipse.equinox.launcher.Main.main(Main.java:1213)
>>
>> If you remove the try/catch block (and the view.getResource(LOCATION)
>> line) then it works fine.
>>
>> Any thoughts on what I might be doing wrong? Thanks!
>>
>> --Stephen
Re: IndexOutOfBoundsException [message #426602 is a reply to message #426585] Thu, 15 January 2009 14:51 Go to previous messageGo to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 307
Registered: July 2009
Location: Germany
Senior Member
Hi,
> catch(Exception e) //TODO Catch something better than exception
> {
> // We think this means that there is no resource and nothing
> in the resource
> // so we'll fix that
>
this is a problem of wrong expectations :-)
I also used to expect getResource not being correct (see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=217240)
The reason is that in plain EMF is not supposed to throw an exception
(or even to return null) if a resource does not exist.

In CDO, nowadays you can either use the way described in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247457
to check if a resource exists, or you can (simply) use
getOrCreateResource() if you are using a transaction (as described in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=217236).

Cheers,
Stefan
Re: IndexOutOfBoundsException [message #426675 is a reply to message #426587] Fri, 16 January 2009 23:33 Go to previous message
Stephen McCants is currently offline Stephen McCantsFriend
Messages: 92
Registered: July 2009
Member
Hi Simon,
hasResource does what I need. Thanks for your help!

--Stephen

Simon McDuff wrote:
>
> HI Stephen,
>
> The problems seems to be the following:
>
> // The following throw an exception(like you already know) but.. the
> // resource is added to the resourceset with getErrors
> resource = view.getResource(LOCATION);
>
> At the end when you are doing the following:
>
> > transaction.close();
> > resource = view.getResource(LOCATION); <<<<<<<<<<<<<<<
> > }
> > Folder folder = (Folder) resource.getContents().get(0);
>
> It grabs the TRANSIENT Object that isn't related at all with what you
> have in your view.
>
> I'm not sure if it is a problem since adding EMF does add resource to
> the resourceset even if it has errors at load time. It is the normal
> behavior.
> Maybe you could do the following:
>
> if (!view.hasResource(LOCATION))
> {
> CDOTransaction transaction = session.openTransaction();
> Resource resource = transaction.getOrCreateResource(LOCATION);
> resource.getContents().add(getModel1Factory().createCategory ());
> transaction.commit();
> transaction.close();
> }
> Resource resource = view.getResource(LOCATION);
>
> Category folder = (Category)resource.getContents().get(0);
>
> Does it make sense ?
>
> Simon
>
>
> Stephen McCants wrote:
>> Hello,
>> Maybe I'm doing something wrong, but I get an index out of bounds
>> on the following code (last line). Here is my unit test (session and
>> LOCATION are created in the setup() function):
>>
>> // Create a view and fail to get something
>> CDOView view = session.openView();
>>
>> // Load the autoSubmitter Roots
>> Resource resource;
>> try
>> {
>> resource = view.getResource(LOCATION);
>> }
>> catch(Exception e) //TODO Catch something better than exception
>> {
>> // We think this means that there is no resource and nothing
>> in the resource
>> // so we'll fix that
>> CDOTransaction transaction = session.openTransaction();
>> resource = transaction.getOrCreateResource(LOCATION);
>>
>> resource.getContents().add(DirectoryFactory.eINSTANCE.create Folder());
>> transaction.commit();
>> transaction.close();
>> resource = view.getResource(LOCATION);
>> }
>> Folder folder = (Folder) resource.getContents().get(0);
>>
>> The resource.getResource(LOCATION) throws an exception since the
>> repository has no resources in it (it is brand new everytime I run the
>> test). The last line (resource.getContents().get(0)) throws this
>> exception, even though the contents of the catch block execute
>> successfully:
>>
>> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>> at java.util.ArrayList.RangeCheck(ArrayList.java:572)
>> at java.util.ArrayList.get(ArrayList.java:347)
>> at
>> org.eclipse.emf.cdo.spi.common.AbstractCDORevision.get(Abstr actCDORevision.java:360)
>>
>> at org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:174)
>> at
>> org.eclipse.emf.ecore.impl.EStoreEObjectImpl$BasicEStoreELis t.delegateGet(EStoreEObjectImpl.java:225)
>>
>> at
>> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
>> at
>> com.ibm.hdwb.jobs.server.cdo.junit.TestCDO.testTransactionsA ndView(TestCDO.java:174)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:618)
>> at
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>>
>> at
>> org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>>
>> at
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>>
>> at
>> org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>>
>> at
>> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>
>> at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>>
>> at
>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>>
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at
>> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>>
>> at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>>
>> at
>> org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>>
>> at
>> org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:618)
>> at
>> org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>>
>> at
>> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:195)
>>
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>>
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>>
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:366)
>>
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:79)
>>
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
>>
>> at java.lang.reflect.Method.invoke(Method.java:618)
>> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 550)
>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:505)
>> at org.eclipse.equinox.launcher.Main.run(Main.java:1237)
>> at org.eclipse.equinox.launcher.Main.main(Main.java:1213)
>>
>> If you remove the try/catch block (and the view.getResource(LOCATION)
>> line) then it works fine.
>>
>> Any thoughts on what I might be doing wrong? Thanks!
>>
>> --Stephen
Previous Topic:How to update objects within XMIResource?
Next Topic:Notifying container of its child's feature changes
Goto Forum:
  


Current Time: Fri Apr 26 23:03:03 GMT 2024

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

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

Back to the top