Skip to content

Commit 1ec832b

Browse files
committed
fix: test if return type is null before using it
1 parent d39e015 commit 1ec832b

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

modules/openapi-generator/src/main/resources/JavaSpring/apiUtil.mustache

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public class ApiUtil {
2121
public static void setExampleResponse(NativeWebRequest req, String contentType, String example) {
2222
try {
2323
HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class);
24-
res.setCharacterEncoding("UTF-8");
25-
res.addHeader("Content-Type", contentType);
26-
res.getWriter().print(example);
24+
if (res != null) {
25+
res.setCharacterEncoding("UTF-8");
26+
res.addHeader("Content-Type", contentType);
27+
res.getWriter().print(example);
28+
}
2729
} catch (IOException e) {
2830
throw new RuntimeException(e);
2931
}

0 commit comments

Comments
 (0)