java.lang.NoSuchMethodError


Maven can be nice, but sometimes you can end up with one jar loading before another and that causes unpredictable results at run-time.

An example exception:

  
Exception in thread "Thread-24" java.lang.NoSuchMethodError: 
 com.sun.mail.util.SocketFetcher.getSocket(Ljava/lang/String;ILjava/util/Properties;Ljava/lang/String;Z)Ljava/net/Socket;
	at  com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
	at javax.mail.Service.connect(Service.java:288)
	at javax.mail.Service.connect(Service.java:169)

How to find the offending jar file:

     
     Class cls = SocketFetcher.class;
     ProtectionDomain pDomain = cls.getProtectionDomain();
     CodeSource cSource = pDomain.getCodeSource();
     URL loc = cSource.getLocation();
     System.out.println(loc.toString());

How to fix it:

   <dependency>
      ...
      <exclusions>
        <exclusionv
          <groupId>com.google</groupId>
          <artifactId>googleapi-nomail</artifactId>
        </exclusion>
     </exclusions>
   </dependency>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s