protected static boolean isValidValue(Field f, Object value) {
    if (value != null) {
      return true;
    }

    Schema schema = f.schema();
    Type type = schema.getType();

    // If the type is null, any value is valid
    if (type == Type.NULL) {
      return true;
    }

    // If the type is a union that allows nulls, any value is valid
    if (type == Type.UNION) {
      for (Schema s : schema.getTypes()) {
        if (s.getType() == Type.NULL) {
          return true;
        }
      }
    }

    // The value is null but the type does not allow nulls
    return false;
  }
@Test
  void isValidValueWithPrimitives() {
    // Verify that a non-null value is valid for all primitives:
    for (Type type : primitives) {
      Field f = new Field("f", Schema.create(type), null, null);
      assertTrue(RecordBuilderBase.isValidValue(f, new Object()));
    }

    // Verify that null is not valid for all non-null primitives:
    for (Type type : nonNullPrimitives) {
      Field f = new Field("f", Schema.create(type), null, null);
      assertFalse(RecordBuilderBase.isValidValue(f, null));
    }
  }