[
https://issues.apache.org/jira/browse/METAMODEL-233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15175850#comment-15175850
]
Ankit Kumar commented on METAMODEL-233:
---------------------------------------
Debugged this issue further and what we see is that the query rewriting somehow
changes the SelectItem used in preparing the query. What we noticed is that the
"_query" element inside the SelectItem holds a completely different query than
the original submitted query and hence the ArrayIndexOutOfBound.
It goes wrong in the below code snippet inside SelectItem.java (clone) method.
final SelectItem subQuerySelectItem = (_subQuerySelectItem == null ? null :
_subQuerySelectItem.clone());
final FromItem fromItem;
if (_fromItem == null) {
fromItem = null;
} else if (clonedQuery != null && _query != null) {
final int indexOfFromItem =
_query.getFromClause().indexOf(_fromItem); // Goes wrong here Line 600.
if (indexOfFromItem != -1) {
fromItem = clonedQuery.getFromClause().getItem(indexOfFromItem);
Because the cloning somehow changes the original SelectItems used in query
preparation, it starts fails with this error for subsequent queries where we
use the same SelectItem objects.
> Compile query creation gives IndexOutOfBoundsException with v4.5.0
> ------------------------------------------------------------------
>
> Key: METAMODEL-233
> URL: https://issues.apache.org/jira/browse/METAMODEL-233
> Project: Apache MetaModel
> Issue Type: Bug
> Affects Versions: 4.5.0
> Reporter: Ankit Kumar
>
> With the upgrade to Metamodel 4.5.0 we notice existing Junits fail in compile
> query creation with IndexOutOfBoundsException during query rewriting.
> NOTE: The dao's and the Junits work with Metamodel v4.4.1.
> {code}
> Stacktrace : -
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.479 sec <<<
> FAILURE! - in com.hi.cdi.test.DbTestUtilsTest
> com.hi.cdi.test.DbTestUtilsTest Time elapsed: 0.479 sec <<< ERROR!
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'RawSourceDataDao': Injection of autowired dependencies failed;
> nested exception is org.springframework.beans.factory.BeanCreationException:
> Could not autowire field: private com.hi.cdi.datastore.SourceDataDao
> com.hi.cdi.rawdatastore.RawSourceDataDao.sourceDataDao; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'SourceDataDao': Invocation of init method failed; nested exception
> is java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
> at java.util.ArrayList.rangeCheck(ArrayList.java:653)
> at java.util.ArrayList.get(ArrayList.java:429)
> at
> org.apache.metamodel.query.AbstractQueryClause.getItem(AbstractQueryClause.java:111)
> at org.apache.metamodel.query.SelectItem.clone(SelectItem.java:602)
> at org.apache.metamodel.query.Query.clone(Query.java:606)
> at
> org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter.beforeRewrite(DefaultQueryRewriter.java:62)
> at
> org.apache.metamodel.jdbc.dialects.AbstractQueryRewriter.rewriteQuery(AbstractQueryRewriter.java:74)
> at
> org.apache.metamodel.jdbc.dialects.LimitOffsetQueryRewriter.rewriteQuery(LimitOffsetQueryRewriter.java:52)
> at
> org.apache.metamodel.jdbc.JdbcCompiledQuery.<init>(JdbcCompiledQuery.java:51)
> at
> org.apache.metamodel.jdbc.JdbcDataContext.compileQuery(JdbcDataContext.java:306)
> at
> com.hi.cdi.datastore.SourceDataDao.getCompiledQueryToGetDistinctRecordTypesFromSourceData(SourceDataDao.java:1298)
> at
> com.hi.cdi.datastore.SourceDataDao.initSchemaObjects(SourceDataDao.java:131)
> at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:497)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)