powered by Jive Software

smack cannot retrieve offline messages via OfflineMessageManager

I have a problem with while getting offline messages from ejabberd server 18.01 via smack library.
I have a connector method

private static AbstractXMPPConnection connectToServer(String serverHost, Integer port, String userName, String userPassword) {
            DomainBareJid xmppDomain = null;
            try {
                xmppDomain = JidCreate.domainBareFrom(serverHost);
            } catch (XmppStringprepException e) {
                System.out.println("XMPP Domain initialization exception " + e.getMessage());
                return null;
            XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            AbstractXMPPConnection connection = new XMPPTCPConnection(config);
            try {
                connection.connect().login(userName, userPassword);
                return connection;
            } catch (XMPPException | SmackException | IOException | InterruptedException e) {
                System.out.println("Something went wrong while connection to server: " + e.getMessage());
                return null;

and offline messages receiver

private XMPPConnection connection;
        public void run() {
            connection = Connector.getInstance();
            if (connection != null) {
                System.out.println("Start listening messages in the background");
                String offlineMessageOffline = "Offline message is %s from %s";
                OfflineMessageManager offlineMessageManager = new OfflineMessageManager(connection);
                try {
                    if (offlineMessageManager.supportsFlexibleRetrieval()) {
                                .forEach(message -> {
                                    System.out.println(String.format(offlineMessageOffline, message.getBody(), message.getFrom()));
    //                    offlineMessageManager.deleteMessages();
                } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException |
                        SmackException.NotConnectedException | InterruptedException e) {
                    System.out.println(String.format("Error while getting offline messages from server: by the reason %s", e.getMessage()));
                try {
                    connection.sendStanza(new Presence(Presence.Type.available));
                } catch (SmackException.NotConnectedException e) {
                } catch (InterruptedException e) {
                ChatManager chatManager = ChatManager.getInstanceFor(connection);
                IncomingChatMessageListener listener = (entityBareJid, message, chat) -> {
                    System.out.println(String.format("Incoming message is %s from %s", message.getBody(), message.getFrom()));
            } else {
                System.out.println("Connection has not been established. Please try to choose option 1");

I start running message listener at the background. I see that database has an offline message and in the dubug node I see that offlineMessageManager.getMessageCount() returns the proper number of offline messages but method offlineMessageManager.getMessages() returns noting. The smack version is 4.2.3 but earlier version has the same problem

Please have a look at https://github.com/igniterealtime/Smack/wiki/How-to-ask-for-help,-report-an-issue-and-possible-solve-the-problem-yourself

Especially an XMPP trace would be helpful.