bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [bval] 09/16: code audit: formatting, type-safety, class comparison using .equals instead of == to avoid potential classloader oddities
Date Mon, 10 Jun 2019 05:02:23 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to tag 0.5
in repository https://gitbox.apache.org/repos/asf/bval.git

commit 7b7645e162746891209a082f082e3519d0e71005
Author: mbenson <mbenson@13f79535-47bb-0310-9956-ffa450edef68>
AuthorDate: Mon Sep 17 15:56:56 2012 +0000

    code audit: formatting, type-safety, class comparison using .equals instead of == to avoid
potential classloader oddities
    
    git-svn-id: http://svn.apache.org/repos/asf/bval/trunk@1386678 13f79535-47bb-0310-9956-ffa450edef68
---
 .../bval/jsr303/ApacheValidationProvider.java      | 44 +++++++++-------------
 1 file changed, 17 insertions(+), 27 deletions(-)

diff --git a/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
b/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
index 286016c..42824db 100644
--- a/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
+++ b/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidationProvider.java
@@ -49,7 +49,7 @@ public class ApacheValidationProvider implements ValidationProvider<ApacheValida
      * @return boolean suitability
      */
     public boolean isSuitable(Class<? extends Configuration<?>> builderClass)
{
-        return ApacheValidatorConfiguration.class == builderClass;
+        return ApacheValidatorConfiguration.class.equals(builderClass);
     }
 
     /**
@@ -72,20 +72,17 @@ public class ApacheValidationProvider implements ValidationProvider<ApacheValida
      * @throws javax.validation.ValidationException
      *             if the ValidatorFactory cannot be built
      */
-    @SuppressWarnings("unchecked")
     public ValidatorFactory buildValidatorFactory(final ConfigurationState configuration)
{
         final Class<? extends ValidatorFactory> validatorFactoryClass;
         try {
             String validatorFactoryClassname =
                 configuration.getProperties().get(ApacheValidatorConfiguration.Properties.VALIDATOR_FACTORY_CLASSNAME);
 
-            if (validatorFactoryClassname == null)
+            if (validatorFactoryClassname == null) {
                 validatorFactoryClass = ApacheValidatorFactory.class;
-            else
-            {
-                validatorFactoryClass
-                  = (Class<? extends ValidatorFactory>) ClassUtils.getClass(validatorFactoryClassname);
-                validatorFactoryClass.asSubclass(ValidatorFactory.class);
+            } else {
+                validatorFactoryClass =
+                    ClassUtils.getClass(validatorFactoryClassname).asSubclass(ValidatorFactory.class);
             }
         } catch (ValidationException ex) {
             throw ex;
@@ -103,28 +100,21 @@ public class ApacheValidationProvider implements ValidationProvider<ApacheValida
         // because the classloader of ApacheValidationProvider will always
         // be an ancestor of the loader of validatorFactoryClass.
         return (System.getSecurityManager() == null)
-            ? instantiateValidatorFactory(validatorFactoryClass, configuration)
-            : AccessController.doPrivileged(new PrivilegedAction<ValidatorFactory>()
{
-                  public ValidatorFactory run() {
-                      return instantiateValidatorFactory(validatorFactoryClass, configuration);
-                  }
-              });
+            ? instantiateValidatorFactory(validatorFactoryClass, configuration) : AccessController
+                .doPrivileged(new PrivilegedAction<ValidatorFactory>() {
+                    public ValidatorFactory run() {
+                        return instantiateValidatorFactory(validatorFactoryClass, configuration);
+                    }
+                });
     }
 
-
-
     private static ValidatorFactory instantiateValidatorFactory(
-        final Class<? extends ValidatorFactory> validatorFactoryClass,
-        final ConfigurationState                configuration
-    ) {
-      try
-      {
-          return validatorFactoryClass.getConstructor(ConfigurationState.class).newInstance(configuration);
-      }
-      catch (final Exception ex)
-      {
-          throw new ValidationException("Cannot instantiate : " + validatorFactoryClass,
ex);
-      }
+        final Class<? extends ValidatorFactory> validatorFactoryClass, final ConfigurationState
configuration) {
+        try {
+            return validatorFactoryClass.getConstructor(ConfigurationState.class).newInstance(configuration);
+        } catch (final Exception ex) {
+            throw new ValidationException("Cannot instantiate : " + validatorFactoryClass,
ex);
+        }
     }
 
 }


Mime
View raw message