From 27057889f88ff523a52739147537d0a06c1f6175 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 3 May 2017 13:45:29 +0200 Subject: [PATCH] Polishing --- .../beans/factory/parsing/Problem.java | 12 ++++---- .../core/io/AbstractResource.java | 7 +++-- .../io/support/SpringFactoriesLoader.java | 28 +++++++++---------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java index 9f78a2909d..c317d5f935 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/Problem.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ public class Problem { /** * Create a new instance of the {@link Problem} class. - * @param message a message detailing the problem + * @param message a message detailing the problem * @param location the location within a bean configuration source that triggered the error */ public Problem(String message, Location location) { @@ -51,7 +51,7 @@ public class Problem { /** * Create a new instance of the {@link Problem} class. - * @param message a message detailing the problem + * @param message a message detailing the problem * @param parseState the {@link ParseState} at the time of the error * @param location the location within a bean configuration source that triggered the error */ @@ -61,8 +61,8 @@ public class Problem { /** * Create a new instance of the {@link Problem} class. - * @param message a message detailing the problem - * @param rootCause the underlying expection that caused the error (may be {@code null}) + * @param message a message detailing the problem + * @param rootCause the underlying exception that caused the error (may be {@code null}) * @param parseState the {@link ParseState} at the time of the error * @param location the location within a bean configuration source that triggered the error */ @@ -107,7 +107,7 @@ public class Problem { } /** - * Get the underlying expection that caused the error (may be {@code null}). + * Get the underlying exception that caused the error (may be {@code null}). */ public Throwable getRootCause() { return this.rootCause; diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java index a1c29a837e..520661f574 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -125,8 +125,10 @@ public abstract class AbstractResource implements Resource { } /** - * This implementation returns {@link Channels#newChannel(InputStream)} with the result of - * {@link #getInputStream()}. + * This implementation returns {@link Channels#newChannel(InputStream)} + * with the result of {@link #getInputStream()}. + *

This is the same as in {@link Resource}'s corresponding default method + * but mirrored here for efficient JVM-level dispatching in a class hierarchy. */ @Override public ReadableByteChannel readableChannel() throws IOException { @@ -138,7 +140,6 @@ public abstract class AbstractResource implements Resource { * content length. Subclasses will almost always be able to provide * a more optimal version of this, e.g. checking a File length. * @see #getInputStream() - * @throws IllegalStateException if {@link #getInputStream()} returns null. */ @Override public long contentLength() throws IOException { diff --git a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java index 01d1ca6e86..a3b80bfb32 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java @@ -28,6 +28,7 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.UrlResource; import org.springframework.util.Assert; @@ -60,10 +61,6 @@ import org.springframework.util.StringUtils; */ public abstract class SpringFactoriesLoader { - private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class); - - private static Map> cache = new ConcurrentReferenceHashMap<>(); - /** * The location to look for factories. *

Can be present in multiple JAR files. @@ -71,10 +68,15 @@ public abstract class SpringFactoriesLoader { public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories"; + private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class); + + private static final Map> cache = new ConcurrentReferenceHashMap<>(); + + /** * Load and instantiate the factory implementations of the given type from * {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader. - *

The returned factories are sorted in accordance with the {@link AnnotationAwareOrderComparator}. + *

The returned factories are sorted through {@link AnnotationAwareOrderComparator}. *

If a custom instantiation strategy is required, use {@link #loadFactoryNames} * to obtain all registered factory names. * @param factoryClass the interface or abstract class representing the factory @@ -113,19 +115,17 @@ public abstract class SpringFactoriesLoader { */ public static List loadFactoryNames(Class factoryClass, ClassLoader classLoader) { String factoryClassName = factoryClass.getName(); - return loadSpringFactories(classLoader).getOrDefault(factoryClassName, - Collections.emptyList()); + return loadSpringFactories(classLoader).getOrDefault(factoryClassName, Collections.emptyList()); } - private static Map> loadSpringFactories( - ClassLoader classLoader) { + private static Map> loadSpringFactories(ClassLoader classLoader) { MultiValueMap result = cache.get(classLoader); if (result != null) return result; try { - Enumeration urls = (classLoader != null - ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION) - : ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION)); + Enumeration urls = (classLoader != null ? + classLoader.getResources(FACTORIES_RESOURCE_LOCATION) : + ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION)); result = new LinkedMultiValueMap<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); @@ -141,8 +141,8 @@ public abstract class SpringFactoriesLoader { return result; } catch (IOException ex) { - throw new IllegalArgumentException("Unable to load factories from location [" - + FACTORIES_RESOURCE_LOCATION + "]", ex); + throw new IllegalArgumentException("Unable to load factories from location [" + + FACTORIES_RESOURCE_LOCATION + "]", ex); } }