From d67aa3c0542460ba3cdded515681c71495f7136a Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 8 Mar 2022 12:28:18 +0100 Subject: [PATCH] Fix null safety in Kotlin examples Closes gh-30097 --- .../data/nosql/couchbase/repositories/MyConverter.kt | 4 ++-- .../amqp/receiving/custom/MyMessageConverter.kt | 8 ++++---- .../jms/receiving/custom/MyMessageConverter.kt | 8 ++++---- .../AdditionalHttpMessageConverter.kt | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/nosql/couchbase/repositories/MyConverter.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/nosql/couchbase/repositories/MyConverter.kt index f6714bb2bc..1d06d2f77f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/nosql/couchbase/repositories/MyConverter.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/nosql/couchbase/repositories/MyConverter.kt @@ -18,9 +18,9 @@ package org.springframework.boot.docs.data.nosql.couchbase.repositories import org.springframework.core.convert.converter.Converter -internal class MyConverter : Converter { +internal class MyConverter : Converter { - override fun convert(value: CouchbaseProperties?): Boolean { + override fun convert(value: CouchbaseProperties): Boolean { return true } diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyMessageConverter.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyMessageConverter.kt index f76819aea3..43223184d1 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyMessageConverter.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/amqp/receiving/custom/MyMessageConverter.kt @@ -22,12 +22,12 @@ import org.springframework.amqp.support.converter.MessageConverter internal class MyMessageConverter : MessageConverter { - override fun toMessage(`object`: Any, messageProperties: MessageProperties): Message? { - return null + override fun toMessage(`object`: Any, messageProperties: MessageProperties): Message { + return Message(byteArrayOf()) } - override fun fromMessage(message: Message): Any? { - return null + override fun fromMessage(message: Message): Any { + return Any() } } diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/jms/receiving/custom/MyMessageConverter.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/jms/receiving/custom/MyMessageConverter.kt index 2d55421b29..ed62cd341c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/jms/receiving/custom/MyMessageConverter.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/messaging/jms/receiving/custom/MyMessageConverter.kt @@ -22,12 +22,12 @@ import javax.jms.Session internal class MyMessageConverter : MessageConverter { - override fun toMessage(`object`: Any, session: Session): Message? { - return null + override fun toMessage(`object`: Any, session: Session): Message { + return session.createObjectMessage() } - override fun fromMessage(message: Message): Any? { - return null + override fun fromMessage(message: Message): Any { + return Any() } } diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/messageconverters/AdditionalHttpMessageConverter.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/messageconverters/AdditionalHttpMessageConverter.kt index 15185badea..766a71c589 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/messageconverters/AdditionalHttpMessageConverter.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/messageconverters/AdditionalHttpMessageConverter.kt @@ -24,19 +24,19 @@ import org.springframework.http.converter.HttpMessageNotWritableException import java.io.IOException import kotlin.jvm.Throws -open class AdditionalHttpMessageConverter : AbstractHttpMessageConverter() { +open class AdditionalHttpMessageConverter : AbstractHttpMessageConverter() { - override fun supports(clazz: Class<*>?): Boolean { + override fun supports(clazz: Class<*>): Boolean { return false } @Throws(IOException::class, HttpMessageNotReadableException::class) - override fun readInternal(clazz: Class<*>?, inputMessage: HttpInputMessage): Any? { - return null + override fun readInternal(clazz: Class<*>, inputMessage: HttpInputMessage): Any { + return Any() } @Throws(IOException::class, HttpMessageNotWritableException::class) - override fun writeInternal(t: Any?, outputMessage: HttpOutputMessage) { + override fun writeInternal(t: Any, outputMessage: HttpOutputMessage) { } }