SELECT ... ORDER BY array index out of bounds exception
bwallis42 Dec 18, 2012 8:36 PMThe following bit of code with a select gives an arrayIndexOutOfBounds exception (modeshape 3.0.1.Final, java 1.6.0_37)
{code}
QueryManager queryManager = session.getWorkspace().getQueryManager();
ValueFactory vf = session.getValueFactory();
Query query = queryManager.createQuery(
"SELECT s.[inf:name], sc.[inf:order] FROM [inf:patient] AS p JOIN [inf:section] AS s ON ISCHILDNODE(s, p) JOIN [inf:sectionConfiguration] AS sc ON sc.[inf:name] = s.[inf:name] WHERE p.[inf:masterNs] = $ns AND p.[inf:masterId] = $urno ORDER BY sc.[inf:order] ASC, s.[inf:name] ASC",
Query.JCR_SQL2);
query.bindValue("urno", vf.createValue(urno));
query.bindValue("ns", vf.createValue(namespace));
QueryResult r = query.execute();
{code}
The exception occurs on execute(). I've tried some variations such as SELECT s.*, sc.* but the index is still 32 and the array is shorter than that (21 in that case).
{code}
java.lang.IndexOutOfBoundsException: Index: 32, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at java.util.Collections$UnmodifiableList.get(Collections.java:1152)
at org.modeshape.jcr.query.process.ProcessingComponent.createDynamicOperation(ProcessingComponent.java:160)
at org.modeshape.jcr.query.process.SortValuesComponent.createSortComparator(SortValuesComponent.java:127)
at org.modeshape.jcr.query.process.SortValuesComponent.createSortComparator(SortValuesComponent.java:88)
at org.modeshape.jcr.query.process.SortValuesComponent.<init>(SortValuesComponent.java:53)
at org.modeshape.jcr.query.process.QueryProcessor.createComponent(QueryProcessor.java:346)
at org.modeshape.jcr.query.process.QueryProcessor.execute(QueryProcessor.java:88)
at org.modeshape.jcr.query.process.QueryEngine.execute(QueryEngine.java:140)
at org.modeshape.jcr.query.lucene.LuceneQueryEngine$1.getResults(LuceneQueryEngine.java:151)
at org.modeshape.jcr.query.JcrQuery.execute(JcrQuery.java:119)
at au.com.infomedix.cpf4.ds.PatientRecordOperations.getPatientSectionNames(PatientRecordOperations.java:211)
at au.com.infomedix.cpf4.ds.TestPatientRecordOperations.testGetPatientSectionNames(TestPatientRecordOperations.java:132)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
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)
{code}
Patient, section and sectionConfiguration are defined like so:
{code}
[inf:patient] > mix:versionable, nt:hierarchyNode
+ * (inf:patientId) COPY
+ * (inf:section) COPY
- inf:masterId (STRING) mandatory COPY
- inf:masterNs (STRING) mandatory COPY
[inf:section] > nt:hierarchyNode orderable abstract
- inf:name (STRING) mandatory COPY
[inf:configItem]
[inf:sectionConfiguration] > inf:configItem
- inf:name (STRING) COPY
- inf:episodal (BOOLEAN) COPY
- inf:colour (STRING) COPY
- inf:order (LONG) COPY
{code}
Thanks.