-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Validator causing ClassFormatException when detecting JPA
PostPosted: Fri May 16, 2014 9:03 am 
Newbie

Joined: Fri May 16, 2014 4:57 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: Validator causing ClassFormatException when detecting JPA
PostPosted: Fri May 16, 2014 5:46 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

The problem here is that API JAR you mentioned which *only* may be used for compilation but not at runtime. So you need to make sure that it is not contained one the classpath when executing your tests (and also when running your application of course).

You e.g. can do so for your tests via the "classpathDependencyExcludes" option. If you actually want to test JPA-related stuff, you need to add a proper API JAR (and a JPA provider) to the classpath.

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Validator causing ClassFormatException when detecting JPA
PostPosted: Mon May 19, 2014 4:56 am 
Newbie

Joined: Fri May 16, 2014 4:57 am
Posts: 2
Hi Gunnar,

Thanks very much for your reply. I got the tests working with your suggestion of using the classpathDependencyExcludes in the Surefire plugin.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.