Call method setBooleanAttribute of class Member cause java.lang.NullPointerException #6223

Closed
Xrew opened this Issue Sep 15, 2015 · 6 comments

Projects

None yet

2 participants

@Xrew
Xrew commented Sep 15, 2015

Using hazelcast 3.5.2.

Hi,
problem is, that if i execute method setBooleanAttribute of class Member, than NullPointerException occured on STDOUT. I have debugged it and the problem is in class ClusterServiceImpl in method sendMemberAttributeEvent.
There is created event for service QuorumServiceImpl:

final MemberAttributeServiceEvent event = new MemberAttributeServiceEvent(getClusterProxy(), member, operationType, key, value);

This event inherit from MembershipEvent, and variable members is setted to null.

 public MemberAttributeEvent(Cluster cluster, Member member, MemberAttributeOperationType operationType,
                                String key, Object value) {
        super(cluster, member, MEMBER_ATTRIBUTE_CHANGED, null);
        this.member = member;
        this.operationType = operationType;
        this.key = key;
        this.value = value;
    }

Problem is, that this event is later in this method executed here:

 nodeEngine.getExecutionService().execute(ExecutionService.SYSTEM_EXECUTOR, new Runnable() {
      public void run() {
           service.memberAttributeChanged(event);
      }
});

with service of instance QuorumServiceImpl and on the end by QuorumImpl, where exception is occurred in

private class MemberCountQuorumFunction implements QuorumFunction {
        @Override
        public boolean apply(Collection<Member> members) {
            return members.size() >= size;
        }
    }

because members variable is null.

Stacktrace:
Exception in thread "cached4" java.lang.NullPointerException at com.hazelcast.quorum.impl.QuorumImpl$MemberCountQuorumFunction.apply(QuorumImpl.java:179) at com.hazelcast.quorum.impl.QuorumImpl.update(QuorumImpl.java:63) at com.hazelcast.quorum.impl.QuorumServiceImpl.updateQuorums(QuorumServiceImpl.java:166) at com.hazelcast.quorum.impl.QuorumServiceImpl.memberAttributeChanged(QuorumServiceImpl.java:160) at com.hazelcast.cluster.impl.ClusterServiceImpl$8.run(ClusterServiceImpl.java:1295) at com.hazelcast.util.executor.CachedExecutorServiceDelegate$Worker.run(CachedExecutorServiceDelegate.java:209) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76) at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)

@jerrinot jerrinot added this to the 3.6 milestone Sep 15, 2015
@jerrinot
Contributor

@Xrew: Thank you for reporting the issue and your excellent analysis. It seems as a clear bug to me. Let's see what we can do about it.

@jerrinot jerrinot added VERIFIED and removed PENDING labels Sep 15, 2015
@jerrinot
Contributor

The class hierarchy seems a bit odd. The MembershipEvent class says: Membership event fired when a new member is added to the cluster and/or when a member leaves the cluster.

However its subclass MemberAttributeServiceEvent says: This service event is fired to inform services about a change in a member's attributes collection.

@jerrinot jerrinot self-assigned this Sep 15, 2015
@jerrinot jerrinot added a commit to jerrinot/hazelcast that referenced this issue Sep 15, 2015
@jerrinot jerrinot QuorumService ignores member attribute change events
Fixed #6223
There is no member set in  MemberAttributeServiceEvent.
6d248eb
@jerrinot jerrinot added a commit to jerrinot/hazelcast that referenced this issue Sep 15, 2015
@jerrinot jerrinot QuorumService ignores member attribute change events
Fixed #6223
There is no member set in  MemberAttributeServiceEvent.
eea2e7c
@Xrew
Xrew commented Sep 16, 2015

I would like to ask you, if there is some workaround of this issue. I need to use this...Thank you :-)

@jerrinot
Contributor

@Xrew:

The only (imperfect) workaround I can think of is to provide a custom quorum function. Something along these lines:

    private class StatefulMemberCountQuorumFunction implements QuorumFunction {
        private volatile boolean lastState;

        @Override
        public boolean apply(Collection<Member> members) {
            if (members == null) {
                return lastState;
            }
            boolean quorum = members.size() >= size;
            lastState = quorum;
            return quorum;
        }
    }
@Xrew
Xrew commented Sep 16, 2015

Thanks

@jerrinot
Contributor

@Xrew: No problem. Have a great day!

@jerrinot jerrinot closed this in #6225 Sep 16, 2015
@jerrinot jerrinot added a commit to jerrinot/hazelcast that referenced this issue Sep 16, 2015
@jerrinot jerrinot QuorumService ignores member attribute change events
Backport of #6225, Fixes #6223
There is no member set in MemberAttributeServiceEvent.
(cherry picked from commit eea2e7c)
5a68f95
@Donnerbart Donnerbart added a commit to Donnerbart/hazelcast that referenced this issue Sep 17, 2015
@jerrinot @Donnerbart jerrinot + Donnerbart QuorumService ignores member attribute change events
Fixed #6223
There is no member set in  MemberAttributeServiceEvent.
675e9d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment