Perhaps I can cache some of the most common patterns.
IIRC, any JNI library may request and use another classes private
variables. So, if you are using EnumSet, it should be safe for your JNI
code to assume that it is using an instance of java.util.RegularEnumSet,
with a jlong named "elements", and twiddle with it all you like.
This does require a few constraints: Your enums must be aligned such that
1 << enum ordinal == Windows bitmask from WinNT.h, so it means you'll
probably have to stuff your Enum with some RESERVED/PLACEHOLDER Enums to
fill in between undeclared gaps, like:
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
Also, assuming your code would allow setting attributes, then it would
need to either enforce the use of EnumSet as a parameter, or if it allows
just Set, it would have to provide an alternate mechanism for setting
attributes if the user is not using an EnumSet (ala
Collections.synchronizedSet, or HashSet). And, as long as you provide an
alternate method, then you can fail gracefully for the oddball cases, like
GNU classpath, which could set up the classes entirely differently.
HTH,
-Zig