Bug 260 : IndexOutOfBoundsException with lazy load on ... query joined *ToMany with filterMany
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.6.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
31/03/2010
Updated 
31/03/2010
Type 
Bug
 
Attachments 
No attachments

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.avaje.ebeaninternal.server.core.DefaultBeanLoader.loadMany(DefaultBeanLoader.java:124)
at com.avaje.ebeaninternal.server.core.DefaultServer.loadMany(DefaultServer.java:439)
at com.avaje.ebeaninternal.server.loadcontext.DLoadManyContext.loadMany(DLoadManyContext.java:143)
at com.avaje.ebean.common.AbstractBeanCollection.lazyLoadCollection(AbstractBeanCollection.java:152)
at com.avaje.ebean.common.BeanList.init(BeanList.java:116)
at com.avaje.ebean.common.BeanList.size(BeanList.java:402)
at unittest.TestOne.testFilterOutOfBoundsException(TestOne.java:664)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
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)

 
Rob 31 Mar 01:45
Daryl provided a test case

The issue revolves around loading of *ToMany relationships via +query or +lazy.

Specifically, if there are no rows for a given beanCollection (due to say predicates on a filterMany) then the state of the BeanCollection is not correctly updated (to reflect that the BeanCollection is loaded but empty).

The fix is to check the +query and +lazy loaded BeanCollections to make sure that if they where not loaded that their state is now "loaded but empty".

Rob 31 Mar 01:51
DefaultBeanLoader

Added in some checking on DefaultBeanLoader to check each loaded BeanCollection for the case that it's state was not set due to no matching rows.

// check for BeanCollection's that where never processed
		// in the +query or +lazy load due to no rows (predicates)
		for (int i = 0; i < batch.size(); i++) {
		    if (batch.get(i).checkEmptyLazyLoad()) {
		        if (logger.isLoggable(Level.FINE)){
	                logger.fine("BeanCollection after load was empty owner:"+batch.get(i).getOwnerBean());
		        }
		    }
        }

Rob 31 Mar 01:54
Fixed in HEAD.

Fixed in HEAD.

woResponse

Upload a file