Skip to content

Commit 61ba7e8

Browse files
asutosh936gsmet
asutosh936
authored andcommitted
HV-1689 Log an error when a service cannot be loaded
We used to ignore entirely the exception but it can be a legitimate error. Unfortunately, we don't have enough information about why this was ignored in the first place, otherwise we could have tried to use a finer grained approach.
1 parent 807a53d commit 61ba7e8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

engine/src/main/java/org/hibernate/validator/internal/util/logging/Log.java

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.hibernate.validator.internal.util.logging;
88

99
import static org.jboss.logging.Logger.Level.DEBUG;
10+
import static org.jboss.logging.Logger.Level.ERROR;
1011
import static org.jboss.logging.Logger.Level.INFO;
1112
import static org.jboss.logging.Logger.Level.WARN;
1213

@@ -21,6 +22,7 @@
2122
import java.util.Collection;
2223
import java.util.List;
2324
import java.util.Locale;
25+
import java.util.ServiceConfigurationError;
2426
import java.util.Set;
2527
import java.util.regex.PatternSyntaxException;
2628

@@ -881,4 +883,8 @@ ConstraintDefinitionException getConstraintValidatorDefinitionConstraintMismatch
881883

882884
@Message(id = 250, value = "Uninitialized locale: %s. Please register your locale as a locale to initialize when initializing your ValidatorFactory.")
883885
ValidationException uninitializedLocale(Locale locale);
886+
887+
@LogMessage(level = ERROR)
888+
@Message(id = 251, value = "An error occurred while loading an instance of service %s.")
889+
void unableToLoadInstanceOfService(String serviceName, @Cause ServiceConfigurationError e);
884890
}

engine/src/main/java/org/hibernate/validator/internal/util/privilegedactions/GetInstancesFromServiceLoader.java

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
*/
77
package org.hibernate.validator.internal.util.privilegedactions;
88

9+
import org.hibernate.validator.internal.util.logging.Log;
10+
import org.hibernate.validator.internal.util.logging.LoggerFactory;
11+
12+
import java.lang.invoke.MethodHandles;
913
import java.security.PrivilegedAction;
1014
import java.util.ArrayList;
1115
import java.util.Iterator;
@@ -22,6 +26,8 @@ public class GetInstancesFromServiceLoader<T> implements PrivilegedAction<List<T
2226

2327
private final Class<T> clazz;
2428

29+
private static final Log LOG = LoggerFactory.make( MethodHandles.lookup() );
30+
2531
private GetInstancesFromServiceLoader(ClassLoader primaryClassLoader, Class<T> clazz) {
2632
this.primaryClassLoader = primaryClassLoader;
2733
this.clazz = clazz;
@@ -57,6 +63,8 @@ private List<T> loadInstances(ClassLoader classloader) {
5763
// ignore, because it can happen when multiple
5864
// services are present and some of them are not class loader
5965
// compatible with our API.
66+
// log an error still as it can hide a legitimate issue (see HV-1689)
67+
LOG.unableToLoadInstanceOfService( loader.getClass().getName(), e );
6068
}
6169
}
6270
return instances;

0 commit comments

Comments
 (0)