From 638d91f5f425bf401240f9d467c7121f155010a8 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 4 Nov 2022 16:19:31 +0100 Subject: [PATCH 1/4] Ignore framework-docs from main branch in nohttp check --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c68003140c..9b2c3af505 100644 --- a/build.gradle +++ b/build.gradle @@ -415,7 +415,7 @@ configure(rootProject) { source.exclude "**/test-output/**" allowlistFile = project.file("src/nohttp/allowlist.lines") def rootPath = file(rootDir).toPath() - def projectDirs = allprojects.collect { it.projectDir } + "${rootDir}/buildSrc" + def projectDirs = allprojects.collect { it.projectDir } + "${rootDir}/buildSrc" + "${rootDir}/framework-docs" projectDirs.forEach { dir -> [ 'bin', 'build', 'out', '.settings' ] .collect { rootPath.relativize(new File(dir, it).toPath()) } @@ -439,4 +439,5 @@ configure(rootProject) { } } } + } From a281d8c3fdf1d46f35e6f4b466f817aad86ccd96 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 4 Nov 2022 16:03:47 +0100 Subject: [PATCH 2/4] Polishing --- .../core/io/buffer/DataBufferUtils.java | 2 +- .../messaging/support/MessageHeaderAccessor.java | 2 +- .../r2dbc/core/DefaultDatabaseClient.java | 10 +++++----- .../mock/web/PassThroughFilterChain.java | 4 ++-- .../web/context/request/async/WebAsyncManager.java | 4 ++-- .../testfixture/servlet/PassThroughFilterChain.java | 4 ++-- .../result/view/script/ScriptTemplateView.java | 6 +++--- .../result/view/script/ScriptTemplateViewTests.java | 6 +++--- .../mvc/method/annotation/MvcUriComponentsBuilder.java | 4 ++-- .../mvc/method/annotation/StreamingResponseBody.java | 1 - .../web/servlet/view/script/ScriptTemplateView.java | 6 +++--- .../servlet/view/script/ScriptTemplateViewTests.java | 6 +++--- 12 files changed, 27 insertions(+), 28 deletions(-) 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 a1497b459d..04ad1ac424 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 @@ -695,7 +695,7 @@ public abstract class DataBufferUtils { @Override public byte[] delimiter() { - Assert.state(this.longestDelimiter != NO_DELIMITER, "Illegal state!"); + Assert.state(this.longestDelimiter != NO_DELIMITER, "'delimiter' not set"); return this.longestDelimiter; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java index 8ea3f28539..afbdd8d288 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java @@ -43,7 +43,7 @@ import org.springframework.util.StringUtils; * strongly typed accessors for specific headers, the ability to leave headers * in a {@link Message} mutable, and the option to suppress automatic generation * of {@link MessageHeaders#ID id} and {@link MessageHeaders#TIMESTAMP - * timesteamp} headers. Subclasses such as {@link NativeMessageHeaderAccessor} + * timestamp} headers. Subclasses such as {@link NativeMessageHeaderAccessor} * and others provide support for managing processing vs external source headers * as well as protocol specific headers. * diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java index 366254ae4c..91b21d74f2 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -273,7 +273,7 @@ class DefaultDatabaseClient implements DatabaseClient { public DefaultGenericExecuteSpec bind(String name, Object value) { assertNotPreparedOperation(); - Assert.hasText(name, "Parameter name must not be null or empty!"); + Assert.hasText(name, "Parameter name must not be null or empty"); Assert.notNull(value, () -> String.format( "Value for parameter %s must not be null. Use bindNull(…) instead.", name)); @@ -291,7 +291,7 @@ class DefaultDatabaseClient implements DatabaseClient { @Override public DefaultGenericExecuteSpec bindNull(String name, Class type) { assertNotPreparedOperation(); - Assert.hasText(name, "Parameter name must not be null or empty!"); + Assert.hasText(name, "Parameter name must not be null or empty"); Map byName = new LinkedHashMap<>(this.byName); byName.put(name, Parameter.empty(type)); @@ -301,7 +301,7 @@ class DefaultDatabaseClient implements DatabaseClient { @Override public DefaultGenericExecuteSpec filter(StatementFilterFunction filter) { - Assert.notNull(filter, "Statement FilterFunction must not be null"); + Assert.notNull(filter, "StatementFilterFunction must not be null"); return new DefaultGenericExecuteSpec( this.byIndex, this.byName, this.sqlSupplier, this.filterFunction.andThen(filter)); } @@ -449,7 +449,7 @@ class DefaultDatabaseClient implements DatabaseClient { private String getRequiredSql(Supplier sqlSupplier) { String sql = sqlSupplier.get(); - Assert.state(StringUtils.hasText(sql), "SQL returned by SQL supplier must not be empty!"); + Assert.state(StringUtils.hasText(sql), "SQL returned by supplier must not be empty"); return sql; } } diff --git a/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java b/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java index dfc5f7b303..372fb1f5dd 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java +++ b/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -84,7 +84,7 @@ public class PassThroughFilterChain implements FilterChain { this.filter.doFilter(request, response, this.nextFilterChain); } else { - Assert.state(this.servlet != null, "Neither a Filter not a Servlet set"); + Assert.state(this.servlet != null, "Neither a Filter nor a Servlet has been set"); this.servlet.service(request, response); } } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java index 960ead38d0..14b17ebe09 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -196,7 +196,7 @@ public final class WebAsyncManager { */ public void registerCallableInterceptor(Object key, CallableProcessingInterceptor interceptor) { Assert.notNull(key, "Key is required"); - Assert.notNull(interceptor, "CallableProcessingInterceptor is required"); + Assert.notNull(interceptor, "CallableProcessingInterceptor is required"); this.callableInterceptors.put(key, interceptor); } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java index e3537156ac..10a1eba2d0 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -84,7 +84,7 @@ public class PassThroughFilterChain implements FilterChain { this.filter.doFilter(request, response, this.nextFilterChain); } else { - Assert.state(this.servlet != null, "Neither a Filter not a Servlet set"); + Assert.state(this.servlet != null, "Neither a Filter nor a Servlet has been set"); this.servlet.service(request, response); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java index b831397518..415b126475 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -227,12 +227,12 @@ public class ScriptTemplateView extends AbstractUrlBasedView { engineCount++; } Assert.isTrue(engineCount == 1, - "You should define either 'engine', 'engineSupplier' or 'engineName'."); + "You should define either 'engine', 'engineSupplier', or 'engineName'."); if (Boolean.FALSE.equals(this.sharedEngine)) { Assert.isTrue(this.engine == null, "When 'sharedEngine' is set to false, you should specify the " + - "script engine using 'engineName' or 'engineSupplier' , not 'engine'."); + "script engine using 'engineName' or 'engineSupplier', not 'engine'."); } else if (this.engine != null) { loadScripts(this.engine); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewTests.java index e583e4abbd..879b5e0041 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewTests.java @@ -174,7 +174,7 @@ public class ScriptTemplateViewTests { this.view.setRenderFunction("render"); assertThatIllegalArgumentException().isThrownBy(() -> this.view.setApplicationContext(this.context)) - .withMessageContaining("You should define either 'engine', 'engineSupplier' or 'engineName'."); + .withMessageContaining("You should define either 'engine', 'engineSupplier', or 'engineName'."); } @Test // gh-23258 @@ -185,7 +185,7 @@ public class ScriptTemplateViewTests { this.view.setRenderFunction("render"); assertThatIllegalArgumentException().isThrownBy(() -> this.view.setApplicationContext(this.context)) - .withMessageContaining("You should define either 'engine', 'engineSupplier' or 'engineName'."); + .withMessageContaining("You should define either 'engine', 'engineSupplier', or 'engineName'."); } @Test // gh-23258 @@ -195,7 +195,7 @@ public class ScriptTemplateViewTests { this.view.setRenderFunction("render"); assertThatIllegalArgumentException().isThrownBy(() -> this.view.setApplicationContext(this.context)) - .withMessageContaining("You should define either 'engine', 'engineSupplier' or 'engineName'."); + .withMessageContaining("You should define either 'engine', 'engineSupplier', or 'engineName'."); } @Test diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index 0f5fa243aa..80dcdd4110 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -449,7 +449,7 @@ public class MvcUriComponentsBuilder { */ public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuilder builder, String name) { WebApplicationContext wac = getWebApplicationContext(); - Assert.notNull(wac, "No WebApplicationContext. "); + Assert.notNull(wac, "No WebApplicationContext"); Map map = wac.getBeansOfType(RequestMappingInfoHandlerMapping.class); List handlerMethods = null; for (RequestMappingInfoHandlerMapping mapping : map.values()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBody.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBody.java index eb307b4a62..3c6fe1575c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBody.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBody.java @@ -16,7 +16,6 @@ package org.springframework.web.servlet.mvc.method.annotation; - import java.io.IOException; import java.io.OutputStream; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java index 1593a88ae4..5c5c8f19e2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -258,12 +258,12 @@ public class ScriptTemplateView extends AbstractUrlBasedView { engineCount++; } Assert.isTrue(engineCount == 1, - "You should define either 'engine', 'engineSupplier' or 'engineName'."); + "You should define either 'engine', 'engineSupplier', or 'engineName'."); if (Boolean.FALSE.equals(this.sharedEngine)) { Assert.isTrue(this.engine == null, "When 'sharedEngine' is set to false, you should specify the " + - "script engine using 'engineName' or 'engineSupplier' , not 'engine'."); + "script engine using 'engineName' or 'engineSupplier', not 'engine'."); } else if (this.engine != null) { loadScripts(this.engine); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/ScriptTemplateViewTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/ScriptTemplateViewTests.java index d546737cb8..6246272a6f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/ScriptTemplateViewTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/ScriptTemplateViewTests.java @@ -189,7 +189,7 @@ public class ScriptTemplateViewTests { this.view.setRenderFunction("render"); assertThatIllegalArgumentException().isThrownBy(() -> this.view.setApplicationContext(this.wac)) - .withMessageContaining("You should define either 'engine', 'engineSupplier' or 'engineName'."); + .withMessageContaining("You should define either 'engine', 'engineSupplier', or 'engineName'."); } @Test // gh-23258 @@ -200,7 +200,7 @@ public class ScriptTemplateViewTests { this.view.setRenderFunction("render"); assertThatIllegalArgumentException().isThrownBy(() -> this.view.setApplicationContext(this.wac)) - .withMessageContaining("You should define either 'engine', 'engineSupplier' or 'engineName'."); + .withMessageContaining("You should define either 'engine', 'engineSupplier', or 'engineName'."); } @Test // gh-23258 @@ -210,7 +210,7 @@ public class ScriptTemplateViewTests { this.view.setRenderFunction("render"); assertThatIllegalArgumentException().isThrownBy(() -> this.view.setApplicationContext(this.wac)) - .withMessageContaining("You should define either 'engine', 'engineSupplier' or 'engineName'."); + .withMessageContaining("You should define either 'engine', 'engineSupplier', or 'engineName'."); } @Test From 2a853aea6754341a069191999a53d2065f49cf34 Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Fri, 4 Nov 2022 13:00:02 +0100 Subject: [PATCH 3/4] Avoid String allocations in MediaType.checkParameters Closes gh-29428 --- .../src/main/java/org/springframework/http/MediaType.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index c30efd4c3f..d3e8377510 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -531,10 +531,10 @@ public class MediaType extends MimeType implements Serializable { protected void checkParameters(String parameter, String value) { super.checkParameters(parameter, value); if (PARAM_QUALITY_FACTOR.equals(parameter)) { - value = unquote(value); - double d = Double.parseDouble(value); + String unquotedValue = unquote(value); + double d = Double.parseDouble(unquotedValue); Assert.isTrue(d >= 0D && d <= 1D, - "Invalid quality value \"" + value + "\": should be between 0.0 and 1.0"); + () -> "Invalid quality value \"" + value + "\": should be between 0.0 and 1.0"); } } From deabd669394800053047bb7b2562473b12189f04 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 4 Nov 2022 16:24:36 +0100 Subject: [PATCH 4/4] Avoid String allocations with Assert.state() --- .../converter/json/AbstractJackson2HttpMessageConverter.java | 4 ++-- .../servlet/mvc/method/annotation/ResponseBodyEmitter.java | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java index b5273919e4..657fe94804 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java @@ -356,7 +356,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener Charset charset = getCharset(contentType); ObjectMapper objectMapper = selectObjectMapper(javaType.getRawClass(), contentType); - Assert.state(objectMapper != null, "No ObjectMapper for " + javaType); + Assert.state(objectMapper != null, () -> "No ObjectMapper for " + javaType); boolean isUnicode = ENCODINGS.containsKey(charset.name()) || "UTF-16".equals(charset.name()) || @@ -419,7 +419,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener Class clazz = (object instanceof MappingJacksonValue ? ((MappingJacksonValue) object).getValue().getClass() : object.getClass()); ObjectMapper objectMapper = selectObjectMapper(clazz, contentType); - Assert.state(objectMapper != null, "No ObjectMapper for " + clazz.getName()); + Assert.state(objectMapper != null, () -> "No ObjectMapper for " + clazz.getName()); OutputStream outputStream = StreamUtils.nonClosing(outputMessage.getBody()); try (JsonGenerator generator = objectMapper.getFactory().createGenerator(outputStream, encoding)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java index 732a677933..929385ba68 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -193,8 +193,7 @@ public class ResponseBodyEmitter { * @throws java.lang.IllegalStateException wraps any other errors */ public synchronized void send(Object object, @Nullable MediaType mediaType) throws IOException { - Assert.state(!this.complete, - "ResponseBodyEmitter has already completed" + + Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" + (this.failure != null ? " with error: " + this.failure : "")); sendInternal(object, mediaType); }