diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java index c36314c0d14..2c780cd4ae4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2018 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. @@ -44,7 +44,7 @@ public final class ParserContext { private BeanDefinition containingBeanDefinition; - private final Stack containingComponents = new Stack(); + private final Stack containingComponents = new Stack(); public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate) { @@ -90,8 +90,7 @@ public final class ParserContext { } public CompositeComponentDefinition getContainingComponent() { - return (!this.containingComponents.isEmpty() ? - (CompositeComponentDefinition) this.containingComponents.lastElement() : null); + return (!this.containingComponents.isEmpty() ? this.containingComponents.lastElement() : null); } public void pushContainingComponent(CompositeComponentDefinition containingComponent) { @@ -99,7 +98,7 @@ public final class ParserContext { } public CompositeComponentDefinition popContainingComponent() { - return (CompositeComponentDefinition) this.containingComponents.pop(); + return this.containingComponents.pop(); } public void popAndRegisterContainingComponent() { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java index 369c6a12888..f1efb621efa 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java @@ -1,5 +1,20 @@ -package org.springframework.cache.jcache.interceptor; +/* + * Copyright 2002-2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cache.jcache.interceptor; import java.util.Collection; import java.util.Collections; @@ -23,17 +38,19 @@ class CacheResolverAdapter implements CacheResolver { private final javax.cache.annotation.CacheResolver target; + /** * Create a new instance with the JSR-107 cache resolver to invoke. */ public CacheResolverAdapter(javax.cache.annotation.CacheResolver target) { - Assert.notNull(target, "JSR-107 cache resolver must be set."); + Assert.notNull(target, "JSR-107 CacheResolver is required"); this.target = target; } + /** - * Return the underlying {@link javax.cache.annotation.CacheResolver} that this - * instance is using. + * Return the underlying {@link javax.cache.annotation.CacheResolver} + * that this instance is using. */ protected javax.cache.annotation.CacheResolver getTarget() { return target; @@ -45,8 +62,10 @@ class CacheResolverAdapter implements CacheResolver { throw new IllegalStateException("Unexpected context " + context); } CacheInvocationContext cacheInvocationContext = (CacheInvocationContext) context; - javax.cache.Cache cache = target.resolveCache(cacheInvocationContext); - Assert.notNull(cache, "Cannot resolve cache for '" + context + "' using '" + target + "'"); + javax.cache.Cache cache = this.target.resolveCache(cacheInvocationContext); + if (cache == null) { + throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target); + } return Collections.singleton(new JCacheCache(cache)); } diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java index 56fc64be855..f97225b4377 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -58,7 +58,7 @@ public class CacheResolverAdapterTests extends AbstractJCacheTests { DefaultCacheInvocationContext dummyContext = createDummyContext(); CacheResolverAdapter adapter = new CacheResolverAdapter(getCacheResolver(dummyContext, null)); - thrown.expect(IllegalArgumentException.class); + thrown.expect(IllegalStateException.class); adapter.resolveCaches(dummyContext); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheResolver.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheResolver.java index 4bf2fd02e6b..14011f28a9c 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheResolver.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -34,6 +34,7 @@ public interface CacheResolver { * Return the cache(s) to use for the specified invocation. * @param context the context of the particular invocation * @return the cache(s) to use (never {@code null}) + * @throws IllegalStateException if cache resolution failed */ Collection resolveCaches(CacheOperationInvocationContext context); diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java index a0d182c9cce..07cedb1a19c 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -211,7 +211,6 @@ public abstract class AbstractErrors implements Errors, Serializable { return (!fieldErrors.isEmpty() ? fieldErrors.get(0) : null); } - @Override public Class getFieldType(String field) { Object value = getFieldValue(field); diff --git a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java index 7f6d807fe25..5ed2e1ad6e2 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -24,14 +24,14 @@ import org.springframework.util.Assert; /** * The purpose of this class is to enable capturing and passing a generic * {@link Type}. In order to capture the generic type and retain it at runtime, - * you need to create a subclass as follows: + * you need to create a subclass (ideally as anonymous inline class) as follows: * *
  * ParameterizedTypeReference<List<String>> typeRef = new ParameterizedTypeReference<List<String>>() {};
  * 
* - *

The resulting {@code typeReference} instance can then be used to obtain a - * {@link Type} instance that carries parameterized type information. + *

The resulting {@code typeRef} instance can then be used to obtain a {@link Type} + * instance that carries the captured parameterized type information at runtime. * For more information on "super type tokens" see the link to Neal Gafter's blog post. * * @author Arjen Poutsma @@ -49,8 +49,9 @@ public abstract class ParameterizedTypeReference { Type type = parameterizedTypeReferenceSubclass.getGenericSuperclass(); Assert.isInstanceOf(ParameterizedType.class, type, "Type must be a parameterized type"); ParameterizedType parameterizedType = (ParameterizedType) type; - Assert.isTrue(parameterizedType.getActualTypeArguments().length == 1, "Number of type arguments must be 1"); - this.type = parameterizedType.getActualTypeArguments()[0]; + Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); + Assert.isTrue(actualTypeArguments.length == 1, "Number of type arguments must be 1"); + this.type = actualTypeArguments[0]; } private ParameterizedTypeReference(Type type) { diff --git a/spring-core/src/main/java/org/springframework/util/xml/TransformerUtils.java b/spring-core/src/main/java/org/springframework/util/xml/TransformerUtils.java index 4b48abd4b97..5e655368475 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/TransformerUtils.java +++ b/spring-core/src/main/java/org/springframework/util/xml/TransformerUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -22,8 +22,8 @@ import javax.xml.transform.Transformer; import org.springframework.util.Assert; /** - * Contains common behavior relating to {@link javax.xml.transform.Transformer Transformers}, and the - * {@code javax.xml.transform} package in general. + * Contains common behavior relating to {@link javax.xml.transform.Transformer Transformers} + * and the {@code javax.xml.transform} package in general. * * @author Rick Evans * @author Juergen Hoeller @@ -32,16 +32,16 @@ import org.springframework.util.Assert; public abstract class TransformerUtils { /** - * The indent amount of characters if {@link #enableIndenting(javax.xml.transform.Transformer) indenting is enabled}. + * The indent amount of characters if {@link #enableIndenting indenting is enabled}. *

Defaults to "2". */ public static final int DEFAULT_INDENT_AMOUNT = 2; + /** - * Enable indenting for the supplied {@link javax.xml.transform.Transformer}.

If the underlying XSLT engine is - * Xalan, then the special output key {@code indent-amount} will be also be set to a value of {@link - * #DEFAULT_INDENT_AMOUNT} characters. - * + * Enable indenting for the supplied {@link javax.xml.transform.Transformer}. + *

If the underlying XSLT engine is Xalan, then the special output key {@code indent-amount} + * will be also be set to a value of {@link #DEFAULT_INDENT_AMOUNT} characters. * @param transformer the target transformer * @see javax.xml.transform.Transformer#setOutputProperty(String, String) * @see javax.xml.transform.OutputKeys#INDENT @@ -51,10 +51,9 @@ public abstract class TransformerUtils { } /** - * Enable indenting for the supplied {@link javax.xml.transform.Transformer}.

If the underlying XSLT engine is - * Xalan, then the special output key {@code indent-amount} will be also be set to a value of {@link - * #DEFAULT_INDENT_AMOUNT} characters. - * + * Enable indenting for the supplied {@link javax.xml.transform.Transformer}. + *

If the underlying XSLT engine is Xalan, then the special output key {@code indent-amount} + * will be also be set to a value of {@link #DEFAULT_INDENT_AMOUNT} characters. * @param transformer the target transformer * @param indentAmount the size of the indent (2 characters, 3 characters, etc.) * @see javax.xml.transform.Transformer#setOutputProperty(String, String) @@ -62,7 +61,9 @@ public abstract class TransformerUtils { */ public static void enableIndenting(Transformer transformer, int indentAmount) { Assert.notNull(transformer, "Transformer must not be null"); - Assert.isTrue(indentAmount > -1, "The indent amount cannot be less than zero : got " + indentAmount); + if (indentAmount < 0) { + throw new IllegalArgumentException("The indent amount cannot be less than zero : got " + indentAmount); + } transformer.setOutputProperty(OutputKeys.INDENT, "yes"); try { // Xalan-specific, but this is the most common XSLT engine in any case @@ -74,7 +75,6 @@ public abstract class TransformerUtils { /** * Disable indenting for the supplied {@link javax.xml.transform.Transformer}. - * * @param transformer the target transformer * @see javax.xml.transform.OutputKeys#INDENT */ diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java index 4c92cfad260..b4521e68977 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -135,8 +135,9 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * @param payloadClass either byte[] or String */ public void setSerializedPayloadClass(Class payloadClass) { - Assert.isTrue(byte[].class == payloadClass || String.class == payloadClass, - "Payload class must be byte[] or String: " + payloadClass); + if (!(byte[].class == payloadClass || String.class == payloadClass)) { + throw new IllegalArgumentException("Payload class must be byte[] or String: " + payloadClass); + } this.serializedPayloadClass = payloadClass; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java index 14fcf457214..0feee62d323 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -25,7 +25,6 @@ import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.handler.annotation.Headers; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.support.MessageHeaderAccessor; -import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; /** @@ -45,15 +44,12 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol public boolean supportsParameter(MethodParameter parameter) { Class paramType = parameter.getParameterType(); return ((parameter.hasParameterAnnotation(Headers.class) && Map.class.isAssignableFrom(paramType)) || - MessageHeaders.class == paramType || - MessageHeaderAccessor.class.isAssignableFrom(paramType)); + MessageHeaders.class == paramType || MessageHeaderAccessor.class.isAssignableFrom(paramType)); } @Override public Object resolveArgument(MethodParameter parameter, Message message) throws Exception { - Class paramType = parameter.getParameterType(); - if (Map.class.isAssignableFrom(paramType)) { return message.getHeaders(); } @@ -68,7 +64,10 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol } else { Method method = ReflectionUtils.findMethod(paramType, "wrap", Message.class); - Assert.notNull(method, "Cannot create accessor of type " + paramType + " for message " + message); + if (method == null) { + throw new IllegalStateException( + "Cannot create accessor of type " + paramType + " for message " + message); + } return ReflectionUtils.invokeMethod(method, null, message); } } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java index bdd426eee41..73dd3e934c9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java @@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.MethodParameter; import org.springframework.messaging.Message; -import org.springframework.util.Assert; /** * Resolves method parameters by delegating to a list of registered @@ -106,9 +105,10 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu */ @Override public Object resolveArgument(MethodParameter parameter, Message message) throws Exception { - HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); - Assert.notNull(resolver, "Unknown parameter type [" + parameter.getParameterType().getName() + "]"); + if (resolver == null) { + throw new IllegalStateException("Unknown parameter type [" + parameter.getParameterType().getName() + "]"); + } return resolver.resolveArgument(parameter, message); } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java index 17e7ae1d561..f17eee0a34d 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -554,9 +554,12 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi XMLReader xmlReader = XMLReaderFactory.createXMLReader(); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); for (int i = 0; i < resources.length; i++) { - Assert.notNull(resources[i], "Resource is null"); - Assert.isTrue(resources[i].exists(), "Resource " + resources[i] + " does not exist"); - InputSource inputSource = SaxResourceUtils.createInputSource(resources[i]); + Resource resource = resources[i]; + Assert.notNull(resource, "Resource is null"); + if (!resource.exists()) { + throw new IllegalArgumentException("Resource " + resource + " does not exist"); + } + InputSource inputSource = SaxResourceUtils.createInputSource(resource); schemaSources[i] = new SAXSource(xmlReader, inputSource); } SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage); @@ -1031,12 +1034,12 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { return new ByteArrayInputStream(this.data, this.offset, this.length); } @Override - public OutputStream getOutputStream() throws IOException { + public OutputStream getOutputStream() { throw new UnsupportedOperationException(); } diff --git a/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java b/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java index fb58aa63ba6..9cf673028b7 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java +++ b/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -23,8 +23,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; -import org.springframework.util.Assert; - /** * Represents a set of character entity references defined by the * HTML 4.0 standard. @@ -87,8 +85,9 @@ class HtmlCharacterEntityReferences { while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); int referredChar = Integer.parseInt(key); - Assert.isTrue((referredChar < 1000 || (referredChar >= 8000 && referredChar < 10000)), - "Invalid reference to special HTML entity: " + referredChar); + if (!(referredChar < 1000 || (referredChar >= 8000 && referredChar < 10000))) { + throw new IllegalArgumentException("Invalid reference to special HTML entity: " + referredChar); + } int index = (referredChar < 1000 ? referredChar : referredChar - 7000); String reference = entityReferences.getProperty(key); this.characterToEntityReferenceMap[index] = REFERENCE_START + reference + REFERENCE_END; @@ -119,14 +118,14 @@ class HtmlCharacterEntityReferences { } /** - * Return the reference mapped to the given character or {@code null}. + * Return the reference mapped to the given character, or {@code null} if none found. */ public String convertToReference(char character) { return convertToReference(character, WebUtils.DEFAULT_CHARACTER_ENCODING); } /** - * Return the reference mapped to the given character or {@code null}. + * Return the reference mapped to the given character, or {@code null} if none found. * @since 4.1.2 */ public String convertToReference(char character, String encoding) {