This is an automated email from the ASF dual-hosted git repository.
liuxun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push:
new 14a6b1d SUBMARINE-284. Method invocation `SqlSession#close` may
produce NPE
14a6b1d is described below
commit 14a6b1da6c9e9f32a0a9a3b6fa339d39f5ecc8c9
Author: Ryan Lo <[email protected]>
AuthorDate: Thu Nov 7 21:16:01 2019 +0800
SUBMARINE-284. Method invocation `SqlSession#close` may produce NPE
### What is this PR for?
fix bug "Method invocation `SqlSession#close` may produce NPE"
### What type of PR is it?
[Bug Fix]
### Todos
* [ ] - Task
### What is the Jira issue?
[SUBMARINE-284](https://issues.apache.org/jira/browse/SUBMARINE-284)
### How should this be tested?
[CI](https://travis-ci.org/lowc1012/submarine/builds/608653118)
### Screenshots (if appropriate)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Ryan Lo <[email protected]>
Closes #85 from lowc1012/SUBMARINE-284 and squashes the following commits:
caac99c [Ryan Lo] SUBMARINE-284. remove extra whitespace
b31fafa [Ryan Lo] SUBMARINE-284. Method invocation `SqlSession#close` may
produce NPE in workbench REST API
---
.../org/apache/submarine/rest/LoginRestApi.java | 6 +--
.../org/apache/submarine/rest/SysDeptRestApi.java | 51 +++++-----------------
.../org/apache/submarine/rest/SysDictRestApi.java | 6 +--
3 files changed, 13 insertions(+), 50 deletions(-)
diff --git
a/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/LoginRestApi.java
b/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/LoginRestApi.java
index b6d3e2e..df21f29 100644
---
a/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/LoginRestApi.java
+++
b/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/LoginRestApi.java
@@ -56,16 +56,12 @@ public class LoginRestApi {
= gson.fromJson(loginParams, new TypeToken<HashMap<String, String>>()
{}.getType());
SysUser sysUser = null;
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysUserMapper sysUserMapper = sqlSession.getMapper(SysUserMapper.class);
sysUser = sysUserMapper.login(mapParams);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return new
JsonResponse.Builder<>(Response.Status.OK).success(false).build();
- } finally {
- sqlSession.close();
}
sysUser.setToken("mock_token");
diff --git
a/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDeptRestApi.java
b/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDeptRestApi.java
index 5f10be1..f24954b 100644
---
a/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDeptRestApi.java
+++
b/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDeptRestApi.java
@@ -70,9 +70,8 @@ public class SysDeptRestApi {
LOG.info("SysDeptRestApi.tree()");
List<SysDept> sysDeptList = null;
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
Map<String, Object> where = new HashMap<>();
where.put("deptCode", likeDeptCode);
@@ -81,8 +80,6 @@ public class SysDeptRestApi {
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return new
JsonResponse.Builder<>(Response.Status.OK).success(false).build();
- } finally {
- sqlSession.close();
}
List<SysDeptSelect> sysDeptSelects = new ArrayList<>();
@@ -115,9 +112,7 @@ public class SysDeptRestApi {
LOG.info("queryIdTree({})", disableDeptCode);
List<SysDeptSelect> sysDeptSelects = new ArrayList<>();
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
List<SysDept> sysDeptList = sysDeptMapper.selectAll(new HashMap<>());
@@ -129,8 +124,6 @@ public class SysDeptRestApi {
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return new
JsonResponse.Builder<>(Response.Status.OK).success(false).build();
- } finally {
- sqlSession.close();
}
return new
JsonResponse.Builder<ListResult<List<SysDeptSelect>>>(Response.Status.OK)
@@ -143,9 +136,7 @@ public class SysDeptRestApi {
public Response add(SysDept sysDept) {
LOG.info("add({})", sysDept.toString());
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
sysDeptMapper.add(sysDept);
sqlSession.commit();
@@ -153,8 +144,6 @@ public class SysDeptRestApi {
LOG.error(e.getMessage(), e);
return new JsonResponse.Builder<>(Response.Status.OK).success(false)
.message("Save department failed!").build();
- } finally {
- sqlSession.close();
}
return new JsonResponse.Builder<SysDept>(Response.Status.OK)
@@ -166,9 +155,7 @@ public class SysDeptRestApi {
@SubmarineApi
public Response edit(SysDept sysDept) {
LOG.info("edit({})", sysDept.toString());
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
SysDept dept = sysDeptMapper.getById(sysDept.getId());
@@ -182,8 +169,6 @@ public class SysDeptRestApi {
LOG.error(e.getMessage(), e);
return new JsonResponse.Builder<>(Response.Status.OK)
.message("Update department failed!").success(false).build();
- } finally {
- sqlSession.close();
}
return new JsonResponse.Builder<>(Response.Status.OK).success(true)
@@ -195,9 +180,7 @@ public class SysDeptRestApi {
@SubmarineApi
public Response resetParentDept() {
LOG.info("resetParentDept()");
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
sysDeptMapper.resetDeptLevel();
sqlSession.commit();
@@ -205,8 +188,6 @@ public class SysDeptRestApi {
LOG.error(e.getMessage(), e);
return new JsonResponse.Builder<>(Response.Status.OK)
.message("Reset department level failed!").success(false).build();
- } finally {
- sqlSession.close();
}
return new JsonResponse.Builder<>(Response.Status.OK).success(true)
@@ -223,9 +204,8 @@ public class SysDeptRestApi {
msgOperation = "Restore";
}
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
SysDept dept = new SysDept();
@@ -237,8 +217,6 @@ public class SysDeptRestApi {
LOG.error(e.getMessage(), e);
return new JsonResponse.Builder<>(Response.Status.OK)
.message(msgOperation + " department
failed!").success(false).build();
- } finally {
- sqlSession.close();
}
return new JsonResponse.Builder<>(Response.Status.OK)
@@ -250,9 +228,7 @@ public class SysDeptRestApi {
@SubmarineApi
public Response deleteBatch(@QueryParam("ids") String ids) {
LOG.info("deleteBatch({})", ids.toString());
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
sysDeptMapper.deleteBatch(Arrays.asList(ids.split(",")));
sqlSession.commit();
@@ -260,8 +236,6 @@ public class SysDeptRestApi {
LOG.error(e.getMessage(), e);
return new JsonResponse.Builder<>(Response.Status.OK)
.message("Batch delete department failed!").success(false).build();
- } finally {
- sqlSession.close();
}
return new JsonResponse.Builder<>(Response.Status.OK)
@@ -273,9 +247,8 @@ public class SysDeptRestApi {
@SubmarineApi
public Response remove(String id) {
LOG.info("remove({})", id);
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDeptMapper sysDeptMapper = sqlSession.getMapper(SysDeptMapper.class);
sysDeptMapper.deleteById(id);
sqlSession.commit();
@@ -283,8 +256,6 @@ public class SysDeptRestApi {
LOG.error(e.getMessage(), e);
return new JsonResponse.Builder<>(Response.Status.OK)
.message("Delete department failed!").success(false).build();
- } finally {
- sqlSession.close();
}
return new JsonResponse.Builder<>(Response.Status.OK)
diff --git
a/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDictRestApi.java
b/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDictRestApi.java
index cb2afaa..1217ae7 100644
---
a/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDictRestApi.java
+++
b/submarine-workbench/workbench-server/src/main/java/org/apache/submarine/rest/SysDictRestApi.java
@@ -122,9 +122,7 @@ public class SysDictRestApi {
@Path("/edit")
@SubmarineApi
public Response edit(SysDict sysDict) {
- SqlSession sqlSession = null;
- try {
- sqlSession = MyBatisUtil.getSqlSession();
+ try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
SysDictMapper sysDictMapper = sqlSession.getMapper(SysDictMapper.class);
SysDict dict = sysDictMapper.getById(sysDict.getId());
if (dict == null) {
@@ -137,8 +135,6 @@ public class SysDictRestApi {
LOG.error(e.getMessage(), e);
return new JsonResponse.Builder<>(Response.Status.OK)
.message("Update dictionary failed!").success(false).build();
- } finally {
- sqlSession.close();
}
return new JsonResponse.Builder<>(Response.Status.OK)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]