Issue with bean validation using hibernate-validator api and size validation.
Environment
- Red Hat JBoss Fuse
- 6.1.1
Issue
- User is facing a problem with Bean validation.
- User used the implementation suggested in https://access.redhat.com/solutions/734273
- Everything works as expected but when a
javax.validation.constraints.Sizeis not satisfied an exception is thrown:
Caused by: java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl not found by xxx.yyy.zzz [295]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)[:1.7.0_09]
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1870)
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:937)
at org.apache.cxf.bus.blueprint.BundleDelegatingClassLoader$1.run(BundleDelegatingClassLoader.java:54)[346:org.apache.cxf.cxf-rt-core:2.7.0.redhat-611412]
at org.apache.cxf.bus.blueprint.BundleDelegatingClassLoader$1.run(BundleDelegatingClassLoader.java:52)[346:org.apache.cxf.cxf-rt-core:2.7.0.redhat-611412]
at java.security.AccessController.doPrivileged(Native Method)[:1.7.0_09]
at org.apache.cxf.bus.blueprint.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:52)[346:org.apache.cxf.cxf-rt-core:2.7.0.redhat-611412]
at org.apache.cxf.bus.blueprint.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:110)[346:org.apache.cxf.cxf-rt-core:2.7.0.redhat-611412]
- Constrains of type
javax.validation.constraints.NotNullwork without throwing errors. - It seems that the
javax.el.ExpressionFactoryfactory is using bundle A classloader to instantiate thecom.sun.el.ExpressionFactoryImpl - If User add
Import-package:com.sun.elto the bundle then another exception is thrown:
Caused by: java.lang.ExceptionInInitializerError
at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolateExpression(ResourceBundleMessageInterpolator.java:227)[416:org.hibernate.validator:5.0.1.Final]
at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolateMessage(ResourceBundleMessageInterpolator.java:187)[416:org.hibernate.validator:5.0.1.Final]
at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolate(ResourceBundleMessageInterpolator.java:115)[416:org.hibernate.validator:5.0.1.Final]
at org.hibernate.validator.internal.engine.ValidationContext.interpolate(ValidationContext.java:370)
at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolation(ValidationContext.java:284)
at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolations(ValidationContext.java:246)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:289)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:133)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91)
at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:478)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:424)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:388)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:340)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:158)
at xxx.yyy.www
at Proxye7e3aa5e_772f_4eb3_bef3_2e25aea61c3e.checkOutFull(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_09]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_09]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_09]
at java.lang.reflect.Method.invoke(Method.java:601)[:1.7.0_09]
at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:407)[330:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:278)[330:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:251)[330:org.apache.camel.camel-core:2.12.0.redhat-611412]
... 57 more
Caused by: java.lang.ClassCastException: com.sun.el.ExpressionFactoryImpl cannot be cast to javax.el.ExpressionFactory
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:189)[312:javax.el-api:2.2.4]
at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:160)[312:javax.el-api:2.2.4]
at org.hibernate.validator.internal.engine.messageinterpolation.InterpolationTerm.<clinit>(InterpolationTerm.java:60)
Resolution
- JIRA request has been raised, which can be tracked at https://issues.jboss.org/browse/ENTESB-3402.
- There is a workaround where user can switch version of hibernate-validator bean to an earlier version i.e. 4.3.1.Final.
- In pom.xml replace the existing dependency with following. Build the code with this dependency.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
- Also deploy this dependency to Fuse environment.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments