"XMPP Reader Thread" java.lang.NoSuchMethodError:...ConcurrentHashMap$KeySetView

Issue #44 closed
Geoffrey Knauth created an issue

My program ran great for days, then hung after logging this exception:

Exception in thread "XMPP Reader Thread" java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
2015/06/16 03:01:11 | at rocks.xmpp.core.subscription.PresenceManager$3.sessionStatusChanged(PresenceManager.java:108)
2015/06/16 03:01:11 | at rocks.xmpp.core.session.XmppSession.notifySessionStatusListeners(XmppSession.java:1488)
2015/06/16 03:01:11 | at rocks.xmpp.core.session.XmppSession.updateStatus(XmppSession.java:1479)
2015/06/16 03:01:11 | at rocks.xmpp.core.session.XmppSession.notifyException(XmppSession.java:1320)
2015/06/16 03:01:11 | at rocks.xmpp.core.session.XmppStreamReader$1.run(XmppStreamReader.java:174)
2015/06/16 03:01:11 | at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
2015/06/16 03:01:11 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
2015/06/16 03:01:11 | at java.lang.Thread.run(Unknown Source)

I found another issue (#36) that seemed similar, in that the exception thrown should only have been possible with Java 8, whereas the OP (and I) use Java 7.

I'm supposed to catch this Exception and shutdown the service so that it may immediately restart. I'm not sure where to do that. I have a MyMessageListener that implements handleMessage(MessageEvent e).

Comments (10)

  1. Geoffrey Knauth reporter

    I believe the NoSuchMethodError is caused at the call to presenceMap.keySet() in PresenceManager.java. It might be a Java8-only method ConcurrentHashMap$KeySetView is being invoked, which is a mystery since I thought this was a Java7 library.

            xmppSession.addSessionStatusListener(new SessionStatusListener() {
                @Override
                public void sessionStatusChanged(SessionStatusEvent e) {
                    if (e.getStatus() == XmppSession.Status.DISCONNECTED) {
                        for (Jid contact : presenceMap.keySet()) {
                            try {
                                xmppSession.handleElement(new Presence(Presence.Type.UNAVAILABLE).withFrom(contact));
                            } catch (Exception e1) {
                                logger.log(Level.WARNING, e1.getMessage(), e1);
                            }
                        }
                    }
                }
            });
        }
    

    My hack of a solution, if it works, is to implement my own sessionStatusChanged method in MySessionStatusListener.java, and if I detect the XMPP Session has been disconnected, to exit the program, so that the service will be automatically restarted:

        public void sessionStatusChanged(SessionStatusEvent e) {
            if (e.getStatus() == XmppSession.Status.DISCONNECTED) {
                log.error("ERROR XmppSession DISCONNECTED, exiting, should cause Service Restart of XyzProcessor.");
                System.exit(1);
            }
        }
    
  2. Christian Schudt repo owner

    Yes, it's the same issue described in issue #36. And yes, version 0.5.0 is supposed to work on Java 7 and actually it doesn't use any non-JDK 7 API.

    The issue was some strange cross-compiling issue, which I wasn't aware of when compiling version 0.5.0. I compiled it with Java 8 and obviously it results in problems like these.

    Solution (according to what I've found out): 1. Compile 0.5.0 with Java 7 yourself. 2. Change "private final ConcurrentHashMap" to "private final Map" in PresenceManager.java, line 67, compile with Java 8 and run on Java 7. 3. Kindly ask me to fix it and release a 0.5.1 version ;-) 4. Use Java 8.

  3. Geoffrey Knauth reporter

    Christian, thanks for your answer. I ask kindly for a 0.5.1 release with a fix--it will make people above me happier if an "official" release is available. In the meantime, I'll compile 0.5.0 myself with Java 7. By the way, what is the strange cross-compiling issue? Is that an Oracle problem, or something else?

  4. Geoffrey Knauth reporter

    I tried to do the build myself (mvn package) and everything went smoothly until I got to this:

    Running TestSuite
    Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@9099c38
    Tests run: 495, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 8.025 sec <<< FAILURE!
    marshalBirthDayVCard(rocks.xmpp.extensions.vcard.temp.VCardTest)  Time elapsed: 0.004 sec  <<< FAILURE!
    java.lang.AssertionError: expected [<vCard xmlns="vcard-temp" version="3.0"><BDAY>2004-03-20Z</BDAY></vCard>] but found [<vCard xmlns="vcard-temp" version="3.0"><BDAY>2004-03-19Z</BDAY></vCard>]
            at org.testng.Assert.fail(Assert.java:94)
            at org.testng.Assert.failNotEquals(Assert.java:494)
            at org.testng.Assert.assertEquals(Assert.java:123)
            at org.testng.Assert.assertEquals(Assert.java:176)
            at org.testng.Assert.assertEquals(Assert.java:186)
            at rocks.xmpp.extensions.vcard.temp.VCardTest.marshalBirthDayVCard(VCardTest.java:173)
    
    
    Results :
    
    Failed tests:   marshalBirthDayVCard(rocks.xmpp.extensions.vcard.temp.VCardTest): expected [<vCard xmlns="vcard-temp" version="3.0"><BDAY>2004-03-20Z</BDAY></vCard>] but found [<vCard xmlns="vcard-temp" version="3.0"><BDAY>2004-03-19Z</BDAY></vCard>]
    
    Tests run: 495, Failures: 1, Errors: 0, Skipped: 0
    
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO]
    [INFO] XMPP.rocks - An XMPP Stack ........................ SUCCESS [  0.221 s]
    [INFO] XMPP Core Library ................................. SUCCESS [ 11.296 s]
    [INFO] Babbler - an XMPP Client Library (Core) ........... SUCCESS [  4.725 s]
    [INFO] XMPP Extensions Library ........................... FAILURE [ 12.764 s]
    [INFO] Babbler - an XMPP Client Library (Extensions) ..... SKIPPED
    [INFO] Babbler - XMPP Debugging Library .................. SKIPPED
    [INFO] Babbler - Samples ................................. SKIPPED
    [INFO] xmpp-fx ........................................... SKIPPED
    [INFO] Babbler - Documentation ........................... SKIPPED
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    
  5. Christian Schudt repo owner

    Cross-compiling: I haven't delved into this topic, but the issue is explained here a little bit: https://gist.github.com/AlainODea/1375759b8720a3f9f094

    Regarding the failed test: It worked at my machine (and appearently also on the Continuous Integration machine), because we use a "good" time zone. I guess you are in a negative timezone, causing the day to swap. Known issue #40.

    Just comment the test case out, when building.

  6. Christian Schudt repo owner

    I've uploaded version 0.5.1 to Maven Central. This time built with Java 7 ;-). This should hopefully fix this issue.

  7. Log in to comment