GitHub user VampireAchao added a comment to the discussion: StreamPark
code-style-and-quality Improve
分支顺序不合理导致多代码行深度+1.
一般来讲,如果 某个方法由于 连续嵌套的 if...else.. 导致的代码行深度超过 2+ 个 tab(Streampark 中 TAB
为两个空格)时,应考虑尝试合并分支或者逆置分支条件或者抽取私有方法等方式来减少代码行深度,提高可读性。
```java
if (request instanceof MultipartHttpServletRequest) {
MultipartHttpServletRequest multipartRequest =
(MultipartHttpServletRequest) request;
Map<String, MultipartFile> files = multipartRequest.getFileMap();
for (String file : files.keySet()) {
MultipartFile multipartFile = multipartRequest.getFile(file);
ApiAlertException.throwIfNull(
multipartFile, "File to upload can't be null. Upload file failed.");
boolean fileType =
FileUtils.isJarFileType(multipartFile.getInputStream());
ApiAlertException.throwIfFalse(
fileType, "Illegal file type, Only support standard jar files.
Upload file failed.");
}
}
return true;
----->>
if (!(request instanceof MultipartHttpServletRequest)) {
return true;
}
MultipartHttpServletRequest multipartRequest =
(MultipartHttpServletRequest) request;
Map<String, MultipartFile> files = multipartRequest.getFileMap();
for (String file : files.keySet()) {
MultipartFile multipartFile = multipartRequest.getFile(file);
ApiAlertException.throwIfNull(
multipartFile, "File to upload can't be null. Upload file failed.");
boolean fileType =
FileUtils.isJarFileType(multipartFile.getInputStream());
ApiAlertException.throwIfFalse(
fileType, "Illegal file type, Only support standard jar files. Upload
file failed.");
}
return true;
--------------------
```
GitHub link:
https://github.com/apache/incubator-streampark/discussions/2915#discussioncomment-6623985
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]