[JIRA] (HHH-14138) ScrollableResults closed unexpectedly when performing another query inside scroll loop
by Jamie Strachan (JIRA)
Jamie Strachan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYzNhODNmODJj... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiYzNhOD... ) HHH-14138 ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiYzNhOD... ) ScrollableResults closed unexpectedly when performing another query inside scroll loop ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiYzNhOD... )
Change By: Jamie Strachan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960... )
Using a second query while scrolling causes the ScrollableResults to be closed.
Minimal example:
{code:java}public static void main(String[] args)
{
EntityManager em = getEntityManager();
// Query to be used while scrolling. Can be Native or not,
// it doesn't seem to matter what the query is. ( I just wanted to keep it simple)
Query qExtra = em.createNativeQuery("SELECT 1");
Query q = em.createQuery("SELECT row FROM User row");
q.setMaxResults(10);
@SuppressWarnings("rawtypes")
org.hibernate.query.Query hibernateQuery = q.unwrap(org.hibernate.query.Query.class);
ScrollableResults sr = hibernateQuery.scroll();
while(sr.next())
{
// Comment this query out and function finishes normally
qExtra.getSingleResult();
}
em.close();
}{code}
Perhaps I am not supposed to unwrap the JPA2 query like that?
WIth Hibernate 5.1.0 and the following code to obtain a ScrollableResults, the example code works as expected:
{code:java}org.hibernate.Query query = ((org.hibernate.jpa.internal.QueryImpl)q).getHibernateQuery();
ScrollableResults sr = query.scroll(ScrollMode.FORWARD_ONLY);{code}
However, running 5.4.18, it does not appear to matter what query I issue inside the loop, it will close the result set.
The resulting exception from 5.4.18:
{noformat}Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:70)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:105)
at Test.main(Test.java:???)
Caused by: java.sql.SQLException: You can't operate on a closed ResultSet!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:691)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
... 1 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:685)
... 2 more{noformat}
Thanks for any help\!
Addendum:
I have tested the following code using the JPA2 getResultStream(), and it also produces the same exception:
{noformat}public static void main(String[] args)
{
EntityManager em = EntityManagerSingleton. getEntityManager();
Query qExtra = em.createNativeQuery("SELECT 1");
Query q = em.createQuery("SELECT row FROM User row");
q.getResultStream().forEach(row -> { qExtra.getSingleResult(); });
em.close();
}{noformat}
The exception from using getResultStream():
{noformat}Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:70)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:105)
at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
at java.util.Iterator.forEachRemaining(Iterator.java:115)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at org.hibernate.query.spi.StreamDecorator.forEach(StreamDecorator.java:155)
at Tester.main(Tester.java)
Caused by: java.sql.SQLException: You can't operate on a closed ResultSet!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:691)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
... 6 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:685)
... 7 more{noformat}
( https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:8f92423 )
4 years, 5 months
[JIRA] (HHH-14138) ScrollableResults closed unexpectedly when performing another query inside scroll loop
by Jamie Strachan (JIRA)
Jamie Strachan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMTUzNDZiOGQ0... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiMTUzND... ) HHH-14138 ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiMTUzND... ) ScrollableResults closed unexpectedly when performing another query inside scroll loop ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiMTUzND... )
Change By: Jamie Strachan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960... )
Using a second query while scrolling causes the ScrollableResults to be closed.
Minimal example:
{code:java}public static void main(String[] args)
{
EntityManager em = getEntityManager();
// Query to be used while scrolling. Can be Native or not,
// it doesn't seem to matter what the query is. ( I just wanted to keep it simple)
Query qExtra = em.createNativeQuery("SELECT 1");
Query q = em.createQuery("SELECT row FROM User row");
q.setMaxResults(10);
@SuppressWarnings("rawtypes")
org.hibernate.query.Query hibernateQuery = q.unwrap(org.hibernate.query.Query.class);
ScrollableResults sr = hibernateQuery.scroll();
while(sr.next())
{
// Comment this query out and function finishes normally
qExtra.getSingleResult();
}
em.close();
}{code}
Perhaps I am not supposed to unwrap the JPA2 query like that?
WIth Hibernate 5.1.0 and the following code to obtain a ScrollableResults, the example code works as expected:
{code:java}org.hibernate.Query query = ((org.hibernate.jpa.internal.QueryImpl)q).getHibernateQuery();
ScrollableResults sr = query.scroll(ScrollMode.FORWARD_ONLY);{code}
However, running 5.4.18, it does not appear to matter what query I issue inside the loop, it will close the result set.
The resulting exception from 5.4.18:
{noformat}Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:70)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:105)
at Test.main(Test.java:???)
Caused by: java.sql.SQLException: You can't operate on a closed ResultSet!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:691)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
... 1 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:685)
... 2 more{noformat}
Thanks for any help\!
Addendum:
I have tested the following code using the JPA2 getResultStream(), and it also produces the same exception:
\ { code:java}
{ noformat}public static void main(String[] args)
{
EntityManager em = EntityManagerSingleton.getEntityManager();
Query qExtra = em.createNativeQuery("SELECT 1");
Query q = em.createQuery("SELECT row FROM User row");
q.getResultStream().forEach(row -> { qExtra.getSingleResult(); });
em.close();
}{noformat}
\{code}
The exception from using getResultStream():
\ {noformat}
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:70)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:105)
at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
at java.util.Iterator.forEachRemaining(Iterator.java:115)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at org.hibernate.query.spi.StreamDecorator.forEach(StreamDecorator.java:155)
at Tester.main(Tester.java)
Caused by: java.sql.SQLException: You can't operate on a closed ResultSet \ ! \ ! \ !
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:691)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
... 6 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:685)
... 7 more
\ {noformat}
( https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:8f92423 )
4 years, 5 months
[JIRA] (HHH-14138) ScrollableResults closed unexpectedly when performing another query inside scroll loop
by Jamie Strachan (JIRA)
Jamie Strachan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYmNkMDhiMDQ1... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiYmNkMD... ) HHH-14138 ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiYmNkMD... ) ScrollableResults closed unexpectedly when performing another query inside scroll loop ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiYmNkMD... )
Change By: Jamie Strachan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960... )
Using a second query while scrolling causes the ScrollableResults to be closed.
Minimal example:
{code:java}
public static void main(String[] args)
{
EntityManager em = getEntityManager();
// Query to be used while scrolling. Can be Native or not,
// it doesn't seem to matter what the query is. ( I just wanted to keep it simple)
Query qExtra = em.createNativeQuery("SELECT 1");
Query q = em.createQuery("SELECT row FROM User row");
q.setMaxResults(10);
@SuppressWarnings("rawtypes")
org.hibernate.query.Query hibernateQuery = q.unwrap(org.hibernate.query.Query.class);
ScrollableResults sr = hibernateQuery.scroll();
while(sr.next())
{
// Comment this query out and function finishes normally
qExtra.getSingleResult();
}
em.close();
}
{code}
Perhaps I am not supposed to unwrap the JPA2 query like that?
WIth Hibernate 5.1.0 and the following code to obtain a ScrollableResults, the example code works as expected:
{code:java}
org.hibernate.Query query = ((org.hibernate.jpa.internal.QueryImpl)q).getHibernateQuery();
ScrollableResults sr = query.scroll(ScrollMode.FORWARD_ONLY);
{code}
However, running 5.4.18, it does not appear to matter what query I issue inside the loop, it will close the result set.
The resulting exception from 5.4.18:
{noformat}
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:70)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:105)
at Test.main(Test.java:???)
Caused by: java.sql.SQLException: You can't operate on a closed ResultSet!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:691)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
... 1 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:685)
... 2 more
{noformat}
Thanks for any help \ !
Addendum:
I have tested the following code using the JPA2 getResultStream(), and it also produces the same exception:
\{code:java}
{noformat}public static void main(String[] args)
{
EntityManager em = EntityManagerSingleton.getEntityManager();
Query qExtra = em.createNativeQuery("SELECT 1");
Query q = em.createQuery("SELECT row FROM User row");
q.getResultStream().forEach(row -> { qExtra.getSingleResult(); });
em.close();
}{noformat}
\{code}
The exception from using getResultStream():
\{noformat}
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:70)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:105)
at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
at java.util.Iterator.forEachRemaining(Iterator.java:115)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at org.hibernate.query.spi.StreamDecorator.forEach(StreamDecorator.java:155)
at Tester.main(Tester.java)
Caused by: java.sql.SQLException: You can't operate on a closed ResultSet\!\!\!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:691)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
... 6 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:685)
... 7 more
\{noformat}
( https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:8f92423 )
4 years, 5 months
[JIRA] (HV-1796) Kotlin extension function on parameterized type leads to ArrayIndexOutOfBoundsException during validateParameters
by Frédéric Chuong (JIRA)
Frédéric Chuong ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate Validator ( https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiMDY4NzIxM2U0N... ) / Bug ( https://hibernate.atlassian.net/browse/HV-1796?atlOrigin=eyJpIjoiMDY4NzIx... ) HV-1796 ( https://hibernate.atlassian.net/browse/HV-1796?atlOrigin=eyJpIjoiMDY4NzIx... ) Kotlin extension function on parameterized type leads to ArrayIndexOutOfBoundsException during validateParameters ( https://hibernate.atlassian.net/browse/HV-1796?atlOrigin=eyJpIjoiMDY4NzIx... )
Change By: Frédéric Chuong ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
h1. Context
* Method constraints validation
* Kotlin
** Presence of extension function on parameterized type within the validated object
h1. Problem
Given the following code making use of method constraint validation
*SimpleFooService.kt*
{noformat}package foo
import org.slf4j.LoggerFactory
import javax.validation.Validation
import javax.validation.constraints.NotEmpty
class SimpleFooService {
fun methodName(@NotEmpty ignored: String) {
// no-op
}
private fun List<String>.someExtensionFunction(extensionFunctionArg: Int) = Unit
}
fun main() {
val validator = Validation.buildDefaultValidatorFactory().validator
val executableValidator = validator.forExecutables()
try {
executableValidator.validateParameters(
SimpleFooService(),
SimpleFooService::class.java.getDeclaredMethod(SimpleFooService::methodName.name, String::class.java),
arrayOf("Some value")
)
} catch (e: Exception) {
log.error("Error", e)
}
}
val log = LoggerFactory.getLogger(SimpleFooService::class.java){noformat}
Attempting to execute the code leads to {{ArrayIndexOutOfBoundsException}} and the given arguments not being validated:
{noformat}2020-08-04 16:14:41,937 [main] DEBUG - org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
2020-08-04 16:14:41,949 [main] INFO - org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.1.5.Final
2020-08-04 16:14:41,975 [main] DEBUG - org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
2020-08-04 16:14:41,977 [main] DEBUG - org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
2020-08-04 16:14:41,979 [main] DEBUG - org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
2020-08-04 16:14:41,980 [main] DEBUG - org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
2020-08-04 16:14:41,986 [main] DEBUG - org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
2020-08-04 16:14:42,083 [main] DEBUG - org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
2020-08-04 16:14:42,434 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000252: Using org.hibernate.validator.internal.engine.DefaultPropertyNodeNameProvider as property node name provider.
2020-08-04 16:14:42,443 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
2020-08-04 16:14:42,443 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
2020-08-04 16:14:42,443 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
2020-08-04 16:14:42,444 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
2020-08-04 16:14:42,444 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
2020-08-04 16:14:42,541 [main] ERROR - foo.SimpleFooService - Error
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getTypeParametersCascadingMetaDataForParameterizedType(AnnotationMetaDataProvider.java:678) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getTypeParametersCascadingMetadata(AnnotationMetaDataProvider.java:660) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findCascadingMetaData(AnnotationMetaDataProvider.java:627) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getParameterMetaData(AnnotationMetaDataProvider.java:432) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findExecutableMetaData(AnnotationMetaDataProvider.java:308) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getMetaData(AnnotationMetaDataProvider.java:292) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getMethodMetaData(AnnotationMetaDataProvider.java:279) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.java:130) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.java:120) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanConfigurationForHierarchy(BeanMetaDataManagerImpl.java:234) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.createBeanMetaData(BeanMetaDataManagerImpl.java:201) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanMetaData(BeanMetaDataManagerImpl.java:165) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:267) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:235) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at foo.FooServiceKt.main(FooService.kt:19) ~[main/:na]
at foo.FooServiceKt.main(FooService.kt) ~[main/:na]{noformat}
h1. Preliminary analysis
Debugging reveals that {{org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider#findExecutableMetaData}} [is retrieving|https://github.com/hibernate/hibernate-validator/blob/6.1.5.Fi...] a an incorrect {{JavaBeanExecutable}} result from {{JavaBeanHelper}} when processing the {{private final void foo.SimpleFooService.someExtensionFunction(java.util.List,int)}} method:
!image-2020-08-05-00-24-18-321.png|width=200,height=183!
(!) The {{extensionFunctionArg}} argument has the {{List<String>}} type associated to it, instead of {{int}}
That inconsistency causes {{AnnotationMetaDataProvider.getTypeParametersCascadingMetaDataForParameterizedType}} to fail.
h1. Workaround
Workaround is to remove all extension functions on parameterized receiver from the validated class (which may not be desirable).
h1. Build setup
*build.gradle.kts*
{noformat}import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
plugins {
kotlin("jvm") version "1.3.72"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.3.2.RELEASE"))
implementation("org.slf4j:slf4j-api")
implementation("ch.qos.logback:logback-classic")
implementation("org.hibernate.validator:hibernate-validator")
implementation("org.glassfish:jakarta.el")
}
tasks {
"wrapper"(Wrapper::class) {
gradleVersion = "6.5.1"
distributionType = Wrapper.DistributionType.ALL
}
withType<KotlinCompile<KotlinJvmOptions>>().configureEach {
kotlinOptions {
jvmTarget = "11"
javaParameters = true
}
}
}{noformat}
( https://hibernate.atlassian.net/browse/HV-1796#add-comment?atlOrigin=eyJp... ) Add Comment ( https://hibernate.atlassian.net/browse/HV-1796#add-comment?atlOrigin=eyJp... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:8f92423 )
4 years, 5 months
[JIRA] (HV-1796) Kotlin extension function on parameterized type leads to ArrayIndexOutOfBoundsException during validateParameters
by Frédéric Chuong (JIRA)
Frédéric Chuong ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate Validator ( https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiNDA0MWI4NWUzY... ) / Bug ( https://hibernate.atlassian.net/browse/HV-1796?atlOrigin=eyJpIjoiNDA0MWI4... ) HV-1796 ( https://hibernate.atlassian.net/browse/HV-1796?atlOrigin=eyJpIjoiNDA0MWI4... ) Kotlin extension function on parameterized type leads to ArrayIndexOutOfBoundsException during validateParameters ( https://hibernate.atlassian.net/browse/HV-1796?atlOrigin=eyJpIjoiNDA0MWI4... )
Change By: Frédéric Chuong ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
h1. Context
* Method constraints validation
* Kotlin
** Presence of extension function on parameterized type within the validated object
h1. Problem
Given the following code making use of method constraint validation
*SimpleFooService.kt*
{noformat}package foo
import org.slf4j.LoggerFactory
import javax.validation.Validation
import javax.validation.constraints.NotEmpty
class SimpleFooService {
fun methodName(@NotEmpty ignored: String) {
// no-op
}
private fun List<String>.someExtensionFunction(extensionFunctionArg: Int) = Unit
}
fun main() {
val validator = Validation.buildDefaultValidatorFactory().validator
val executableValidator = validator.forExecutables()
try {
executableValidator.validateParameters(
SimpleFooService(),
SimpleFooService::class.java.getDeclaredMethod(SimpleFooService::methodName.name, String::class.java),
arrayOf("Some value")
)
} catch (e: Exception) {
log.error("Error", e)
}
}
val log = LoggerFactory.getLogger(SimpleFooService::class.java){noformat}
Attempting to execute the code leads to {{ArrayIndexOutOfBoundsException}} and the given arguments not being validated:
{noformat}2020-08-04 16:14:41,937 [main] DEBUG - org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
2020-08-04 16:14:41,949 [main] INFO - org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.1.5.Final
2020-08-04 16:14:41,975 [main] DEBUG - org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
2020-08-04 16:14:41,977 [main] DEBUG - org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
2020-08-04 16:14:41,979 [main] DEBUG - org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
2020-08-04 16:14:41,980 [main] DEBUG - org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
2020-08-04 16:14:41,986 [main] DEBUG - org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
2020-08-04 16:14:42,083 [main] DEBUG - org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
2020-08-04 16:14:42,434 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000252: Using org.hibernate.validator.internal.engine.DefaultPropertyNodeNameProvider as property node name provider.
2020-08-04 16:14:42,443 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
2020-08-04 16:14:42,443 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
2020-08-04 16:14:42,443 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
2020-08-04 16:14:42,444 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
2020-08-04 16:14:42,444 [main] DEBUG - org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
2020-08-04 16:14:42,541 [main] ERROR - foo.SimpleFooService - Error
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getTypeParametersCascadingMetaDataForParameterizedType(AnnotationMetaDataProvider.java:678) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getTypeParametersCascadingMetadata(AnnotationMetaDataProvider.java:660) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findCascadingMetaData(AnnotationMetaDataProvider.java:627) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getParameterMetaData(AnnotationMetaDataProvider.java:432) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findExecutableMetaData(AnnotationMetaDataProvider.java:308) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getMetaData(AnnotationMetaDataProvider.java:292) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getMethodMetaData(AnnotationMetaDataProvider.java:279) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.java:130) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.java:120) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanConfigurationForHierarchy(BeanMetaDataManagerImpl.java:234) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.createBeanMetaData(BeanMetaDataManagerImpl.java:201) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanMetaData(BeanMetaDataManagerImpl.java:165) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:267) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:235) ~[hibernate-validator-6.1.5.Final.jar:6.1.5.Final]
at foo.FooServiceKt.main(FooService.kt:19) ~[main/:na]
at foo.FooServiceKt.main(FooService.kt) ~[main/:na]{noformat}
h1. Preliminary analysis
Debugging reveals that {{org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider#findExecutableMetaData}} [ is retrieving |https://github.com/hibernate/hibernate-validator/blob/6.1.5.Final/engine/src/main/java/org/hibernate/validator/internal/metadata/provider/AnnotationMetaDataProvider.java#L307] a incorrect {{JavaBeanExecutable}} result from {{JavaBeanHelper}} when processing the {{private final void foo.SimpleFooService.someExtensionFunction(java.util.List,int)}} method:
!image-2020-08-05-00-24-18-321.png|width=200,height=183!
(!) The {{extensionFunctionArg}} argument has the {{List<String>}} type associated to it, instead of {{int}}
That inconsistency causes {{AnnotationMetaDataProvider.getTypeParametersCascadingMetaDataForParameterizedType}} to fail.
h1. Workaround
Workaround is to remove all extension functions on parameterized receiver from the validated class (which may not be desirable).
h1. Build setup
*build.gradle.kts*
{ code:java noformat }import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
plugins {
kotlin("jvm") version "1.3.72"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.3.2.RELEASE"))
implementation("org.slf4j:slf4j-api")
implementation("ch.qos.logback:logback-classic")
implementation("org.hibernate.validator:hibernate-validator")
implementation("org.glassfish:jakarta.el")
}
tasks {
"wrapper"(Wrapper::class) {
gradleVersion = "6.5.1"
distributionType = Wrapper.DistributionType.ALL
}
withType<KotlinCompile<KotlinJvmOptions>>().configureEach {
kotlinOptions {
jvmTarget = "11"
javaParameters = true
}
}
}{ code noformat }
( https://hibernate.atlassian.net/browse/HV-1796#add-comment?atlOrigin=eyJp... ) Add Comment ( https://hibernate.atlassian.net/browse/HV-1796#add-comment?atlOrigin=eyJp... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:8f92423 )
4 years, 5 months