You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mc...@apache.org on 2010/05/17 19:41:35 UTC
svn commit: r945268 -
/myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
Author: mconcini
Date: Mon May 17 17:41:35 2010
New Revision: 945268
URL: http://svn.apache.org/viewvc?rev=945268&view=rev
Log:
MYFACES-2722 - fix ClassNotFoundException from BeanValidator
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java?rev=945268&r1=945267&r2=945268&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java Mon May 17 17:41:35 2010
@@ -19,6 +19,9 @@
package javax.faces.validator;
import java.beans.FeatureDescriptor;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
@@ -282,17 +285,52 @@ public class BeanValidator implements Va
clazz = clazz.trim();
if (!clazz.equals(""))
{
- try
+ Class<?> theClass = null;
+ ClassLoader cl = null;
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ cl = AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run() throws PrivilegedActionException
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ catch (PrivilegedActionException pae)
+ {
+ throw new FacesException(pae);
+ }
+ }
+ else
{
- final Class<?> theClass = Class.forName(clazz);
- validationGroupsList.add(theClass);
+ cl = Thread.currentThread().getContextClassLoader();
+ }
+
+ try
+ {
+ // Try WebApp ClassLoader first
+ theClass = Class.forName(clazz,false,cl);
}
- catch (ClassNotFoundException e)
+ catch (ClassNotFoundException ignore)
{
- throw new RuntimeException("Could not load validation group", e);
+ try
+ {
+ // fallback: Try ClassLoader for BeanValidator (i.e. the myfaces.jar lib)
+ theClass = Class.forName(clazz,false, BeanValidator.class.getClassLoader());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Could not load validation group", e);
+ }
}
+ // the class was found
+ validationGroupsList.add(theClass);
}
}
+
this.validationGroupsArray = validationGroupsList.toArray(new Class[validationGroupsList.size()]);
}
}