We are working on an application in which we need to pass a SID.
We have an ACLEntry object from which we obtain the UserPrincipal then using reflection, we make the sid field accessible and retrieve it.
//reflection to get sid string, so we can return sid with userAndGroup name
Class<?> c = Class.forName("sun.nio.fs.WindowsUserPrincipals$User");
Field sidString = c.getDeclaredField("sidString");
sidString.setAccessible(true);
UserPrincipal userPrincipal = aclEntry.principal();
String sid = ((String) sidString.get(userPrincipal)).toLowerCase();
This worked on Java 8 but we're migrating to Java 17 and when we run the code, we receive the error: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.String sun.nio.fs.WindowsUserPrincipals$User.sidString accessible: module java.base does not "opens sun.nio.fs" to unnamed module @5f150435
Is there a way to access this sidString without using reflection or is there a way to bypass this InaccessibleObjectException using reflection?