Skip to content

Commit 90a4740

Browse files
committed
Polishing
1 parent c803ad7 commit 90a4740

File tree

3 files changed

+50
-52
lines changed

3 files changed

+50
-52
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ public void ternary() throws Exception {
692692
}
693693

694694
@Test
695-
public void ternaryWithBooleanReturn() { // SPR-12271
695+
public void ternaryWithBooleanReturn_SPR12271() {
696696
expression = parser.parseExpression("T(Boolean).TRUE?'abc':'def'");
697697
assertEquals("abc", expression.getValue());
698698
assertCanCompile(expression);
@@ -4199,7 +4199,7 @@ public void propertyReference() throws Exception {
41994199
}
42004200

42014201
@Test
4202-
public void propertyReferenceVisibility() { // SPR-12771
4202+
public void propertyReferenceVisibility_SPR12771() {
42034203
StandardEvaluationContext ctx = new StandardEvaluationContext();
42044204
ctx.setVariable("httpServletRequest", HttpServlet3RequestFactory.getOne());
42054205
// Without a fix compilation was inserting a checkcast to a private type
@@ -4898,7 +4898,6 @@ public void elvisOperator_SPR15192() {
48984898
assertIsCompiled(exp);
48994899
}
49004900

4901-
49024901
@Test
49034902
public void elvisOperator_SPR17214() throws Exception {
49044903
SpelParserConfiguration spc = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
@@ -4947,22 +4946,6 @@ public void elvisOperator_SPR17214() throws Exception {
49474946
assertNull(expression.getValue(rh));
49484947
}
49494948

4950-
public static class RecordHolder {
4951-
public void add(String key, Long value) {
4952-
record.put(key, value);
4953-
}
4954-
public long get(String key) {
4955-
return record.get(key);
4956-
}
4957-
public Map<String,Long> record = new HashMap<>();
4958-
public LongHolder expression = new LongHolder();
4959-
4960-
}
4961-
4962-
public static class LongHolder {
4963-
public Long someLong = 3L;
4964-
}
4965-
49664949
@Test
49674950
public void ternaryOperator_SPR15192() {
49684951
SpelParserConfiguration configuration = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
@@ -6125,4 +6108,26 @@ public String bar(String arg) {
61256108
}
61266109
}
61276110

6111+
6112+
public static class RecordHolder {
6113+
6114+
public Map<String,Long> record = new HashMap<>();
6115+
6116+
public LongHolder expression = new LongHolder();
6117+
6118+
public void add(String key, Long value) {
6119+
record.put(key, value);
6120+
}
6121+
6122+
public long get(String key) {
6123+
return record.get(key);
6124+
}
6125+
}
6126+
6127+
6128+
public static class LongHolder {
6129+
6130+
public Long someLong = 3L;
6131+
}
6132+
61286133
}

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.http.client.reactive;
1718

1819
import java.util.function.Consumer;
@@ -45,19 +46,16 @@ public class ReactorResourceFactory implements InitializingBean, DisposableBean
4546
@Nullable
4647
private Consumer<HttpResources> globalResourcesConsumer;
4748

48-
4949
private Supplier<ConnectionProvider> connectionProviderSupplier = () -> ConnectionProvider.elastic("webflux");
5050

5151
private Supplier<LoopResources> loopResourcesSupplier = () -> LoopResources.create("webflux-http");
5252

53-
5453
@Nullable
5554
private ConnectionProvider connectionProvider;
5655

5756
@Nullable
5857
private LoopResources loopResources;
5958

60-
6159
private boolean manageConnectionProvider = false;
6260

6361
private boolean manageLoopResources = false;
@@ -76,6 +74,14 @@ public void setUseGlobalResources(boolean useGlobalResources) {
7674
this.useGlobalResources = useGlobalResources;
7775
}
7876

77+
/**
78+
* Whether this factory exposes the global
79+
* {@link reactor.netty.http.HttpResources HttpResources} holder.
80+
*/
81+
public boolean isUseGlobalResources() {
82+
return this.useGlobalResources;
83+
}
84+
7985
/**
8086
* Add a Consumer for configuring the global Reactor Netty resources on
8187
* startup. When this option is used, {@link #setUseGlobalResources} is also
@@ -97,7 +103,7 @@ public void addGlobalResourcesConsumer(Consumer<HttpResources> consumer) {
97103
* {@link #setConnectionProvider(ConnectionProvider)} is set.
98104
* @param supplier the supplier to use
99105
*/
100-
public void setConnectionProviderSupplier(@Nullable Supplier<ConnectionProvider> supplier) {
106+
public void setConnectionProviderSupplier(Supplier<ConnectionProvider> supplier) {
101107
this.connectionProviderSupplier = supplier;
102108
}
103109

@@ -109,7 +115,7 @@ public void setConnectionProviderSupplier(@Nullable Supplier<ConnectionProvider>
109115
* {@link #setLoopResources(LoopResources)} is set.
110116
* @param supplier the supplier to use
111117
*/
112-
public void setLoopResourcesSupplier(@Nullable Supplier<LoopResources> supplier) {
118+
public void setLoopResourcesSupplier(Supplier<LoopResources> supplier) {
113119
this.loopResourcesSupplier = supplier;
114120
}
115121

@@ -118,50 +124,41 @@ public void setLoopResourcesSupplier(@Nullable Supplier<LoopResources> supplier)
118124
* {@link ConnectionProvider} instance.
119125
* @param connectionProvider the connection provider to use as is
120126
*/
121-
public void setConnectionProvider(@Nullable ConnectionProvider connectionProvider) {
127+
public void setConnectionProvider(ConnectionProvider connectionProvider) {
122128
this.connectionProvider = connectionProvider;
123129
}
124130

125131
/**
126-
* Use this option when you want to provide an externally managed
127-
* {@link LoopResources} instance.
128-
* @param loopResources the loop resources to use as is
129-
*/
130-
public void setLoopResources(@Nullable LoopResources loopResources) {
131-
this.loopResources = loopResources;
132-
}
133-
134-
135-
/**
136-
* Whether this factory exposes the global
137-
* {@link reactor.netty.http.HttpResources HttpResources} holder.
132+
* Return the configured {@link ConnectionProvider}.
138133
*/
139-
public boolean isUseGlobalResources() {
140-
return this.useGlobalResources;
134+
public ConnectionProvider getConnectionProvider() {
135+
Assert.state(this.connectionProvider != null, "ConnectionProvider not initialized yet");
136+
return this.connectionProvider;
141137
}
142138

143139
/**
144-
* Return the configured {@link ConnectionProvider}.
140+
* Use this option when you want to provide an externally managed
141+
* {@link LoopResources} instance.
142+
* @param loopResources the loop resources to use as is
145143
*/
146-
public ConnectionProvider getConnectionProvider() {
147-
Assert.notNull(this.connectionProvider, "ConnectionProvider not initialized yet via InitializingBean.");
148-
return this.connectionProvider;
144+
public void setLoopResources(LoopResources loopResources) {
145+
this.loopResources = loopResources;
149146
}
150147

151148
/**
152149
* Return the configured {@link LoopResources}.
153150
*/
154151
public LoopResources getLoopResources() {
155-
Assert.notNull(this.loopResources, "LoopResources not initialized yet via InitializingBean.");
152+
Assert.state(this.loopResources != null, "LoopResources not initialized yet");
156153
return this.loopResources;
157154
}
158155

159156

160157
@Override
161-
public void afterPropertiesSet() throws Exception {
158+
public void afterPropertiesSet() {
162159
if (this.useGlobalResources) {
163160
Assert.isTrue(this.loopResources == null && this.connectionProvider == null,
164-
"'useGlobalResources' is mutually exclusive with explicitly configured resources.");
161+
"'useGlobalResources' is mutually exclusive with explicitly configured resources");
165162
HttpResources httpResources = HttpResources.get();
166163
if (this.globalResourcesConsumer != null) {
167164
this.globalResourcesConsumer.accept(httpResources);

spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private String getServletPath(ServletConfig config) {
156156

157157
@Override
158158
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
159-
159+
// Check for existing error attribute first
160160
if (DispatcherType.ASYNC.equals(request.getDispatcherType())) {
161161
Throwable ex = (Throwable) request.getAttribute(WRITE_ERROR_ATTRIBUTE_NAME);
162162
throw new ServletException("Failed to create response content", ex);
@@ -179,9 +179,7 @@ public void service(ServletRequest request, ServletResponse response) throws Ser
179179
return;
180180
}
181181

182-
ServerHttpResponse httpResponse =
183-
createResponse(((HttpServletResponse) response), asyncContext, httpRequest);
184-
182+
ServerHttpResponse httpResponse = createResponse(((HttpServletResponse) response), asyncContext, httpRequest);
185183
if (httpRequest.getMethod() == HttpMethod.HEAD) {
186184
httpResponse = new HttpHeadResponseDecorator(httpResponse);
187185
}
@@ -247,7 +245,6 @@ private static class HandlerResultAsyncListener implements AsyncListener {
247245

248246
private final String logPrefix;
249247

250-
251248
public HandlerResultAsyncListener(AtomicBoolean isCompleted, ServletServerHttpRequest httpRequest) {
252249
this.isCompleted = isCompleted;
253250
this.logPrefix = httpRequest.getLogPrefix();
@@ -288,7 +285,6 @@ private class HandlerResultSubscriber implements Subscriber<Void> {
288285

289286
private final String logPrefix;
290287

291-
292288
public HandlerResultSubscriber(
293289
AsyncContext asyncContext, AtomicBoolean isCompleted, ServletServerHttpRequest httpRequest) {
294290

0 commit comments

Comments
 (0)