lowka commented on code in PR #3714:
URL: https://github.com/apache/ignite-3/pull/3714#discussion_r1596683345
##########
modules/marshaller-common/src/main/java/org/apache/ignite/internal/marshaller/ValidationUtils.java:
##########
@@ -95,5 +99,35 @@ private static boolean isColumnCompatible(BinaryMode
colType, Class<?> cls) {
}
}
+ /**
+ * Checks whether {@code null} is allowed for the given value type in a
{@code KeyValueView} operation.
+ * If the value type is not natively supported, throws an exception.
+ *
+ * @param val Value to check.
+ * @param valueType Value type.
+ * @throws NullPointerException If value is null and valueType is not
natively supported.
+ */
+ public static void validateNullableValue(@Nullable Object val, Class<?>
valueType) {
+ if (val == null && !Mapper.nativelySupported(valueType)) {
+ String message = "null value cannot be used when a value is not
mapped to a simple type";
+
+ throw new NullPointerException(message);
+ }
+ }
+
+ /**
+ * Checks whether {@code getNullable*} operation on a {@code KeyValueView}
is allowed for the given value type.
+ * If the value type is not natively supported, throws an exception.
+ *
+ * @param valueType Value type.
+ */
+ public static void validateNullableOperation(Class<?> valueType) {
+ if (!Mapper.nativelySupported(valueType)) {
+ String message = format("`getNullable`* methods cannot be used
when a value is not mapped to a simple type");
Review Comment:
This code uses already established pattern see
`ClientKeyValueView::throwIfNull` its callers.
> throw new UnexpectedNullValueException("Got unexpected null value: use
`getNullable` sibling method instead.");
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]