[Mono-dev] Error in UnixGroupInfo

Jonathan Pryor jonpryor at vt.edu
Thu Jun 21 07:29:15 EDT 2007


So we have two proposed solutions:

1. Skip invalid user names in UnixGroupInfo.GetMembers().

Pro: Allows use on mis-configured systems

Con: The only way to know that an error occurred is to compare
UnixGroupInfo.GetMembers().Length to
UnixGroupInfo.GetMemberNames().Length, and then to find which one was
invalid you'd have to go through both arrays.

2. Return the invalid user from UnixGroupInfo.GetMembers(), but make the
UnixUserInfo instance returned provide invalid data; Rafael Teixeira
mentioned two ways to do this (subclass UnixUserInfo or have a bool
'valid' flag on the UnixUserInfo instance).

Pro: Allows use on mis-configured systems.
Pro: To find out which user is invalid you don't need to compare two
different arrays.

Con: All but one property would now be able to throw an exception, while
previously they wouldn't.  So currently-working "broken" code like this:

	UnixGroupInfo g = ...
	foreach (UnixUserInfo u in g.GetMembers ()) {
		Console.WriteLine ("User: {0}; Home: {1}",
			u.UserName, u.HomeDirectory);
	}

would now start throwing InvalidOperationException's on the
u.HomeDirectory property accessor.

A variation on (2) would be to have all properties return -1 or null
instead of throwing an InvalidOperationException.

Approach (1) may make it more difficult to figure out which user is
invalid, but (2) is effectively a breaking change as it will break
existing code.  Even the variation on (2) isn't good, as none of the
properties currently return null or otherwise invalid data, so `u.Group'
could now return null (resulting in a later NullReferenceException)
while before it couldn't.

I'm open to other opinions, but for now it looks like (1) is the saner
solution.

Thoughts?

 - Jon





More information about the Mono-devel-list mailing list