Skip to content

Commit eea0062

Browse files
committed
Polishing
1 parent 8d74546 commit eea0062

File tree

8 files changed

+38
-37
lines changed

8 files changed

+38
-37
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.
@@ -747,7 +747,7 @@ else if (this.type instanceof ParameterizedType parameterizedType) {
747747
* Convenience method that will {@link #getGenerics() get} and
748748
* {@link #resolve() resolve} generic parameters.
749749
* @return an array of resolved generic parameters (the resulting array
750-
* will never be {@code null}, but it may contain {@code null} elements})
750+
* will never be {@code null}, but it may contain {@code null} elements)
751751
* @see #getGenerics()
752752
* @see #resolve()
753753
*/

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-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.
@@ -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 ? codecException :
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 ? codecException :
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-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.
@@ -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.
@@ -136,7 +136,7 @@ static boolean hasConversionMethodOrConstructor(Class<?> targetClass, Class<?> s
136136
@Nullable
137137
private static Executable getValidatedExecutable(Class<?> targetClass, Class<?> sourceClass) {
138138
Executable executable = conversionExecutableCache.get(targetClass);
139-
if (isApplicable(executable, sourceClass)) {
139+
if (executable != null && isApplicable(executable, sourceClass)) {
140140
return executable;
141141
}
142142

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

+10-14
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.
@@ -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

@@ -745,7 +745,7 @@ private interface NestedMatcher extends Matcher {
745745
*/
746746
private static class SingleByteMatcher implements NestedMatcher {
747747

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

750750
private final byte[] delimiter;
751751

@@ -784,7 +784,7 @@ public void reset() {
784784
/**
785785
* Base class for a {@link NestedMatcher}.
786786
*/
787-
private static abstract class AbstractNestedMatcher implements NestedMatcher {
787+
private abstract static class AbstractNestedMatcher implements NestedMatcher {
788788

789789
private final byte[] delimiter;
790790

@@ -990,7 +990,7 @@ private void read() {
990990
DataBuffer.ByteBufferIterator iterator = dataBuffer.writableByteBuffers();
991991
Assert.state(iterator.hasNext(), "No ByteBuffer available");
992992
ByteBuffer byteBuffer = iterator.next();
993-
Attachment attachment = new Attachment(dataBuffer, iterator);
993+
Attachment attachment = new Attachment(dataBuffer, iterator);
994994
this.channel.read(byteBuffer, this.position.get(), attachment, this);
995995
}
996996

@@ -999,7 +999,7 @@ public void completed(Integer read, Attachment attachment) {
999999
attachment.iterator().close();
10001000
DataBuffer dataBuffer = attachment.dataBuffer();
10011001

1002-
if (this.state.get().equals(State.DISPOSED)) {
1002+
if (this.state.get() == State.DISPOSED) {
10031003
release(dataBuffer);
10041004
closeChannel(this.channel);
10051005
return;
@@ -1030,13 +1030,13 @@ public void completed(Integer read, Attachment attachment) {
10301030
}
10311031

10321032
@Override
1033-
public void failed(Throwable exc, Attachment attachment) {
1033+
public void failed(Throwable ex, Attachment attachment) {
10341034
attachment.iterator().close();
10351035
release(attachment.dataBuffer());
10361036

10371037
closeChannel(this.channel);
10381038
this.state.set(State.DISPOSED);
1039-
this.sink.error(exc);
1039+
this.sink.error(ex);
10401040
}
10411041

10421042
private enum State {
@@ -1095,7 +1095,6 @@ protected void hookOnComplete() {
10951095
public Context currentContext() {
10961096
return Context.of(this.sink.contextView());
10971097
}
1098-
10991098
}
11001099

11011100

@@ -1190,13 +1189,13 @@ else if (this.completed.get()) {
11901189
}
11911190

11921191
@Override
1193-
public void failed(Throwable exc, Attachment attachment) {
1192+
public void failed(Throwable ex, Attachment attachment) {
11941193
attachment.iterator().close();
11951194

11961195
this.sink.next(attachment.dataBuffer());
11971196
this.writing.set(false);
11981197

1199-
this.sink.error(exc);
1198+
this.sink.error(ex);
12001199
}
12011200

12021201
@Override
@@ -1205,9 +1204,6 @@ public Context currentContext() {
12051204
}
12061205

12071206
private record Attachment(ByteBuffer byteBuffer, DataBuffer dataBuffer, DataBuffer.ByteBufferIterator iterator) {}
1208-
1209-
12101207
}
12111208

1212-
12131209
}

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)