roster.addSubscribeListener() can't receive the Type.Subscribe sometimes

i am using Smack 4.4.8

i try to use UserA to send a Presence.Type.Subscribe packet by roster.createItemAndRequestSubscription to UserB who is offline.

If I write the code like this:

        Roster roster = Roster.getInstanceFor(connection);

        roster.setSubscriptionMode(Roster.SubscriptionMode.manual);

        System.out.println(roster.getSubscriptionMode());

        roster.addSubscribeListener(new SubscribeListener() {
            @Override
            public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
                System.out.println(subscribeRequest.toXML());
                return null;
            }
        });

When UserB online , he will receive the packet from UserA.

But if i change the postion of the " roster.addSubscribeListener" like this:

        Roster roster = Roster.getInstanceFor(connection);

        roster.setSubscriptionMode(Roster.SubscriptionMode.manual);

        System.out.println(roster.getSubscriptionMode());
       <------------------------------------------------------------>
            other code
            other code
            other code
            other code
            other code
       <------------------------------------------------------------>

        roster.addSubscribeListener(new SubscribeListener() {
            @Override
            public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
                System.out.println(subscribeRequest.toXML());
                return null;
            }
        });

When UserB online ,he can’t receive the packet from UserA. Even packets from UserA will be deleted directly sometimes.

You don’t seem to invoke Roster.createItemAndRequestSubscription() in the two code snippets shown.