Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ object ApiUtil {
fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) {
try {
val res = req.getNativeResponse(HttpServletResponse::class.java)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val res = req.getNativeResponse(HttpServletResponse::class.java)
val res: HttpServletResponse? = req.getNativeResponse(HttpServletResponse::class.java)

Copy link
Contributor Author

@sylvainmoindron sylvainmoindron Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If res is nullable, how about declare HttpServletResponse? ?

kotlin infer itself that res is of type HttpServletResponse? that's why res.setCharacterEncoding doesn't compile in the original bug.
(in the spring librairie getNativeResponse is annotated by @Nullable)

res.setCharacterEncoding("UTF-8")
res.addHeader("Content-Type", contentType)
res.getWriter().print(example)
res?.characterEncoding = "UTF-8"
res?.addHeader("Content-Type", contentType)
res?.writer?.print(example)
} catch (e: IOException) {
throw RuntimeException(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ object ApiUtil {
fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) {
try {
val res = req.getNativeResponse(HttpServletResponse::class.java)
res.setCharacterEncoding("UTF-8")
res.addHeader("Content-Type", contentType)
res.getWriter().print(example)
res?.characterEncoding = "UTF-8"
res?.addHeader("Content-Type", contentType)
res?.writer?.print(example)
} catch (e: IOException) {
throw RuntimeException(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ object ApiUtil {
fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) {
try {
val res = req.getNativeResponse(HttpServletResponse::class.java)
res.setCharacterEncoding("UTF-8")
res.addHeader("Content-Type", contentType)
res.getWriter().print(example)
res?.characterEncoding = "UTF-8"
res?.addHeader("Content-Type", contentType)
res?.writer?.print(example)
} catch (e: IOException) {
throw RuntimeException(e)
}
Expand Down