diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java index 1617e2267e9d..c2151741d597 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -126,10 +126,16 @@ public AspectMetadata(Class aspectClass, String aspectName) { * Extract contents from String of form {@code pertarget(contents)}. */ private String findPerClause(Class aspectClass) { - String str = aspectClass.getAnnotation(Aspect.class).value(); - int beginIndex = str.indexOf('(') + 1; - int endIndex = str.length() - 1; - return str.substring(beginIndex, endIndex); + Aspect ann = aspectClass.getAnnotation(Aspect.class); + if (ann == null) { + return ""; + } + String value = ann.value(); + int beginIndex = value.indexOf('('); + if (beginIndex < 0) { + return ""; + } + return value.substring(beginIndex + 1, value.length() - 1); } diff --git a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java index 0d51b56117c8..9bc9181f8947 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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 MultiValueMapAdapter(Map> targetMap) { @Nullable public V getFirst(K key) { List values = this.targetMap.get(key); - return (values != null && !values.isEmpty() ? values.get(0) : null); + return (!CollectionUtils.isEmpty(values) ? values.get(0) : null); } @Override @@ -69,7 +69,7 @@ public void add(K key, @Nullable V value) { @Override public void addAll(K key, List values) { - List currentValues = this.targetMap.computeIfAbsent(key, k -> new ArrayList<>(1)); + List currentValues = this.targetMap.computeIfAbsent(key, k -> new ArrayList<>(values.size())); currentValues.addAll(values); } @@ -96,7 +96,7 @@ public void setAll(Map values) { public Map toSingleValueMap() { Map singleValueMap = CollectionUtils.newLinkedHashMap(this.targetMap.size()); this.targetMap.forEach((key, values) -> { - if (values != null && !values.isEmpty()) { + if (!CollectionUtils.isEmpty(values)) { singleValueMap.put(key, values.get(0)); } }); diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 96290a3cea61..76111f847ab8 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -781,6 +781,7 @@ public static boolean pathEquals(String path1, String path2) { * and {@code "0"} through {@code "9"} stay the same. *
  • Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.
  • *
  • A sequence "{@code %xy}" is interpreted as a hexadecimal representation of the character.
  • + *
  • For all other characters (including those already decoded), the output is undefined.
  • * * @param source the encoded String * @param charset the character set @@ -829,7 +830,7 @@ public static String uriDecode(String source, Charset charset) { * the {@link Locale#toString} format as well as BCP 47 language tags as * specified by {@link Locale#forLanguageTag}. * @param localeValue the locale value: following either {@code Locale's} - * {@code toString()} format ("en", "en_UK", etc), also accepting spaces as + * {@code toString()} format ("en", "en_UK", etc.), also accepting spaces as * separators (as an alternative to underscores), or BCP 47 (e.g. "en-UK") * @return a corresponding {@code Locale} instance, or {@code null} if none * @throws IllegalArgumentException in case of an invalid locale specification @@ -859,7 +860,7 @@ public static Locale parseLocale(String localeValue) { *

    Note: This delegate does not accept the BCP 47 language tag format. * Please use {@link #parseLocale} for lenient parsing of both formats. * @param localeString the locale {@code String}: following {@code Locale's} - * {@code toString()} format ("en", "en_UK", etc), also accepting spaces as + * {@code toString()} format ("en", "en_UK", etc.), also accepting spaces as * separators (as an alternative to underscores) * @return a corresponding {@code Locale} instance, or {@code null} if none * @throws IllegalArgumentException in case of an invalid locale specification diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java index c399afa96126..56d3accb10d7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -32,7 +32,7 @@ import org.springframework.util.CollectionUtils; /** - * The default implementation of Spring's {@link SqlRowSet} interface, wrapping a + * The common implementation of Spring's {@link SqlRowSet} interface, wrapping a * {@link java.sql.ResultSet}, catching any {@link SQLException SQLExceptions} and * translating them to a corresponding Spring {@link InvalidResultSetAccessException}. * @@ -43,17 +43,17 @@ *

    Note: Since JDBC 4.0, it has been clarified that any methods using a String to identify * the column should be using the column label. The column label is assigned using the ALIAS * keyword in the SQL query string. When the query doesn't use an ALIAS, the default label is - * the column name. Most JDBC ResultSet implementations follow this new pattern but there are + * the column name. Most JDBC ResultSet implementations follow this pattern, but there are * exceptions such as the {@code com.sun.rowset.CachedRowSetImpl} class which only uses - * the column name, ignoring any column labels. As of Spring 3.0.5, ResultSetWrappingSqlRowSet - * will translate column labels to the correct column index to provide better support for the + * the column name, ignoring any column labels. {@code ResultSetWrappingSqlRowSet} + * will translate column labels to the correct column index to provide better support for * {@code com.sun.rowset.CachedRowSetImpl} which is the default implementation used by * {@link org.springframework.jdbc.core.JdbcTemplate} when working with RowSets. * *

    Note: This class implements the {@code java.io.Serializable} marker interface * through the SqlRowSet interface, but is only actually serializable if the disconnected * ResultSet/RowSet contained in it is serializable. Most CachedRowSet implementations - * are actually serializable, so this should usually work out. + * are actually serializable, so serialization should usually work. * * @author Thomas Risberg * @author Juergen Hoeller @@ -67,16 +67,18 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { /** use serialVersionUID from Spring 1.2 for interoperability. */ private static final long serialVersionUID = -4688694393146734764L; - + @SuppressWarnings("serial") private final ResultSet resultSet; + @SuppressWarnings("serial") private final SqlRowSetMetaData rowSetMetaData; + @SuppressWarnings("serial") private final Map columnLabelMap; /** - * Create a new ResultSetWrappingSqlRowSet for the given ResultSet. + * Create a new {@code ResultSetWrappingSqlRowSet} for the given {@link ResultSet}. * @param resultSet a disconnected ResultSet to wrap * (usually a {@code javax.sql.rowset.CachedRowSet}) * @throws InvalidResultSetAccessException if extracting diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java index 7eaa1bd8d988..7d7baad5c39a 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2024 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. @@ -189,11 +189,6 @@ public void send(Message message) { } } - @Override - public void convertAndSend(Object payload) throws MessagingException { - convertAndSend(payload, null); - } - @Override public void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException { Destination defaultDestination = getDefaultDestination(); diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java index 9b2cef401b92..94d1f475f224 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2024 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. @@ -290,7 +290,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor *

    This method should be used carefully, since it will block the thread * until the message becomes available or until the timeout value is exceeded. *

    This will only work with a default destination specified! - * @return the message produced for the consumer or {@code null} if the timeout expires. + * @return the message produced for the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ @Nullable @@ -303,7 +303,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor *

    This method should be used carefully, since it will block the thread * until the message becomes available or until the timeout value is exceeded. * @param destination the destination to receive a message from - * @return the message produced for the consumer or {@code null} if the timeout expires. + * @return the message produced for the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ @Nullable @@ -317,7 +317,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * until the message becomes available or until the timeout value is exceeded. * @param destinationName the name of the destination to send this message to * (to be resolved to an actual destination by a DestinationResolver) - * @return the message produced for the consumer or {@code null} if the timeout expires. + * @return the message produced for the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ @Nullable @@ -332,7 +332,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor *

    This will only work with a default destination specified! * @param messageSelector the JMS message selector expression (or {@code null} if none). * See the JMS specification for a detailed definition of selector expressions. - * @return the message produced for the consumer or {@code null} if the timeout expires. + * @return the message produced for the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ @Nullable @@ -347,7 +347,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @param destination the destination to receive a message from * @param messageSelector the JMS message selector expression (or {@code null} if none). * See the JMS specification for a detailed definition of selector expressions. - * @return the message produced for the consumer or {@code null} if the timeout expires. + * @return the message produced for the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ @Nullable @@ -363,7 +363,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * (to be resolved to an actual destination by a DestinationResolver) * @param messageSelector the JMS message selector expression (or {@code null} if none). * See the JMS specification for a detailed definition of selector expressions. - * @return the message produced for the consumer or {@code null} if the timeout expires. + * @return the message produced for the consumer, or {@code null} if the timeout expires * @throws JmsException checked JMSException converted to unchecked */ @Nullable diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java index fd48945d5fe2..d79bae649211 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -39,11 +39,10 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; import org.springframework.lang.Nullable; import org.springframework.util.Assert; -import static org.springframework.http.MediaType.ALL_VALUE; - /** * {@link ClientHttpRequest} implementation for the Apache HttpComponents HttpClient 5.x. * @author Martin Tarjányi @@ -123,16 +122,14 @@ public Mono setComplete() { @Override protected void applyHeaders() { HttpHeaders headers = getHeaders(); - headers.entrySet() .stream() .filter(entry -> !HttpHeaders.CONTENT_LENGTH.equals(entry.getKey())) .forEach(entry -> entry.getValue().forEach(v -> this.httpRequest.addHeader(entry.getKey(), v))); if (!this.httpRequest.containsHeader(HttpHeaders.ACCEPT)) { - this.httpRequest.addHeader(HttpHeaders.ACCEPT, ALL_VALUE); + this.httpRequest.addHeader(HttpHeaders.ACCEPT, MediaType.ALL_VALUE); } - this.contentLength = headers.getContentLength(); } @@ -143,7 +140,6 @@ protected void applyCookies() { } CookieStore cookieStore = this.context.getCookieStore(); - getCookies().values() .stream() .flatMap(Collection::stream) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java index d740a3c2cc65..8a81cce0d95f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -221,7 +221,7 @@ public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque @Nullable private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) { - if (path != null && !path.isEmpty()) { + if (StringUtils.hasLength(path)) { path = getUrlPathHelper().decodeRequestString(request, path); if (path.charAt(0) != '/') { String requestUri = getUrlPathHelper().getRequestUri(request);