From 14dc767dd6cad9ce5f677f8c6b7ed3ddbfead827 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Sun, 4 Oct 2026 15:26:43 +0200 Subject: [PATCH] Fix syntax errors in code examples in reference manual This commit fixes syntax errors in Java, Kotlin, and XML examples in the reference manual, such as Java syntax in Kotlin examples, unbalanced braces and parentheses, and unclosed XML elements. Closes gh-37392 --- .../pages/core/beans/context-introduction.adoc | 10 +++++----- .../factory-properties-detailed.adoc | 2 +- .../beans/java/configuration-annotation.adoc | 2 +- .../language-ref/operator-safe-navigation.adoc | 2 +- .../modules/ROOT/pages/core/resources.adoc | 4 ++-- .../pages/core/validation/beanvalidation.adoc | 2 +- .../ROOT/pages/data-access/jdbc/object.adoc | 2 +- .../modules/ROOT/pages/data-access/r2dbc.adoc | 2 +- .../data-access/transaction/programmatic.adoc | 9 ++++----- framework-docs/modules/ROOT/pages/rsocket.adoc | 6 +++--- .../ctx-management/dynamic-property-sources.adoc | 2 +- .../pages/testing/testcontext-framework/tx.adoc | 2 +- .../ROOT/pages/testing/webtestclient.adoc | 16 ++++++++-------- .../web/webflux-webclient/client-attributes.adoc | 2 -- .../ann-methods/sessionattributes.adoc | 5 ++--- .../web/webflux/controller/ann-validation.adoc | 2 ++ .../ROOT/pages/web/webmvc-functional.adoc | 6 ++++-- .../webmvc/mvc-controller/ann-validation.adoc | 2 ++ 18 files changed, 40 insertions(+), 38 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/core/beans/context-introduction.adoc b/framework-docs/modules/ROOT/pages/core/beans/context-introduction.adoc index affad4a1bec..82b40b630f3 100644 --- a/framework-docs/modules/ROOT/pages/core/beans/context-introduction.adoc +++ b/framework-docs/modules/ROOT/pages/core/beans/context-introduction.adoc @@ -946,11 +946,11 @@ Kotlin:: [source,kotlin,indent=0,subs="verbatim,quotes"] ---- // create a startup step and start recording - try (val scanPackages = getApplicationStartup().start("spring.context.base-packages.scan")) { - // add tagging information to the current step - scanPackages.tag("packages", () -> Arrays.toString(basePackages)); - // perform the actual phase we're instrumenting - this.scanner.scan(basePackages); + getApplicationStartup().start("spring.context.base-packages.scan").use { scanPackages -> + // add tagging information to the current step + scanPackages.tag("packages") { Arrays.toString(basePackages) } + // perform the actual phase we're instrumenting + this.scanner.scan(basePackages) } ---- ====== diff --git a/framework-docs/modules/ROOT/pages/core/beans/dependencies/factory-properties-detailed.adoc b/framework-docs/modules/ROOT/pages/core/beans/dependencies/factory-properties-detailed.adoc index 212f388d0a5..5c17680c811 100644 --- a/framework-docs/modules/ROOT/pages/core/beans/dependencies/factory-properties-detailed.adoc +++ b/framework-docs/modules/ROOT/pages/core/beans/dependencies/factory-properties-detailed.adoc @@ -295,7 +295,7 @@ The following example demonstrates collection merging: - + ---- Notice the use of the `merge=true` attribute on the `` element of the diff --git a/framework-docs/modules/ROOT/pages/core/beans/java/configuration-annotation.adoc b/framework-docs/modules/ROOT/pages/core/beans/java/configuration-annotation.adoc index 2e17543405b..cf26804f706 100644 --- a/framework-docs/modules/ROOT/pages/core/beans/java/configuration-annotation.adoc +++ b/framework-docs/modules/ROOT/pages/core/beans/java/configuration-annotation.adoc @@ -134,7 +134,7 @@ Java:: protected Command createCommand() { return asyncCommand(); } - } + }; } ---- diff --git a/framework-docs/modules/ROOT/pages/core/expressions/language-ref/operator-safe-navigation.adoc b/framework-docs/modules/ROOT/pages/core/expressions/language-ref/operator-safe-navigation.adoc index 2ab7a549818..5a104c07271 100644 --- a/framework-docs/modules/ROOT/pages/core/expressions/language-ref/operator-safe-navigation.adoc +++ b/framework-docs/modules/ROOT/pages/core/expressions/language-ref/operator-safe-navigation.adoc @@ -452,7 +452,7 @@ Kotlin:: val expression = "members?.^[nationality == 'Serbian']?.name" // <1> // evaluates to "Nikola Tesla" - String name = parser.parseExpression(expression) + var name = parser.parseExpression(expression) .getValue(context, String::class.java) society.members = null diff --git a/framework-docs/modules/ROOT/pages/core/resources.adoc b/framework-docs/modules/ROOT/pages/core/resources.adoc index cfe100f6d35..be4d2a444a0 100644 --- a/framework-docs/modules/ROOT/pages/core/resources.adoc +++ b/framework-docs/modules/ROOT/pages/core/resources.adoc @@ -521,7 +521,7 @@ latter being used to access a file in the filesystem): [source,xml,indent=0,subs="verbatim,quotes"] ---- - + ---- [source,xml,indent=0,subs="verbatim,quotes"] @@ -597,7 +597,7 @@ Kotlin:: [source,kotlin,indent=0,subs="verbatim,quotes"] ---- @Component - class MyBean(@Value("\${templates.path}") private val templates: Resource[]) + class MyBean(@Value("\${templates.path}") private val templates: Array) ---- ====== diff --git a/framework-docs/modules/ROOT/pages/core/validation/beanvalidation.adoc b/framework-docs/modules/ROOT/pages/core/validation/beanvalidation.adoc index 4a810b98a70..e6c21434a58 100644 --- a/framework-docs/modules/ROOT/pages/core/validation/beanvalidation.adoc +++ b/framework-docs/modules/ROOT/pages/core/validation/beanvalidation.adoc @@ -250,7 +250,7 @@ Java:: public class MyConstraintValidator implements ConstraintValidator { - @Autowired; + @Autowired private Foo aDependency; // ... diff --git a/framework-docs/modules/ROOT/pages/data-access/jdbc/object.adoc b/framework-docs/modules/ROOT/pages/data-access/jdbc/object.adoc index 2c7455e0a44..c2718d82c45 100644 --- a/framework-docs/modules/ROOT/pages/data-access/jdbc/object.adoc +++ b/framework-docs/modules/ROOT/pages/data-access/jdbc/object.adoc @@ -556,7 +556,7 @@ Java:: public TitlesAfterDateStoredProcedure(DataSource dataSource) { super(dataSource, SPROC_NAME); - declareParameter(new SqlParameter(CUTOFF_DATE_PARAM, Types.DATE); + declareParameter(new SqlParameter(CUTOFF_DATE_PARAM, Types.DATE)); declareParameter(new SqlOutParameter("titles", OracleTypes.CURSOR, new TitleMapper())); compile(); } diff --git a/framework-docs/modules/ROOT/pages/data-access/r2dbc.adoc b/framework-docs/modules/ROOT/pages/data-access/r2dbc.adoc index aa0eeeba991..d4b25b85ce1 100644 --- a/framework-docs/modules/ROOT/pages/data-access/r2dbc.adoc +++ b/framework-docs/modules/ROOT/pages/data-access/r2dbc.adoc @@ -360,7 +360,7 @@ Or you may pass in a parameter object with bean properties or record components: ---- // assuming id, name, age properties on Person db.sql("INSERT INTO person (id, name, age) VALUES(:id, :name, :age)") - .bindProperties(new Person("joe", "Joe", 34); + .bindProperties(new Person("joe", "Joe", 34)); ---- Alternatively, you can use positional parameters for binding values to statements. diff --git a/framework-docs/modules/ROOT/pages/data-access/transaction/programmatic.adoc b/framework-docs/modules/ROOT/pages/data-access/transaction/programmatic.adoc index 0b22fe99a22..8f4d40b2d96 100644 --- a/framework-docs/modules/ROOT/pages/data-access/transaction/programmatic.adoc +++ b/framework-docs/modules/ROOT/pages/data-access/transaction/programmatic.adoc @@ -301,7 +301,6 @@ Java:: public Mono doInTransaction(ReactiveTransaction status) { return updateOperation1().then(updateOperation2) .doOnError(SomeBusinessException.class, e -> status.setRollbackOnly()); - } } }); ---- @@ -310,11 +309,11 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - transactionalOperator.execute(object : TransactionCallback() { + transactionalOperator.execute(object : TransactionCallback { - override fun doInTransactionWithoutResult(status: ReactiveTransaction) { - updateOperation1().then(updateOperation2) - .doOnError(SomeBusinessException.class, e -> status.setRollbackOnly()) + override fun doInTransaction(status: ReactiveTransaction): Mono { + return updateOperation1().then(updateOperation2) + .doOnError(SomeBusinessException::class.java) { status.setRollbackOnly() } } }) ---- diff --git a/framework-docs/modules/ROOT/pages/rsocket.adoc b/framework-docs/modules/ROOT/pages/rsocket.adoc index bf6dd0490f1..e76c177b61f 100644 --- a/framework-docs/modules/ROOT/pages/rsocket.adoc +++ b/framework-docs/modules/ROOT/pages/rsocket.adoc @@ -192,7 +192,7 @@ Kotlin:: ---- val requester = RSocketRequester.builder().tcp("localhost", 7000) - URI url = URI.create("https://example.org:8080/rsocket"); + val url = URI.create("https://example.org:8080/rsocket") val requester = RSocketRequester.builder().webSocket(url) ---- ====== @@ -304,7 +304,7 @@ Kotlin:: .build() val responder = - RSocketMessageHandler.responder(strategies, new ClientHandler()); // <2> + RSocketMessageHandler.responder(strategies, ClientHandler()) // <2> val requester = RSocketRequester.builder() .rsocketConnector { it.acceptor(responder) } // <3> @@ -503,7 +503,7 @@ Java:: + [source,java,indent=0,subs="verbatim,quotes"] ---- - Mono location = requester.route("find.radar.EWR")) + Mono location = requester.route("find.radar.EWR") .retrieveMono(AirportLocation.class); ---- diff --git a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management/dynamic-property-sources.adoc b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management/dynamic-property-sources.adoc index 1eb927a4185..0f42cfc18b9 100644 --- a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management/dynamic-property-sources.adoc +++ b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management/dynamic-property-sources.adoc @@ -182,7 +182,7 @@ Kotlin:: @Bean fun apiPropertiesRegistrar(apiServer: ApiServer): DynamicPropertyRegistrar { - return registry -> registry.add("api.url", apiServer::getUrl) + return DynamicPropertyRegistrar { registry -> registry.add("api.url", apiServer::url) } } } ---- diff --git a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tx.adoc b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tx.adoc index 2d9cf648ee5..2f9fce39be0 100644 --- a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tx.adoc +++ b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tx.adoc @@ -583,7 +583,7 @@ Kotlin:: @Transactional @Test(expected = ...) - void updateWithEntityManagerFlush() { + fun updateWithEntityManagerFlush() { updateEntityInJpaPersistenceContext() // Manual flush is required to avoid false positive in test entityManager.flush() diff --git a/framework-docs/modules/ROOT/pages/testing/webtestclient.adoc b/framework-docs/modules/ROOT/pages/testing/webtestclient.adoc index 05975771977..3f844d8400c 100644 --- a/framework-docs/modules/ROOT/pages/testing/webtestclient.adoc +++ b/framework-docs/modules/ROOT/pages/testing/webtestclient.adoc @@ -158,16 +158,16 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - @ExtendWith(SpringExtension.class) + @ExtendWith(SpringExtension::class) @WebAppConfiguration("classpath:META-INF/web-resources") // <1> - @ContextHierarchy({ - @ContextConfiguration(classes = RootConfig.class), - @ContextConfiguration(classes = WebConfig.class) - }) + @ContextHierarchy( + ContextConfiguration(classes = [RootConfig::class]), + ContextConfiguration(classes = [WebConfig::class]) + ) class MyTests { @Autowired - lateinit var wac: WebApplicationContext; // <2> + lateinit var wac: WebApplicationContext // <2> lateinit var client: WebTestClient @@ -394,8 +394,6 @@ Java:: + [source,java,indent=0,subs="verbatim,quotes"] ---- - import org.springframework.test.web.reactive.server.expectBody - client.get().uri("/persons/1") .exchange() .expectStatus().isOk() @@ -409,6 +407,8 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- + import org.springframework.test.web.reactive.server.expectBody + client.get().uri("/persons/1") .exchange() .expectStatus().isOk() diff --git a/framework-docs/modules/ROOT/pages/web/webflux-webclient/client-attributes.adoc b/framework-docs/modules/ROOT/pages/web/webflux-webclient/client-attributes.adoc index f91ed00d9c6..8c1d7bd6c44 100644 --- a/framework-docs/modules/ROOT/pages/web/webflux-webclient/client-attributes.adoc +++ b/framework-docs/modules/ROOT/pages/web/webflux-webclient/client-attributes.adoc @@ -22,8 +22,6 @@ Java:: .attribute("myAttribute", "...") .retrieve() .bodyToMono(Void.class); - - } ---- Kotlin:: diff --git a/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-methods/sessionattributes.adoc b/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-methods/sessionattributes.adoc index 5dd729b04fb..8cfd374f159 100644 --- a/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-methods/sessionattributes.adoc +++ b/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-methods/sessionattributes.adoc @@ -60,9 +60,8 @@ Java:: if (errors.hasErrors()) { // ... } - status.setComplete(); - // ... - } + status.setComplete(); + // ... } } ---- diff --git a/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-validation.adoc b/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-validation.adoc index 67fb1256a88..2ed254ece78 100644 --- a/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-validation.adoc +++ b/framework-docs/modules/ROOT/pages/web/webflux/controller/ann-validation.adoc @@ -87,6 +87,8 @@ Java:: @Override public void modelAttribute(@Nullable ModelAttribute modelAttribute, ParameterErrors errors) { + // ... + } // ... diff --git a/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc b/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc index 91caa3358ec..49a250d874f 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc @@ -329,8 +329,10 @@ Kotlin:: [source,kotlin,indent=0,subs="verbatim,quotes"] ---- fun sse(): RouterFunction = router { - GET("/sse") { request -> ServerResponse.sse { sseBuilder -> - // Save the sseBuilder object somewhere.. + GET("/sse") { request -> + ServerResponse.sse { sseBuilder -> + // Save the sseBuilder object somewhere.. + } } } diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-validation.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-validation.adoc index 45e5c632f4b..58602c1ec9f 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-validation.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-validation.adoc @@ -87,6 +87,8 @@ Java:: @Override public void modelAttribute(@Nullable ModelAttribute modelAttribute, ParameterErrors errors) { + // ... + } // ...