From c0506422908ef0d985c0133f7e1c1059e6cb34e1 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 4 Aug 2023 15:50:07 +0300 Subject: [PATCH] Polish contribution See gh-30942 --- .../http/converter/StringHttpMessageConverter.java | 11 ++++------- .../converter/StringHttpMessageConverterTests.java | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java index f5b33fb97f..5a408d8749 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -94,12 +94,9 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter clazz, HttpInputMessage inputMessage) throws IOException { Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); long length = inputMessage.getHeaders().getContentLength(); - final byte[] bytes; - if (length >= 0 && length <= Integer.MAX_VALUE) { - bytes = inputMessage.getBody().readNBytes((int) length); - } else { - bytes = inputMessage.getBody().readAllBytes(); - } + byte[] bytes = (length >= 0 && length <= Integer.MAX_VALUE ? + inputMessage.getBody().readNBytes((int) length) : + inputMessage.getBody().readAllBytes()); return new String(bytes, charset); } diff --git a/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java index 7bd9479462..dbc54b5dfd 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/StringHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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.