Hibernate Validator version: 5.1.0.Final
I am trying to write unit tests for the validation of some of my classes but when I run them I keep getting an error at the line
Code:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
The error is
Code:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.hibernate.validator.internal.util.privilegedactions.LoadClass.loadNonValidatorClass(LoadClass.java:87)
at org.hibernate.validator.internal.util.privilegedactions.LoadClass.run(LoadClass.java:53)
at org.hibernate.validator.internal.util.privilegedactions.LoadClass.run(LoadClass.java:29)
at org.hibernate.validator.internal.util.ReflectionHelper.run(ReflectionHelper.java:674)
at org.hibernate.validator.internal.util.ReflectionHelper.loadClass(ReflectionHelper.java:154)
at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.detectJPA(DefaultTraversableResolver.java:71)
at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.<init>(DefaultTraversableResolver.java:61)
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:107)
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:86)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
As far as I can tell this is caused by the JPA interfaces being found on the classpath but no implementation being present. This is caused in my case by the fact that I'm not using JPA but I do have javaee-web-api as a dependency. From my point of view this is a bug in the way that Validator is trying to detect the presence of JPA.
Can anyone suggest a way that I can get around this problem? I am using the Maven Surefire plugin with JUnit to run my tests. Thanks.