File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
java-runtime/src/main/java/io/spine/validate/option Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 29
29
import com .google .common .collect .ImmutableSet ;
30
30
import com .google .errorprone .annotations .Immutable ;
31
31
import com .google .protobuf .Descriptors .FieldDescriptor .JavaType ;
32
+ import io .spine .base .CommandMessage ;
33
+ import io .spine .base .EntityState ;
32
34
import io .spine .code .proto .FieldContext ;
33
35
import io .spine .code .proto .FieldDeclaration ;
34
36
import io .spine .logging .WithLogging ;
@@ -101,6 +103,18 @@ public boolean shouldValidate(FieldContext context) {
101
103
void checkUsage (FieldDeclaration field ) {
102
104
var type = field .javaType ();
103
105
if (!CAN_BE_REQUIRED .contains (type ) && field .isNotCollection ()) {
106
+ var isTheFirstField = field .descriptor ().getIndex () == 0 ;
107
+ if (isTheFirstField ) {
108
+ // The first field declared in a message type could be assumed as required
109
+ // because by convention it is an ID field of the message.
110
+ // If so, do not log the warning message for this field because ID fields
111
+ // could be of any reasonable type.
112
+ var messageClass = field .messageType ().javaClass ();
113
+ if (CommandMessage .class .isAssignableFrom (messageClass )
114
+ || EntityState .class .isAssignableFrom (messageClass )) {
115
+ return ;
116
+ }
117
+ }
104
118
var typeName = field .descriptor ().getType ().name ();
105
119
logger ().atWarning ().log (() -> format (
106
120
"The field `%s.%s` has the type %s and" +
You can’t perform that action at this time.
0 commit comments