SocketTimeout on Java 11 but not on Java 8

The OKHttp version you are using is incompatible with Java 11 (Java 9 and above actually).

Microsoft Graph 1.7.1 has a dependency of Microsoft Graph Core 1.0.0, which has a dependency on OKHttp version 3.12.1.

According to Square's changelog for OKHttp, 3.12.x is a LTS version for Java 7+. This means it will expect certain packages/modules and class names to exist, which may not after Java 9 and above (more below).

Version 3.14.8 introduced some fixes for Java 9 API changes that break OKHttp.

You should manually specify this version of OKHttp in your POM, or include this Jar to override the older version's implicit dependency.

As an aside, this is a common issue when porting things from Java 8 to Java 9 and above. Project Jigsaw broke out many components of the bloated JDK into modules. Many of the "enterprise" features that made the JDK so large were separated into their own modules, which you must specify to include in your project. Many libraries from the Java 8 days and older expect these modules to still exist "out of the box", which leads to strange failures like what you are seeing - but more commonly the infamous NoClassDefFoundError.


OkHttp on JDK9 (or JDK8 252+), will negotiate HTTP/2 by default. There is a high chance it is related to this change.

Try building a client without HTTP/2 and see if you still get this problem.

  val client = OkHttpClient.Builder()
      .protocols(listOf(Protocol.HTTP_1_1))
      .build()

If it fixes things, it's likely either an incompatibility of the server with HTTP/2, or related to connection reuse e.g. too many requests over a single connection.

UPDATE by kekolab 20201030.

Microsoft fixed the issue by restraining the protocol version to 1.1, exactly as suggested by the OP Yuri above. Nice stuff, this thread is referenced in the code: https://github.com/microsoftgraph/msgraph-sdk-java/pull/473/files#