Skip to content

Commit b30bed0

Browse files
committed
mark nullable
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
1 parent 9448adb commit b30bed0

File tree

9 files changed

+55
-11
lines changed

9 files changed

+55
-11
lines changed

core-ng/src/main/java/core/framework/internal/validate/Validator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ private Validator(Class<T> beanClass) {
3535
this.validator = builder.build();
3636
}
3737

38-
public void validate(T bean, boolean partial) {
38+
public void validate(@Nullable T bean, boolean partial) {
3939
Map<String, String> errors = errors(bean, partial);
4040
if (errors != null) throw new ValidationException(errors);
4141
}
4242

4343
// used only internally, for places don't want to catch exception
4444
@Nullable
45-
public Map<String, String> errors(T bean, boolean partial) {
45+
public Map<String, String> errors(@Nullable T bean, boolean partial) {
4646
if (bean == null) {
4747
return Map.of("bean", "bean must not be null");
4848
}

core-ng/src/main/java/core/framework/internal/web/bean/QueryParamHelper.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import core.framework.internal.web.service.PathParamHelper;
44
import core.framework.json.JSON;
55
import core.framework.web.exception.BadRequestException;
6+
import org.jspecify.annotations.Nullable;
67

78
import java.math.BigDecimal;
89
import java.time.LocalDate;
@@ -16,57 +17,68 @@
1617
* @author neo
1718
*/
1819
final class QueryParamHelper { // used by generated QueryParamMapper
19-
public static String toString(Number value) {
20+
@Nullable
21+
public static String toString(@Nullable Number value) {
2022
if (value == null) return null;
2123
return value.toString();
2224
}
2325

24-
public static String toString(Boolean value) {
26+
@Nullable
27+
public static String toString(@Nullable Boolean value) {
2528
if (value == null) return null;
2629
return value.toString();
2730
}
2831

29-
public static String toString(LocalDateTime dateTime) {
32+
@Nullable
33+
public static String toString(@Nullable LocalDateTime dateTime) {
3034
if (dateTime == null) return null;
3135
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(dateTime);
3236
}
3337

34-
public static String toString(LocalDate date) {
38+
@Nullable
39+
public static String toString(@Nullable LocalDate date) {
3540
if (date == null) return null;
3641
return DateTimeFormatter.ISO_LOCAL_DATE.format(date);
3742
}
3843

39-
public static String toString(LocalTime time) {
44+
@Nullable
45+
public static String toString(@Nullable LocalTime time) {
4046
if (time == null) return null;
4147
return DateTimeFormatter.ISO_LOCAL_TIME.format(time);
4248
}
4349

44-
public static String toString(ZonedDateTime dateTime) {
50+
@Nullable
51+
public static String toString(@Nullable ZonedDateTime dateTime) {
4552
if (dateTime == null) return null;
4653
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(dateTime);
4754
}
4855

49-
public static <T extends Enum<?>> String toString(T enumValue) {
56+
@Nullable
57+
public static <T extends Enum<?>> String toString(@Nullable T enumValue) {
5058
if (enumValue == null) return null;
5159
return JSON.toEnumValue(enumValue);
5260
}
5361

5462
// deserialization helpers
63+
@Nullable
5564
public static String toString(String value) {
5665
if (value.isEmpty()) return null;
5766
return value;
5867
}
5968

69+
@Nullable
6070
public static Integer toInt(String value) {
6171
if (value.isEmpty()) return null;
6272
return PathParamHelper.toInt(value);
6373
}
6474

75+
@Nullable
6576
public static Long toLong(String value) {
6677
if (value.isEmpty()) return null;
6778
return PathParamHelper.toLong(value);
6879
}
6980

81+
@Nullable
7082
public static Double toDouble(String value) {
7183
if (value.isEmpty()) return null;
7284
try {
@@ -76,6 +88,7 @@ public static Double toDouble(String value) {
7688
}
7789
}
7890

91+
@Nullable
7992
public static BigDecimal toBigDecimal(String value) {
8093
if (value.isEmpty()) return null;
8194
try {
@@ -85,16 +98,19 @@ public static BigDecimal toBigDecimal(String value) {
8598
}
8699
}
87100

101+
@Nullable
88102
public static Boolean toBoolean(String value) {
89103
if (value.isEmpty()) return null;
90104
return Boolean.valueOf(value); // Boolean.parseBoolean does not throw exception
91105
}
92106

107+
@Nullable
93108
public static <T extends Enum<?>> T toEnum(String value, Class<T> valueClass) {
94109
if (value.isEmpty()) return null;
95110
return PathParamHelper.toEnum(value, valueClass);
96111
}
97112

113+
@Nullable
98114
public static ZonedDateTime toZonedDateTime(String value) {
99115
if (value.isEmpty()) return null;
100116
try {
@@ -104,6 +120,7 @@ public static ZonedDateTime toZonedDateTime(String value) {
104120
}
105121
}
106122

123+
@Nullable
107124
public static LocalDateTime toDateTime(String value) {
108125
if (value.isEmpty()) return null;
109126
try {
@@ -113,6 +130,7 @@ public static LocalDateTime toDateTime(String value) {
113130
}
114131
}
115132

133+
@Nullable
116134
public static LocalTime toTime(String value) {
117135
if (value.isEmpty()) return null;
118136
try {
@@ -122,6 +140,7 @@ public static LocalTime toTime(String value) {
122140
}
123141
}
124142

143+
@Nullable
125144
public static LocalDate toDate(String value) {
126145
if (value.isEmpty()) return null;
127146
try {

core-ng/src/main/java/core/framework/internal/web/bean/ResponseBeanReader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import core.framework.internal.validate.Validator;
88
import core.framework.internal.web.service.InternalErrorResponse;
99
import core.framework.util.Maps;
10+
import org.jspecify.annotations.Nullable;
1011

1112
import java.io.IOException;
1213
import java.lang.reflect.Type;
@@ -36,6 +37,7 @@ public void register(Type responseType, BeanClassValidator validator) {
3637
}
3738
}
3839

40+
@Nullable
3941
public Object fromJSON(Type responseType, byte[] body) throws IOException {
4042
if (void.class == responseType) return null;
4143

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package core.framework.internal.web.bean;
3+
4+
import org.jspecify.annotations.NullMarked;

core-ng/src/main/java/core/framework/internal/web/service/InternalErrorResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package core.framework.internal.web.service;
22

33
import core.framework.api.json.Property;
4+
import org.jspecify.annotations.Nullable;
45

56
/**
67
* @author neo
78
*/
89
public class InternalErrorResponse { // keep compatible with ErrorResponse with additional severity/stackTrace fields
10+
@Nullable
911
@Property(name = "id")
1012
public String id;
1113

1214
@Property(name = "severity")
1315
public String severity;
1416

17+
@Nullable
1518
@Property(name = "errorCode")
1619
public String errorCode;
1720

core-ng/src/main/java/core/framework/internal/web/service/WebServiceClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import core.framework.util.Maps;
1818
import core.framework.web.service.RemoteServiceException;
1919
import core.framework.web.service.WebServiceClientInterceptor;
20+
import org.jspecify.annotations.Nullable;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223

@@ -51,6 +52,7 @@ static HTTPStatus parseHTTPStatus(int statusCode) {
5152
private final HTTPClient httpClient;
5253
private final RequestBeanWriter writer;
5354
private final ResponseBeanReader reader;
55+
@Nullable
5456
private WebServiceClientInterceptor interceptor;
5557

5658
public WebServiceClient(String serviceURL, HTTPClient httpClient, RequestBeanWriter writer, ResponseBeanReader reader) {
@@ -61,7 +63,8 @@ public WebServiceClient(String serviceURL, HTTPClient httpClient, RequestBeanWri
6163
}
6264

6365
// used by generated code, must be public
64-
public <T> Object execute(HTTPMethod method, String path, Class<T> requestBeanClass, T requestBean, Type responseType) {
66+
@Nullable
67+
public <T> Object execute(HTTPMethod method, String path, @Nullable Class<T> requestBeanClass, T requestBean, Type responseType) {
6568
var request = new HTTPRequest(method, serviceURL + path);
6669
request.accept(ContentType.APPLICATION_JSON);
6770
linkContext(request);
@@ -155,7 +158,7 @@ private InternalErrorResponse errorResponse(HTTPResponse response) {
155158
}
156159
}
157160

158-
private Severity parseSeverity(String severity) {
161+
private Severity parseSeverity(@Nullable String severity) {
159162
if (severity == null) return Severity.ERROR;
160163
return Severity.valueOf(severity);
161164
}

core-ng/src/main/java/core/framework/internal/web/service/WebServiceInterfaceValidator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import core.framework.util.Maps;
2222
import core.framework.util.Sets;
2323
import core.framework.util.Strings;
24+
import org.jspecify.annotations.Nullable;
2425

2526
import java.lang.annotation.Annotation;
2627
import java.lang.reflect.Method;
@@ -37,9 +38,13 @@
3738
public class WebServiceInterfaceValidator {
3839
private final Class<?> serviceInterface;
3940
private final BeanClassValidator validator;
41+
@Nullable
4042
public RequestBeanReader requestBeanReader;
43+
@Nullable
4144
public RequestBeanWriter requestBeanWriter;
45+
@Nullable
4246
public ResponseBeanReader responseBeanReader;
47+
@Nullable
4348
public ResponseBeanWriter responseBeanWriter;
4449

4550
public WebServiceInterfaceValidator(Class<?> serviceInterface, BeanClassValidator validator) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package core.framework.internal.web.service;
3+
4+
import org.jspecify.annotations.NullMarked;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package core.framework.log.message;
3+
4+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)