Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit f13d9fc

Browse files
committed
fix: 🐛 ensure non-null collections for API schema properties
ApiSchema.java and IDocBuildTemplate.java have been updated to initialize apiDatas and apiExceptionStatuses collections to prevent null pointer exceptions. Additionally, postRender method in IDocBuildTemplate.java nowchecks for null apiSchema before processing, enhancing the robustness of the documentation build process.
1 parent 217a0c2 commit f13d9fc

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/main/java/com/ly/doc/model/ApiSchema.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package com.ly.doc.model;
2323

24+
import java.util.ArrayList;
2425
import java.util.List;
2526

2627
/**
@@ -37,6 +38,9 @@ public class ApiSchema<T> {
3738
private List<ApiExceptionStatus> apiExceptionStatuses;
3839

3940
public List<T> getApiDatas() {
41+
if (apiDatas == null) {
42+
apiDatas = new ArrayList<>();
43+
}
4044
return apiDatas;
4145
}
4246

@@ -45,6 +49,9 @@ public void setApiDatas(List<T> apiDatas) {
4549
}
4650

4751
public List<ApiExceptionStatus> getApiExceptionStatuses() {
52+
if (apiExceptionStatuses == null) {
53+
apiExceptionStatuses = new ArrayList<>();
54+
}
4855
return apiExceptionStatuses;
4956
}
5057

src/main/java/com/ly/doc/template/IDocBuildTemplate.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.Collection;
3131
import java.util.List;
32+
import java.util.Objects;
3233

3334
/**
3435
* @author yu 2019/12/21.
@@ -46,12 +47,15 @@ default ApiSchema<T> getApiData(ProjectDocConfigBuilder projectBuilder) {
4647
DocMapping.init();
4748
DocBuildHelper docBuildHelper = DocBuildHelper.create(projectBuilder);
4849

49-
preRender(docBuildHelper);
50+
this.preRender(docBuildHelper);
5051
// get candidate classes
51-
Collection<JavaClass> candidateClasses = getCandidateClasses(projectBuilder, docBuildHelper);
52-
ApiSchema<T> apiSchema = renderApi(projectBuilder, candidateClasses);
52+
Collection<JavaClass> candidateClasses = this.getCandidateClasses(projectBuilder, docBuildHelper);
53+
ApiSchema<T> apiSchema = this.renderApi(projectBuilder, candidateClasses);
5354

54-
postRender(docBuildHelper, apiSchema.getApiDatas());
55+
if (Objects.isNull(apiSchema)) {
56+
apiSchema = new ApiSchema<>();
57+
}
58+
this.postRender(docBuildHelper, apiSchema.getApiDatas());
5559

5660
return apiSchema;
5761
}
@@ -67,8 +71,6 @@ default ApiSchema<T> getApiData(ProjectDocConfigBuilder projectBuilder) {
6771
ApiSchema<T> renderApi(ProjectDocConfigBuilder projectBuilder, Collection<JavaClass> candidateClasses);
6872

6973

70-
71-
7274
/**
7375
* post render
7476
*

0 commit comments

Comments
 (0)