Skip to content

Commit ee3e159

Browse files
committed
Polishing
1 parent e81c788 commit ee3e159

File tree

10 files changed

+36
-39
lines changed

10 files changed

+36
-39
lines changed

Diff for: spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -124,10 +124,16 @@ public AspectMetadata(Class<?> aspectClass, String aspectName) {
124124
* Extract contents from String of form {@code pertarget(contents)}.
125125
*/
126126
private String findPerClause(Class<?> aspectClass) {
127-
String str = aspectClass.getAnnotation(Aspect.class).value();
128-
int beginIndex = str.indexOf('(') + 1;
129-
int endIndex = str.length() - 1;
130-
return str.substring(beginIndex, endIndex);
127+
Aspect ann = aspectClass.getAnnotation(Aspect.class);
128+
if (ann == null) {
129+
return "";
130+
}
131+
String value = ann.value();
132+
int beginIndex = value.indexOf('(');
133+
if (beginIndex < 0) {
134+
return "";
135+
}
136+
return value.substring(beginIndex + 1, value.length() - 1);
131137
}
132138

133139

Diff for: spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ public MultiValueMapAdapter(Map<K, List<V>> targetMap) {
5959
@Nullable
6060
public V getFirst(K key) {
6161
List<V> values = this.targetMap.get(key);
62-
return (values != null && !values.isEmpty() ? values.get(0) : null);
62+
return (!CollectionUtils.isEmpty(values) ? values.get(0) : null);
6363
}
6464

6565
@Override
@@ -95,7 +95,7 @@ public void setAll(Map<K, V> values) {
9595
public Map<K, V> toSingleValueMap() {
9696
Map<K, V> singleValueMap = CollectionUtils.newLinkedHashMap(this.targetMap.size());
9797
this.targetMap.forEach((key, values) -> {
98-
if (values != null && !values.isEmpty()) {
98+
if (!CollectionUtils.isEmpty(values)) {
9999
singleValueMap.put(key, values.get(0));
100100
}
101101
});

Diff for: spring-core/src/main/java/org/springframework/util/StringUtils.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -123,7 +123,7 @@ public static boolean isEmpty(@Nullable Object str) {
123123
* @see #hasText(CharSequence)
124124
*/
125125
public static boolean hasLength(@Nullable CharSequence str) {
126-
return (str != null && str.length() > 0);
126+
return (str != null && !str.isEmpty()); // as of JDK 15
127127
}
128128

129129
/**
@@ -791,6 +791,7 @@ public static boolean pathEquals(String path1, String path2) {
791791
* and {@code "0"} through {@code "9"} stay the same.</li>
792792
* <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.</li>
793793
* <li>A sequence "{@code %<i>xy</i>}" is interpreted as a hexadecimal representation of the character.</li>
794+
* <li>For all other characters (including those already decoded), the output is undefined.</li>
794795
* </ul>
795796
* @param source the encoded String
796797
* @param charset the character set
@@ -839,7 +840,7 @@ public static String uriDecode(String source, Charset charset) {
839840
* the {@link Locale#toString} format as well as BCP 47 language tags as
840841
* specified by {@link Locale#forLanguageTag}.
841842
* @param localeValue the locale value: following either {@code Locale's}
842-
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
843+
* {@code toString()} format ("en", "en_UK", etc.), also accepting spaces as
843844
* separators (as an alternative to underscores), or BCP 47 (e.g. "en-UK")
844845
* @return a corresponding {@code Locale} instance, or {@code null} if none
845846
* @throws IllegalArgumentException in case of an invalid locale specification
@@ -868,15 +869,15 @@ public static Locale parseLocale(String localeValue) {
868869
* <p><b>Note: This delegate does not accept the BCP 47 language tag format.
869870
* Please use {@link #parseLocale} for lenient parsing of both formats.</b>
870871
* @param localeString the locale {@code String}: following {@code Locale's}
871-
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
872+
* {@code toString()} format ("en", "en_UK", etc.), also accepting spaces as
872873
* separators (as an alternative to underscores)
873874
* @return a corresponding {@code Locale} instance, or {@code null} if none
874875
* @throws IllegalArgumentException in case of an invalid locale specification
875876
*/
876877
@SuppressWarnings("deprecation") // for Locale constructors on JDK 19
877878
@Nullable
878879
public static Locale parseLocaleString(String localeString) {
879-
if (localeString.equals("")) {
880+
if (localeString.isEmpty()) {
880881
return null;
881882
}
882883

Diff for: spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
import org.springframework.util.CollectionUtils;
3333

3434
/**
35-
* The default implementation of Spring's {@link SqlRowSet} interface, wrapping a
35+
* The common implementation of Spring's {@link SqlRowSet} interface, wrapping a
3636
* {@link java.sql.ResultSet}, catching any {@link SQLException SQLExceptions} and
3737
* translating them to a corresponding Spring {@link InvalidResultSetAccessException}.
3838
*

Diff for: spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -189,11 +189,6 @@ public void send(Message<?> message) {
189189
}
190190
}
191191

192-
@Override
193-
public void convertAndSend(Object payload) throws MessagingException {
194-
convertAndSend(payload, null);
195-
}
196-
197192
@Override
198193
public void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException {
199194
Destination defaultDestination = getDefaultDestination();

Diff for: spring-jms/src/main/java/org/springframework/jms/core/JmsOperations.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -290,7 +290,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
290290
* <p>This method should be used carefully, since it will block the thread
291291
* until the message becomes available or until the timeout value is exceeded.
292292
* <p>This will only work with a default destination specified!
293-
* @return the message produced for the consumer or {@code null} if the timeout expires.
293+
* @return the message produced for the consumer, or {@code null} if the timeout expires
294294
* @throws JmsException checked JMSException converted to unchecked
295295
*/
296296
@Nullable
@@ -303,7 +303,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
303303
* <p>This method should be used carefully, since it will block the thread
304304
* until the message becomes available or until the timeout value is exceeded.
305305
* @param destination the destination to receive a message from
306-
* @return the message produced for the consumer or {@code null} if the timeout expires.
306+
* @return the message produced for the consumer, or {@code null} if the timeout expires
307307
* @throws JmsException checked JMSException converted to unchecked
308308
*/
309309
@Nullable
@@ -317,7 +317,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
317317
* until the message becomes available or until the timeout value is exceeded.
318318
* @param destinationName the name of the destination to send this message to
319319
* (to be resolved to an actual destination by a DestinationResolver)
320-
* @return the message produced for the consumer or {@code null} if the timeout expires.
320+
* @return the message produced for the consumer, or {@code null} if the timeout expires
321321
* @throws JmsException checked JMSException converted to unchecked
322322
*/
323323
@Nullable
@@ -332,7 +332,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
332332
* <p>This will only work with a default destination specified!
333333
* @param messageSelector the JMS message selector expression (or {@code null} if none).
334334
* See the JMS specification for a detailed definition of selector expressions.
335-
* @return the message produced for the consumer or {@code null} if the timeout expires.
335+
* @return the message produced for the consumer, or {@code null} if the timeout expires
336336
* @throws JmsException checked JMSException converted to unchecked
337337
*/
338338
@Nullable
@@ -347,7 +347,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
347347
* @param destination the destination to receive a message from
348348
* @param messageSelector the JMS message selector expression (or {@code null} if none).
349349
* See the JMS specification for a detailed definition of selector expressions.
350-
* @return the message produced for the consumer or {@code null} if the timeout expires.
350+
* @return the message produced for the consumer, or {@code null} if the timeout expires
351351
* @throws JmsException checked JMSException converted to unchecked
352352
*/
353353
@Nullable
@@ -363,7 +363,7 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor
363363
* (to be resolved to an actual destination by a DestinationResolver)
364364
* @param messageSelector the JMS message selector expression (or {@code null} if none).
365365
* See the JMS specification for a detailed definition of selector expressions.
366-
* @return the message produced for the consumer or {@code null} if the timeout expires.
366+
* @return the message produced for the consumer, or {@code null} if the timeout expires
367367
* @throws JmsException checked JMSException converted to unchecked
368368
*/
369369
@Nullable

Diff for: spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -168,8 +168,7 @@ protected Message<?> doConvert(Object payload, @Nullable Map<String, Object> hea
168168

169169
Map<String, Object> headersToUse = processHeadersToSend(headers);
170170
if (headersToUse != null) {
171-
messageHeaders = (headersToUse instanceof MessageHeaders _messageHeaders ?
172-
_messageHeaders : new MessageHeaders(headersToUse));
171+
messageHeaders = (headersToUse instanceof MessageHeaders mh ? mh : new MessageHeaders(headersToUse));
173172
}
174173

175174
MessageConverter converter = getMessageConverter();

Diff for: spring-web/src/main/java/org/springframework/http/ResponseEntity.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -277,7 +277,6 @@ public static <T> ResponseEntity<T> of(Optional<T> body) {
277277
*/
278278
public static HeadersBuilder<?> of(ProblemDetail body) {
279279
return new DefaultBuilder(body.getStatus()) {
280-
281280
@SuppressWarnings("unchecked")
282281
@Override
283282
public <T> ResponseEntity<T> build() {

Diff for: spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -124,7 +124,6 @@ public Mono<Void> setComplete() {
124124
@Override
125125
protected void applyHeaders() {
126126
HttpHeaders headers = getHeaders();
127-
128127
headers.entrySet()
129128
.stream()
130129
.filter(entry -> !HttpHeaders.CONTENT_LENGTH.equals(entry.getKey()))
@@ -133,7 +132,6 @@ protected void applyHeaders() {
133132
if (!this.httpRequest.containsHeader(HttpHeaders.ACCEPT)) {
134133
this.httpRequest.addHeader(HttpHeaders.ACCEPT, MediaType.ALL_VALUE);
135134
}
136-
137135
this.contentLength = headers.getContentLength();
138136
}
139137

@@ -144,7 +142,6 @@ protected void applyCookies() {
144142
}
145143

146144
CookieStore cookieStore = this.context.getCookieStore();
147-
148145
getCookies().values()
149146
.stream()
150147
.flatMap(Collection::stream)

Diff for: spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -220,7 +220,7 @@ public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque
220220

221221
@Nullable
222222
private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) {
223-
if (path != null && !path.isEmpty()) {
223+
if (StringUtils.hasLength(path)) {
224224
path = getUrlPathHelper().decodeRequestString(request, path);
225225
if (path.charAt(0) != '/') {
226226
String requestUri = getUrlPathHelper().getRequestUri(request);

0 commit comments

Comments
 (0)