diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java index 28916e5260..09987862b1 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -167,9 +167,8 @@ public class PartEventHttpMessageReader extends LoggingCodecSupport implements H Assert.state(headersToken != null, "Signal should be headers token"); HttpHeaders headers = headersToken.headers(); - Flux bodyTokens = - flux.filter(t -> t instanceof MultipartParser.BodyToken) - .cast(MultipartParser.BodyToken.class); + Flux bodyTokens = flux.ofType( + MultipartParser.BodyToken.class); return createEvents(headers, bodyTokens); } else { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java index 198d73b972..1268d8a15a 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java @@ -240,9 +240,8 @@ class MultipartRouterFunctionIntegrationTests extends AbstractRouterFunctionInte public Mono transferTo(ServerRequest request) { return request.body(BodyExtractors.toParts()) - .filter(FilePart.class::isInstance) + .ofType(FilePart.class) .next() - .cast(FilePart.class) .flatMap(part -> createTempFile() .flatMap(tempFile -> part.transferTo(tempFile)