Description copied from https://github.com/belaban/JGroups/discussions/799
This issue is related to discussion #641.
As far as I understand, the fix was applied only locally for X509Token. I am using RegexMembership and it fails with NPE in a similar way. The stack trace is like this:
ProtoclStack#initProtocolStack calls AUTH#init
AUTH#init calls RegexMembership#init
RegexMembership fields such as match_string are not yet initialized at this stage, so NPE is thrown
The issue is, as before, the order of operations here:
public void initProtocolStack(List<ProtocolConfiguration> configs, ProtocolHook afterCreationHook) throws Exception { List<Protocol> protocols=getProtocols(); Collections.reverse(protocols); try { for(int i=0; i < protocols.size(); i++) { Protocol prot=protocols.get(i); if(prot.getProtocolStack() == null) prot.setProtocolStack(this); callAfterCreationHook(prot, prot.afterCreationHook()); if (afterCreationHook != null) { afterCreationHook.afterCreation(prot); } prot.init(); // Here components are not yet initialized. The NPE will be thrown. initComponents(prot, configs != null? configs.get(i) : null); // Here the initialization is done. // sanity checking via policies: List<? extends Policy> pols=prot.getPolicies(); if(pols != null && !pols.isEmpty()) { for(Policy p: pols) p.check(prot); } } } catch(Exception ex) { this.destroy(); throw ex; } }
A solution is, as was suggested in a previous discussion, to move some checks from RegexMembership#init() to RegexMembership#start().
For example, I tweak the token like this:
public class CustomRegexMembership extends RegexMembership { @Override public void init() throws Exception { if (!match_ip_address && !match_logical_name) { throw new IllegalArgumentException("either match_ip_address or match_logical_address has to be true"); } } @Override public void start() throws Exception { if (match_string == null) { throw new IllegalArgumentException("match_string cannot be null"); } pattern = Pattern.compile(match_string); } }