From f06167ea0194bce9da565e5f86f978d156a6dc68 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 21 Mar 2025 10:58:40 +0100 Subject: [PATCH] Polishing --- .../beans/AbstractNestablePropertyAccessor.java | 5 ++--- .../jdbc/core/SingleColumnRowMapper.java | 5 +++-- .../service/DestinationVariableArgumentResolver.java | 6 +++--- .../springframework/web/client/DefaultRestClient.java | 8 ++------ .../tags/form/AbstractMultiCheckedElementTag.java | 11 +++++------ 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java index 64e3a1e57c2..efca60ebcb9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java @@ -291,7 +291,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA String lastKey = tokens.keys[tokens.keys.length - 1]; if (propValue.getClass().isArray()) { - Class requiredType = propValue.getClass().componentType(); + Class componentType = propValue.getClass().componentType(); int arrayIndex = Integer.parseInt(lastKey); Object oldValue = null; try { @@ -299,10 +299,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA oldValue = Array.get(propValue, arrayIndex); } Object convertedValue = convertIfNecessary(tokens.canonicalName, oldValue, pv.getValue(), - requiredType, ph.nested(tokens.keys.length)); + componentType, ph.nested(tokens.keys.length)); int length = Array.getLength(propValue); if (arrayIndex >= length && arrayIndex < this.autoGrowCollectionLimit) { - Class componentType = propValue.getClass().componentType(); Object newArray = Array.newInstance(componentType, arrayIndex + 1); System.arraycopy(propValue, 0, newArray, 0, length); int lastKeyIndex = tokens.canonicalName.lastIndexOf('['); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java index 43dffc066eb..ccf632ef057 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -85,12 +85,13 @@ public class SingleColumnRowMapper implements RowMapper { * Set a {@link ConversionService} for converting a fetched value. *

Default is the {@link DefaultConversionService}. * @since 5.0.4 - * @see DefaultConversionService#getSharedInstance + * @see DefaultConversionService#getSharedInstance() */ public void setConversionService(@Nullable ConversionService conversionService) { this.conversionService = conversionService; } + /** * Extract a value for the single column in the current row. *

Validates that there is only one column selected, diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java index 99b00160da2..844a8d9e002 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -48,8 +48,8 @@ public class DestinationVariableArgumentResolver implements RSocketServiceArgume collection.forEach(requestValues::addRouteVariable); return true; } - else if (argument.getClass().isArray()) { - for (Object variable : (Object[]) argument) { + else if (argument instanceof Object[] arguments) { + for (Object variable : arguments) { requestValues.addRouteVariable(variable); } return true; diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java index dcfb734e7da..dd883d77116 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -139,6 +139,7 @@ final class DefaultRestClient implements RestClient { this.builder = builder; } + @Override public RequestHeadersUriSpec get() { return methodInternal(HttpMethod.GET); @@ -272,8 +273,6 @@ final class DefaultRestClient implements RestClient { } - - private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec { private final HttpMethod httpMethod; @@ -452,7 +451,6 @@ final class DefaultRestClient implements RestClient { } } - @Override public ResponseSpec retrieve() { ResponseSpec responseSpec = exchangeInternal(DefaultResponseSpec::new, false); @@ -784,8 +782,6 @@ final class DefaultRestClient implements RestClient { this.observationScope.close(); this.observation.stop(); } - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java index 3547f810cf8..e81fad4e564 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -217,11 +217,10 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem throw new IllegalArgumentException("Attribute 'items' is required and must be a Collection, an Array or a Map"); } - if (itemsObject.getClass().isArray()) { - Object[] itemsArray = (Object[]) itemsObject; - for (int i = 0; i < itemsArray.length; i++) { - Object item = itemsArray[i]; - writeObjectEntry(tagWriter, valueProperty, labelProperty, item, i); + if (itemsObject instanceof Object[] itemsArray) { + for (int itemIndex = 0; itemIndex < itemsArray.length; itemIndex++) { + Object item = itemsArray[itemIndex]; + writeObjectEntry(tagWriter, valueProperty, labelProperty, item, itemIndex); } } else if (itemsObject instanceof Collection optionCollection) {