Bläddra i källkod

fix: okhttp的response没有close导致内存泄露

Azure 2 år sedan
förälder
incheckning
2f14c81105

+ 1 - 1
pom.xml

@@ -11,7 +11,7 @@
 
     <groupId>com.nju.edu</groupId>
     <artifactId>seecoder-gitlab</artifactId>
-    <version>0.1.3</version>
+    <version>0.1.4</version>
     <packaging>pom</packaging>
     <description>Gitlab API project</description>
     <modules>

+ 1 - 1
seecoder-gitlab-client/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>seecoder-gitlab</artifactId>
         <groupId>com.nju.edu</groupId>
-        <version>0.1.3</version>
+        <version>0.1.4</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 67 - 18
seecoder-gitlab-client/src/main/java/com.nju.edu.gitlab/SeecoderGitlabClient.java

@@ -105,6 +105,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Response response = call.execute();
             GitlabUserVO gitlabUserVO = processResponse(objectMapper, response, new TypeReference<GitlabUserVO>() {
             });
+            response.close();
             return gitlabUserVO;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -131,8 +132,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<Boolean>() {
+            boolean change= processResponse(objectMapper, response, new TypeReference<Boolean>() {
             });
+            response.close();
+            return change;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -159,8 +162,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<Boolean>() {
+            boolean change=processResponse(objectMapper, response, new TypeReference<Boolean>() {
             });
+            response.close();
+            return change;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -206,8 +211,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<String>() {
+            String email= processResponse(objectMapper, response, new TypeReference<String>() {
             });
+            response.close();
+            return email;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -229,8 +236,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<User>() {
+            User user= processResponse(objectMapper, response, new TypeReference<User>() {
             });
+            response.close();
+            return user;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -252,8 +261,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<GitlabUserVO>() {
+            GitlabUserVO gitlabUserVO= processResponse(objectMapper, response, new TypeReference<GitlabUserVO>() {
             });
+            response.close();
+            return gitlabUserVO;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -277,6 +288,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Response response = call.execute();
             GitlabGroup gitlabGroup = processResponse(objectMapper, response, new TypeReference<GitlabGroup>() {
             });
+            response.close();
             return gitlabGroup;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -307,6 +319,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Response response = call.execute();
             boolean isAdded = processResponse(objectMapper, response, new TypeReference<Boolean>() {
             });
+            response.close();
             return isAdded;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -334,8 +347,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<ProjectVO>() {
+            ProjectVO projectVO= processResponse(objectMapper, response, new TypeReference<ProjectVO>() {
             });
+            response.close();
+            return projectVO;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -363,8 +378,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<ProjectVO>() {
+            ProjectVO projectVO= processResponse(objectMapper, response, new TypeReference<ProjectVO>() {
             });
+            response.close();
+            return projectVO;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -388,6 +405,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Response response = call.execute();
             boolean isDeleted = processResponse(objectMapper, response, new TypeReference<Boolean>() {
             });
+            response.close();
             return isDeleted;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -417,6 +435,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Response response = call.execute();
             projectId = processResponse(objectMapper, response, new TypeReference<Integer>() {
             });
+            response.close();
             return projectId;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -445,6 +464,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Response response = call.execute();
             projectId = processResponse(objectMapper, response, new TypeReference<Integer>() {
             });
+            response.close();
             return projectId;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -470,6 +490,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Set<DiffVO> diffVOSet = new HashSet<>();
             diffVOSet = processResponse(objectMapper, response, new TypeReference<Set<DiffVO>>() {
             });
+            response.close();
             return diffVOSet;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -499,8 +520,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<Boolean>() {
+            boolean add= processResponse(objectMapper, response, new TypeReference<Boolean>() {
             });
+            response.close();
+            return add;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -522,8 +545,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<Boolean>() {
+            boolean archive= processResponse(objectMapper, response, new TypeReference<Boolean>() {
             });
+            response.close();
+            return archive;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -549,8 +574,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<String>() {
+            String file= processResponse(objectMapper, response, new TypeReference<String>() {
             });
+            response.close();
+            return file;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -576,8 +603,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<String>() {
+            String file= processResponse(objectMapper, response, new TypeReference<String>() {
             });
+            response.close();
+            return file;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -613,8 +642,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<CommitVO>() {
+            CommitVO commitVO= processResponse(objectMapper, response, new TypeReference<CommitVO>() {
             });
+            response.close();
+            return commitVO;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -639,6 +670,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             List<CommitVO> commitVOList = new ArrayList<>();
             commitVOList = processResponse(objectMapper, response, new TypeReference<List<CommitVO>>() {
             });
+            response.close();
             return commitVOList;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -665,6 +697,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             List<CommitVO> commitVOList = new ArrayList<>();
             commitVOList = processResponse(objectMapper, response, new TypeReference<List<CommitVO>>() {
             });
+            response.close();
             return commitVOList;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -687,7 +720,9 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<CommitVO>() {});
+            CommitVO commitVO= processResponse(objectMapper, response, new TypeReference<CommitVO>() {});
+            response.close();
+            return commitVO;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -712,6 +747,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             List<BranchVO> branchVOList = new ArrayList<>();
             branchVOList = processResponse(objectMapper, response, new TypeReference<List<BranchVO>>() {
             });
+            response.close();
             return branchVOList;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -742,6 +778,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Response response = call.execute();
             boolean isAdded = processResponse(objectMapper, response, new TypeReference<Boolean>() {
             });
+            response.close();
             return isAdded;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -767,6 +804,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             List<ProjectVO> projectVOList = new ArrayList<>();
             projectVOList = processResponse(objectMapper, response, new TypeReference<List<ProjectVO>>() {
             });
+            response.close();
             return projectVOList;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -792,6 +830,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             List<Integer> userList = new ArrayList<>();
             userList = processResponse(objectMapper, response, new TypeReference<List<Integer>>() {
             });
+            response.close();
             return userList;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
@@ -814,8 +853,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<List<String>>() {
+            List<String> filePaths= processResponse(objectMapper, response, new TypeReference<List<String>>() {
             });
+            response.close();
+            return filePaths;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -836,8 +877,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<List<TreeItem>>() {
+            List<TreeItem> treeItems= processResponse(objectMapper, response, new TypeReference<List<TreeItem>>() {
             });
+            response.close();
+            return treeItems;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsTreeItem error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -859,8 +902,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<MergeRequest>() {
+            MergeRequest mergeRequest= processResponse(objectMapper, response, new TypeReference<MergeRequest>() {
             });
+            response.close();
+            return mergeRequest;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsTreeItem error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -881,8 +926,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<VisibilityVO>() {
+            VisibilityVO visibilityVO= processResponse(objectMapper, response, new TypeReference<VisibilityVO>() {
             });
+            response.close();
+            return visibilityVO;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsTreeItem error", e);
             throw SeecoderGitlabException.JSON_ERROR;
@@ -904,8 +951,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            return processResponse(objectMapper, response, new TypeReference<VisibilityVO>() {
+            VisibilityVO visibilityVO1= processResponse(objectMapper, response, new TypeReference<VisibilityVO>() {
             });
+            response.close();
+            return visibilityVO1;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsTreeItem error", e);
             throw SeecoderGitlabException.JSON_ERROR;

+ 1 - 1
seecoder-gitlab-common/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>seecoder-gitlab</artifactId>
         <groupId>com.nju.edu</groupId>
-        <version>0.1.3</version>
+        <version>0.1.4</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

+ 1 - 1
seecoder-gitlab-server/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>seecoder-gitlab</artifactId>
         <groupId>com.nju.edu</groupId>
-        <version>0.1.3</version>
+        <version>0.1.4</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>