java.lang.StringIndexOutOfBoundsException: String index out of range: -5

Hibernate JIRA | Dmitry Tolmachov | 3 years ago
  1. 0

    In one specific situation the Hibernate fails to parse the JPQL query correctly. When there is "select" query with "left outer join" with "select size" on join part - the hiberante falls with "String index out of range: -5" exception. I first encountered this with MSSQL database, and then succesfully reproduced the bug with HSQL database. I will attach to this issue a simple maven project that reproduces this bug. The JPQL query, that makes hibernate fall looks like this: "Select a, b.size from EntityA a left outer join a.entityBList b"; Strangely, if you change in that query "left outer join" to "join", it Hibernate stops from falling with exception. Here is full stacktrace: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -5 at java.lang.String.substring(String.java:1875) at org.hibernate.hql.internal.CollectionSubqueryFactory.createCollectionSubquery(CollectionSubqueryFactory.java:52) at org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:400) at org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:382) at org.hibernate.hql.internal.ast.tree.FromElement.toColumns(FromElement.java:504) at org.hibernate.hql.internal.ast.tree.DotNode.getColumns(DotNode.java:139) at org.hibernate.hql.internal.ast.tree.DotNode.initText(DotNode.java:261) at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:255) at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:126) at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:121) at org.hibernate.hql.internal.ast.tree.DotNode.resolveSelectExpression(DotNode.java:711) at org.hibernate.hql.internal.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:957) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2248) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2185) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1471) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:278) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1796) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)

    Hibernate JIRA | 3 years ago | Dmitry Tolmachov
    java.lang.StringIndexOutOfBoundsException: String index out of range: -5
  2. 0

    In one specific situation the Hibernate fails to parse the JPQL query correctly. When there is "select" query with "left outer join" with "select size" on join part - the hiberante falls with "String index out of range: -5" exception. I first encountered this with MSSQL database, and then succesfully reproduced the bug with HSQL database. I will attach to this issue a simple maven project that reproduces this bug. The JPQL query, that makes hibernate fall looks like this: "Select a, b.size from EntityA a left outer join a.entityBList b"; Strangely, if you change in that query "left outer join" to "join", it Hibernate stops from falling with exception. Here is full stacktrace: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -5 at java.lang.String.substring(String.java:1875) at org.hibernate.hql.internal.CollectionSubqueryFactory.createCollectionSubquery(CollectionSubqueryFactory.java:52) at org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:400) at org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:382) at org.hibernate.hql.internal.ast.tree.FromElement.toColumns(FromElement.java:504) at org.hibernate.hql.internal.ast.tree.DotNode.getColumns(DotNode.java:139) at org.hibernate.hql.internal.ast.tree.DotNode.initText(DotNode.java:261) at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:255) at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:126) at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:121) at org.hibernate.hql.internal.ast.tree.DotNode.resolveSelectExpression(DotNode.java:711) at org.hibernate.hql.internal.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:957) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2248) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2185) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1471) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:278) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1796) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)

    Hibernate JIRA | 3 years ago | Dmitry Tolmachov
    java.lang.StringIndexOutOfBoundsException: String index out of range: -5
  3. 0

    java.lang.StringIndexOutOfBoundsException on some java classes

    GitHub | 3 years ago | micw
    java.lang.StringIndexOutOfBoundsException: String index out of range: -5
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    GitHub comment 131#189930440

    GitHub | 9 months ago | mbrlabs
    java.lang.StringIndexOutOfBoundsException: String index out of range: -5
  6. 0

    Unable to Reset AD Account Password for the reconciled accounts using OIM out of the box reset functionality

    Oracle Community | 5 months ago | 3010398
    java.lang.StringIndexOutOfBoundsException: String index out of range: -5

  1. richard77 2 times, last 4 days ago
  2. kjhdofjosvs 2 times, last 1 week ago
  3. archenroot 17 times, last 2 weeks ago
  4. Alexandru Popa 2 times, last 4 weeks ago
  5. poroszd 3 times, last 1 month ago
18 more registered users
58 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.StringIndexOutOfBoundsException

    String index out of range: -5

    at java.lang.String.substring()
  2. Java RT
    String.substring
    1. java.lang.String.substring(String.java:1875)
    1 frame
  3. Hibernate
    SessionImpl.createQuery
    1. org.hibernate.hql.internal.CollectionSubqueryFactory.createCollectionSubquery(CollectionSubqueryFactory.java:52)
    2. org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:400)
    3. org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:382)
    4. org.hibernate.hql.internal.ast.tree.FromElement.toColumns(FromElement.java:504)
    5. org.hibernate.hql.internal.ast.tree.DotNode.getColumns(DotNode.java:139)
    6. org.hibernate.hql.internal.ast.tree.DotNode.initText(DotNode.java:261)
    7. org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:255)
    8. org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:126)
    9. org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:121)
    10. org.hibernate.hql.internal.ast.tree.DotNode.resolveSelectExpression(DotNode.java:711)
    11. org.hibernate.hql.internal.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:957)
    12. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2248)
    13. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2185)
    14. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1471)
    15. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
    16. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
    17. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
    18. org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:278)
    19. org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
    20. org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
    21. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
    22. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
    23. org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
    24. org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
    25. org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
    26. org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1796)
    26 frames
  4. org.hibernate.jpa
    AbstractEntityManagerImpl.createQuery
    1. org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)
    1 frame