Original S2 products contain lots of useful built-in masks like information about clouds. However, when I save the original product in *.dim format none of the masks are saved. It is not related with version of SNAP. I tried it in 6.0 and versions before it, same results. I guess it is a bug but could you please check this behaviour?
This is a known limitation. The masks are of a special type and are not yet handled correctly by the generic SNAP framework. If you need one of them you can turn it into a raster by Band Maths. Simply use the name of the mask as expression and uncheck the checkbox for creating a virtual band.
I tried it in SNAP UI and it works. Do you have any suggestion about how to do that in an operator? (within the code). I want to create a target product that will contain specific mask from sourceProduct.