diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java index 5e37afabf09..433e2bf3b71 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.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. @@ -98,7 +98,9 @@ public final class ReactiveTypeDescriptor { */ public Object getEmptyValue() { Assert.state(this.emptySupplier != null, "Empty values not supported"); - return this.emptySupplier.get(); + Object emptyValue = this.emptySupplier.get(); + Assert.notNull(emptyValue, "Invalid null return value from emptySupplier"); + return emptyValue; } /** @@ -130,7 +132,7 @@ public final class ReactiveTypeDescriptor { /** - * Descriptor for a reactive type that can produce 0..N values. + * Descriptor for a reactive type that can produce {@code 0..N} values. * @param type the reactive type * @param emptySupplier a supplier of an empty-value instance of the reactive type */ diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index a56670b4b5d..7e96f292e16 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.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. @@ -750,7 +750,7 @@ public class ResolvableType implements Serializable { * Convenience method that will {@link #getGenerics() get} and * {@link #resolve() resolve} generic parameters. * @return an array of resolved generic parameters (the resulting array - * will never be {@code null}, but it may contain {@code null} elements}) + * will never be {@code null}, but it may contain {@code null} elements) * @see #getGenerics() * @see #resolve() */ diff --git a/spring-core/src/main/java/org/springframework/core/codec/Decoder.java b/spring-core/src/main/java/org/springframework/core/codec/Decoder.java index cc5271d5c01..18f8fd8c5e6 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/Decoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/Decoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 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. @@ -95,20 +95,19 @@ public interface Decoder { @Nullable MimeType mimeType, @Nullable Map hints) throws DecodingException { CompletableFuture future = decodeToMono(Mono.just(buffer), targetType, mimeType, hints).toFuture(); - Assert.state(future.isDone(), "DataBuffer decoding should have completed."); + Assert.state(future.isDone(), "DataBuffer decoding should have completed"); - Throwable failure; try { return future.get(); } catch (ExecutionException ex) { - failure = ex.getCause(); + Throwable cause = ex.getCause(); + throw (cause instanceof CodecException ? (CodecException) cause : + new DecodingException("Failed to decode: " + (cause != null ? cause.getMessage() : ex), cause)); } catch (InterruptedException ex) { - failure = ex; + throw new DecodingException("Interrupted during decode", ex); } - throw (failure instanceof CodecException ? (CodecException) failure : - new DecodingException("Failed to decode: " + failure.getMessage(), failure)); } /** diff --git a/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java index 4e9552a650a..8b176c3c55e 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.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. @@ -76,10 +76,11 @@ public class ResourceDecoder extends AbstractDataBufferDecoder { } Class clazz = elementType.toClass(); - String filename = hints != null ? (String) hints.get(FILENAME_HINT) : null; + String filename = (hints != null ? (String) hints.get(FILENAME_HINT) : null); if (clazz == InputStreamResource.class) { return new InputStreamResource(new ByteArrayInputStream(bytes)) { @Override + @Nullable public String getFilename() { return filename; } @@ -92,6 +93,7 @@ public class ResourceDecoder extends AbstractDataBufferDecoder { else if (Resource.class.isAssignableFrom(clazz)) { return new ByteArrayResource(bytes) { @Override + @Nullable public String getFilename() { return filename; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java index cef40a25ee5..e1405abcf9e 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.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. @@ -138,7 +138,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { @Nullable private static Executable getValidatedExecutable(Class targetClass, Class sourceClass) { Executable executable = conversionExecutableCache.get(targetClass); - if (isApplicable(executable, sourceClass)) { + if (executable != null && isApplicable(executable, sourceClass)) { return executable; } diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java index 7bb0cc91054..c9b9a9a9f94 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.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. @@ -62,7 +62,7 @@ import org.springframework.util.Assert; */ public abstract class DataBufferUtils { - private final static Log logger = LogFactory.getLog(DataBufferUtils.class); + private static final Log logger = LogFactory.getLog(DataBufferUtils.class); private static final Consumer RELEASE_CONSUMER = DataBufferUtils::release; @@ -728,7 +728,7 @@ public abstract class DataBufferUtils { */ private static class SingleByteMatcher implements NestedMatcher { - static SingleByteMatcher NEWLINE_MATCHER = new SingleByteMatcher(new byte[] {10}); + static final SingleByteMatcher NEWLINE_MATCHER = new SingleByteMatcher(new byte[] {10}); private final byte[] delimiter; @@ -767,7 +767,7 @@ public abstract class DataBufferUtils { /** * Base class for a {@link NestedMatcher}. */ - private static abstract class AbstractNestedMatcher implements NestedMatcher { + private abstract static class AbstractNestedMatcher implements NestedMatcher { private final byte[] delimiter; @@ -1005,11 +1005,11 @@ public abstract class DataBufferUtils { } @Override - public void failed(Throwable exc, DataBuffer dataBuffer) { + public void failed(Throwable ex, DataBuffer dataBuffer) { release(dataBuffer); closeChannel(this.channel); this.state.set(State.DISPOSED); - this.sink.error(exc); + this.sink.error(ex); } private enum State { @@ -1064,7 +1064,6 @@ public abstract class DataBufferUtils { public Context currentContext() { return Context.of(this.sink.contextView()); } - } @@ -1145,9 +1144,9 @@ public abstract class DataBufferUtils { } @Override - public void failed(Throwable exc, ByteBuffer byteBuffer) { + public void failed(Throwable ex, ByteBuffer byteBuffer) { sinkDataBuffer(); - this.sink.error(exc); + this.sink.error(ex); } private void sinkDataBuffer() { @@ -1161,7 +1160,6 @@ public abstract class DataBufferUtils { public Context currentContext() { return Context.of(this.sink.contextView()); } - } } diff --git a/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java b/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java index 9fdb24ac9ed..9a497d3eb9e 100644 --- a/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java +++ b/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 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. @@ -20,6 +20,8 @@ import java.util.Collections; import java.util.Iterator; import java.util.function.Supplier; +import org.springframework.lang.Nullable; + /** * Default "no op" {@code ApplicationStartup} implementation. * @@ -52,6 +54,7 @@ class DefaultApplicationStartup implements ApplicationStartup { } @Override + @Nullable public Long getParentId() { return null; } @@ -73,7 +76,6 @@ class DefaultApplicationStartup implements ApplicationStartup { @Override public void end() { - } diff --git a/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java b/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java index 96874edb2ea..ee7d6d5046e 100644 --- a/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java +++ b/spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.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. @@ -73,20 +73,20 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte // Optimization to avoid creating ClassReader for superclass. Boolean superClassMatch = matchSuperClass(superClassName); if (superClassMatch != null) { - if (superClassMatch.booleanValue()) { + if (superClassMatch) { return true; } } else { // Need to read superclass to determine a match... try { - if (match(metadata.getSuperClassName(), metadataReaderFactory)) { + if (match(superClassName, metadataReaderFactory)) { return true; } } catch (IOException ex) { if (logger.isDebugEnabled()) { - logger.debug("Could not read superclass [" + metadata.getSuperClassName() + + logger.debug("Could not read superclass [" + superClassName + "] of type-filtered class [" + metadata.getClassName() + "]"); } } @@ -99,7 +99,7 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte // Optimization to avoid creating ClassReader for superclass Boolean interfaceMatch = matchInterface(ifc); if (interfaceMatch != null) { - if (interfaceMatch.booleanValue()) { + if (interfaceMatch) { return true; } }