Skip to content

Commit 76c0017

Browse files
committed
Polishing
1 parent 0628b47 commit 76c0017

File tree

8 files changed

+36
-33
lines changed

8 files changed

+36
-33
lines changed

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

+5-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.
@@ -98,7 +98,9 @@ public boolean supportsEmpty() {
9898
*/
9999
public Object getEmptyValue() {
100100
Assert.state(this.emptySupplier != null, "Empty values not supported");
101-
return this.emptySupplier.get();
101+
Object emptyValue = this.emptySupplier.get();
102+
Assert.notNull(emptyValue, "Invalid null return value from emptySupplier");
103+
return emptyValue;
102104
}
103105

104106
/**
@@ -130,7 +132,7 @@ public int hashCode() {
130132

131133

132134
/**
133-
* Descriptor for a reactive type that can produce 0..N values.
135+
* Descriptor for a reactive type that can produce {@code 0..N} values.
134136
* @param type the reactive type
135137
* @param emptySupplier a supplier of an empty-value instance of the reactive type
136138
*/

Diff for: spring-core/src/main/java/org/springframework/core/ResolvableType.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.
@@ -750,7 +750,7 @@ else if (this.type instanceof ParameterizedType) {
750750
* Convenience method that will {@link #getGenerics() get} and
751751
* {@link #resolve() resolve} generic parameters.
752752
* @return an array of resolved generic parameters (the resulting array
753-
* will never be {@code null}, but it may contain {@code null} elements})
753+
* will never be {@code null}, but it may contain {@code null} elements)
754754
* @see #getGenerics()
755755
* @see #resolve()
756756
*/

Diff for: spring-core/src/main/java/org/springframework/core/codec/Decoder.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -95,20 +95,19 @@ default T decode(DataBuffer buffer, ResolvableType targetType,
9595
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {
9696

9797
CompletableFuture<T> future = decodeToMono(Mono.just(buffer), targetType, mimeType, hints).toFuture();
98-
Assert.state(future.isDone(), "DataBuffer decoding should have completed.");
98+
Assert.state(future.isDone(), "DataBuffer decoding should have completed");
9999

100-
Throwable failure;
101100
try {
102101
return future.get();
103102
}
104103
catch (ExecutionException ex) {
105-
failure = ex.getCause();
104+
Throwable cause = ex.getCause();
105+
throw (cause instanceof CodecException ? (CodecException) cause :
106+
new DecodingException("Failed to decode: " + (cause != null ? cause.getMessage() : ex), cause));
106107
}
107108
catch (InterruptedException ex) {
108-
failure = ex;
109+
throw new DecodingException("Interrupted during decode", ex);
109110
}
110-
throw (failure instanceof CodecException ? (CodecException) failure :
111-
new DecodingException("Failed to decode: " + failure.getMessage(), failure));
112111
}
113112

114113
/**

Diff for: spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java

+4-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.
@@ -76,10 +76,11 @@ public Resource decode(DataBuffer dataBuffer, ResolvableType elementType,
7676
}
7777

7878
Class<?> clazz = elementType.toClass();
79-
String filename = hints != null ? (String) hints.get(FILENAME_HINT) : null;
79+
String filename = (hints != null ? (String) hints.get(FILENAME_HINT) : null);
8080
if (clazz == InputStreamResource.class) {
8181
return new InputStreamResource(new ByteArrayInputStream(bytes)) {
8282
@Override
83+
@Nullable
8384
public String getFilename() {
8485
return filename;
8586
}
@@ -92,6 +93,7 @@ public long contentLength() {
9293
else if (Resource.class.isAssignableFrom(clazz)) {
9394
return new ByteArrayResource(bytes) {
9495
@Override
96+
@Nullable
9597
public String getFilename() {
9698
return filename;
9799
}

Diff for: spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java

+2-2
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.
@@ -138,7 +138,7 @@ static boolean hasConversionMethodOrConstructor(Class<?> targetClass, Class<?> s
138138
@Nullable
139139
private static Executable getValidatedExecutable(Class<?> targetClass, Class<?> sourceClass) {
140140
Executable executable = conversionExecutableCache.get(targetClass);
141-
if (isApplicable(executable, sourceClass)) {
141+
if (executable != null && isApplicable(executable, sourceClass)) {
142142
return executable;
143143
}
144144

Diff for: spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java

+8-10
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.
@@ -62,7 +62,7 @@
6262
*/
6363
public abstract class DataBufferUtils {
6464

65-
private final static Log logger = LogFactory.getLog(DataBufferUtils.class);
65+
private static final Log logger = LogFactory.getLog(DataBufferUtils.class);
6666

6767
private static final Consumer<DataBuffer> RELEASE_CONSUMER = DataBufferUtils::release;
6868

@@ -728,7 +728,7 @@ private interface NestedMatcher extends Matcher {
728728
*/
729729
private static class SingleByteMatcher implements NestedMatcher {
730730

731-
static SingleByteMatcher NEWLINE_MATCHER = new SingleByteMatcher(new byte[] {10});
731+
static final SingleByteMatcher NEWLINE_MATCHER = new SingleByteMatcher(new byte[] {10});
732732

733733
private final byte[] delimiter;
734734

@@ -767,7 +767,7 @@ public void reset() {
767767
/**
768768
* Base class for a {@link NestedMatcher}.
769769
*/
770-
private static abstract class AbstractNestedMatcher implements NestedMatcher {
770+
private abstract static class AbstractNestedMatcher implements NestedMatcher {
771771

772772
private final byte[] delimiter;
773773

@@ -1005,11 +1005,11 @@ public void completed(Integer read, DataBuffer dataBuffer) {
10051005
}
10061006

10071007
@Override
1008-
public void failed(Throwable exc, DataBuffer dataBuffer) {
1008+
public void failed(Throwable ex, DataBuffer dataBuffer) {
10091009
release(dataBuffer);
10101010
closeChannel(this.channel);
10111011
this.state.set(State.DISPOSED);
1012-
this.sink.error(exc);
1012+
this.sink.error(ex);
10131013
}
10141014

10151015
private enum State {
@@ -1064,7 +1064,6 @@ protected void hookOnComplete() {
10641064
public Context currentContext() {
10651065
return Context.of(this.sink.contextView());
10661066
}
1067-
10681067
}
10691068

10701069

@@ -1145,9 +1144,9 @@ else if (this.completed.get()) {
11451144
}
11461145

11471146
@Override
1148-
public void failed(Throwable exc, ByteBuffer byteBuffer) {
1147+
public void failed(Throwable ex, ByteBuffer byteBuffer) {
11491148
sinkDataBuffer();
1150-
this.sink.error(exc);
1149+
this.sink.error(ex);
11511150
}
11521151

11531152
private void sinkDataBuffer() {
@@ -1161,7 +1160,6 @@ private void sinkDataBuffer() {
11611160
public Context currentContext() {
11621161
return Context.of(this.sink.contextView());
11631162
}
1164-
11651163
}
11661164

11671165
}

Diff for: spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -20,6 +20,8 @@
2020
import java.util.Iterator;
2121
import java.util.function.Supplier;
2222

23+
import org.springframework.lang.Nullable;
24+
2325
/**
2426
* Default "no op" {@code ApplicationStartup} implementation.
2527
*
@@ -52,6 +54,7 @@ public long getId() {
5254
}
5355

5456
@Override
57+
@Nullable
5558
public Long getParentId() {
5659
return null;
5760
}
@@ -73,7 +76,6 @@ public StartupStep tag(String key, Supplier<String> value) {
7376

7477
@Override
7578
public void end() {
76-
7779
}
7880

7981

Diff for: spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java

+5-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.
@@ -73,20 +73,20 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada
7373
// Optimization to avoid creating ClassReader for superclass.
7474
Boolean superClassMatch = matchSuperClass(superClassName);
7575
if (superClassMatch != null) {
76-
if (superClassMatch.booleanValue()) {
76+
if (superClassMatch) {
7777
return true;
7878
}
7979
}
8080
else {
8181
// Need to read superclass to determine a match...
8282
try {
83-
if (match(metadata.getSuperClassName(), metadataReaderFactory)) {
83+
if (match(superClassName, metadataReaderFactory)) {
8484
return true;
8585
}
8686
}
8787
catch (IOException ex) {
8888
if (logger.isDebugEnabled()) {
89-
logger.debug("Could not read superclass [" + metadata.getSuperClassName() +
89+
logger.debug("Could not read superclass [" + superClassName +
9090
"] of type-filtered class [" + metadata.getClassName() + "]");
9191
}
9292
}
@@ -99,7 +99,7 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada
9999
// Optimization to avoid creating ClassReader for superclass
100100
Boolean interfaceMatch = matchInterface(ifc);
101101
if (interfaceMatch != null) {
102-
if (interfaceMatch.booleanValue()) {
102+
if (interfaceMatch) {
103103
return true;
104104
}
105105
}

0 commit comments

Comments
 (0)