]
Steve Ebersole commented on HV-363:
-----------------------------------
Its not always that cut-n-dried though Sanjeeb in the general case.
Often Hibernate needs to load an implementation of a given contract interface. Now that
implementation class might be part of Hibernate itself or t might be provided by the user.
We don't know and silly regex package name hacks aside we really cannot know. So
what do we do in that case?
HV uses Thread's context class loader to load internal
implementation classes
-----------------------------------------------------------------------------
Key: HV-363
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-363
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Reporter: Sanjeeb Sahoo
Assignee: Hardy Ferentschik
Priority: Blocker
Fix For: 4.2.0
{{org.hibernate.validator.engine.resolver.DefaultTraversableResolver}} uses Thread's
context class loader to load {{JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME}}, which is
{{org.hibernate.validator.engine.resolver.JPATraversableResolver}}. Why? Since one
implementation class is looking for another implementation class, should it not use
{{getClass().getClassLoader()}} instead? The relevant code is given below:
{code}
private void detectJPA() {
try {
loadClass( PERSISTENCE_UTIL_CLASS_NAME, this.getClass() );
log.debug( "Found {} on classpath.", PERSISTENCE_UTIL_CLASS_NAME );
}
catch ( ValidationException e ) {
log.debug(
"Cannot find {} on classpath. All properties will per default be
traversable.",
PERSISTENCE_UTIL_CLASS_NAME
);
return;
}
try {
@SuppressWarnings( "unchecked" )
Class<? extends TraversableResolver> jpaAwareResolverClass = (Class<? extends
TraversableResolver>)
loadClass(JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, this.getClass() );
NewInstance<? extends TraversableResolver> newInstance = NewInstance.action(
jpaAwareResolverClass, "" );
if ( System.getSecurityManager() != null ) {
jpaTraversableResolver = AccessController.doPrivileged( newInstance );
}
else {
jpaTraversableResolver = newInstance.run();
}
log.info(
"Instantiated an instance of {}.",
JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
}
catch ( ValidationException e ) {
log.info(
"Unable to load or instanciate JPA aware resolver {}. All properties will per
default be traversable.",
JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME
);
}
}
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: