powered by Jive Software

Bug in HybridUserProvider

I noticed a bug in openfire’s HybridUserProvider today. The code below results in “userproviders” always containing null values.

Since this breaks the provider, I cant imagine it always worked this way. It looks like a regression introduced by a refactoring. Its a good example of where unit tests repay the high cost of their creation.

public class HybridUserProvider implements UserProvider {

private UserProvider primaryProvider = null;
private UserProvider secondaryProvider = null;
private UserProvider tertiaryProvider = null;
private UserProvider[] userproviders = {primaryProvider, secondaryProvider, tertiaryProvider};

Hello Ben,

I’d be happy to file this issue in Jira. Could you provide a patch for it and perhaps the unit tests you think are necessary?

thanks,

daryl

How would HybridUserProvider be set in this fashion, e.g. from a user’s perspective? I don’t understand what circumstances would cause this bug to be manifested.

Thanks

Hi,

userproviders[] is initialized with null values. That’s just fine, but I assume that one would like to add assign usefull values to it at the end of the constructor

public HybridUserProvider() {      ...;
     userproviders = {primaryProvider, secondaryProvider, tertiaryProvider};
}
...
for (UserProvider provider : userproviders) {

So the for loop may work much better.

Otherwise it is a private read-only object and one should make it final, just like this (while I think that this was not the intention):

private final UserProvider[] userproviders = {null, null, null};

LG