Java Runtime errors

Core environment and runtime library

https://java.com
Solution coverage:
Summary coverage:

Top patterns

  1. A class that is not available on the classpath or the class loader is closed

    java.lang.ClassNotFoundException is one of the most frequent exceptions in Java. It is a runtime error, however, it does not signal a bug in your application logic, but rather an issue with the environment (build system, dependency management, runtime environment, etc.)

    According to the javadoc, it "is thrown when an application tries to load in a class through its string name". There are several different situations leading to this error and you have to examine the stack trace thoroughly to be able to decide how to solve this problem.

    The first thing to check is whether you get this checked exception directly, or wrapped in a java.class.NoClassDefFoundException. The latter happens when the class not found was resolved during compilation time, but not found during runtime, which is a bit different than the first case and it needs special care. If this is what happened to you, then you should read that article (coming soon).

    Next we ask what is the class that was not found. Fortunately, in most cases, you can see it in the message of the exception. If this class was specified by you (either directly in the code, or via a configuration file), double check that you did not misspell it. Some practical advices:

    • Make sure you use the fully qualified name of the class (e.g. org.postgresql.ds.PGSimpleDataSource)
    • When loading a nested class, make sure you use the proper name (joined with a $ sign, e.g. test.MyClass$InnerClass).
    • If you are unsure, you can check the name of the class in the code by using MyClass.class.getName()

    If none of the above helped then you have an issue with your classpath, which requires some time and experience to resolve. When the java.lang.ClassNotFoundException is related to a third party library, you might want to ask for help in their support forums. However, if you want to debug it yourself, let me equip you with some theoretical and practical knowledge.

    • To understand what is class loading in Java, start with this StackOverflow question or the Java Language Specification §12.2. Roughly speaking, the classes that your application use are located in jar files on the file system. The classpath is a list of jar files which are searched through when your application loads a class. The java.lang.ClassNotFoundException means that the class you wanted to load is not present in any of the jar files on the classpath.
    • The configuration of your classpath depends on your runtime environment (i.e. do you run the application from console, from IDE, web container, etc), you can find more information on the specific forums. However, if you can use breakpoints to stop at specific points in your application, stop at the first line of java.net.URLClassLoader.findClass and check the value of the field ucp.
    • You should have an idea on which jar file contains the class that could not be loaded, and look for that jar in the classpath. If it is not there, you have to add that jar to the classpath (precise details depend on the runtime environment).
    • If you find the jar you suspect to contain your class, check if it is true by opening the jar file (they are simple zip files actually) and look for the class definition in the directory structure in it (the directory structure must be identical to the package structure of the java code). At this point you should realize that the class is not present, otherwise the problem would have been found previously during debugging.
    • There are two reasons for class not being present in the jar: the first is that you have an incorrect version of the library you wanted to use. To fix this, you have to tweak your build system (maven, ant, sbt, gradle etc) by making sure that you configured the right version of the library as the dependency, and that you don’t have conflicting library versions. To find out how to do this, look for help on the forums of that build system.
    • The other reason of the class not being present is that it’s a bug in that library. If this is a third-party library, you might want to check the support forum and the release notes. If this library was written by you, then try to rebuild this library and check if the class you look for is present in the resulting jar file.
  2. The class could not be found

    This error pattern looks similar to error pattern 88439.

    However, in this case, we are sure that this happens when sun.misc.URLClassPath.getResource(String name, boolean check) returns null. Practically every exception that happens in getResource is handled by returning null.

  3. Java Runtime cannot connect a network socket

    Roughly there are three categories of this problem:

    • no network available: Probably your machine's network interface is down. Check if you have internet and your application has permissions to use the network interface
    • connection refused: The address you are trying to connect is not listening. Check if you did not misspelled the host or the port. Also verify that the server you are trying to reach is actually running and listening.
    • connection timed out: The server took too much time to respond. You either have to increase the timeout limit or speed up the server.

DescriptionException TypeEntry MethodWeb pages

A class that is not available on the classpath or the class loader is closed

java.lang.ClassNotFoundException
2 frames hidden
java.net.URLClassLoader.findClass
6800Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6800

The class could not be found

java.lang.ClassNotFoundException
java.net.URLClassLoader.findClass
6311Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6311

Java Runtime cannot connect a network socket

java.net.ConnectException
java.net.PlainSocketImpl.socketConnect
4902Web pages
1Solution
ConnectExceptionPlainSocketImpl.socketConnect4902

PlainSocketImpl.doConnect() has thrown a ConnectException

java.net.ConnectException
1 frames hidden
java.net.PlainSocketImpl.doConnect
2914Web pages
ConnectExceptionPlainSocketImpl.doConnect2914

PlainSocketImpl.connectToAddress() has thrown a ConnectException

java.net.ConnectException
2 frames hidden
java.net.PlainSocketImpl.connectToAddress
2864Web pages
ConnectExceptionPlainSocketImpl.connectToAddress2864

PlainSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
3 frames hidden
java.net.PlainSocketImpl.connect
2845Web pages
ConnectExceptionPlainSocketImpl.connect2845

SocketInputStream.read() has thrown a SocketException

java.net.SocketException
java.net.SocketInputStream.read
2055Web pages
SocketExceptionSocketInputStream.read2055

SocketOutputStream.socketWrite0() has thrown a SocketException

java.net.SocketException
java.net.SocketOutputStream.socketWrite0
1961Web pages
SocketExceptionSocketOutputStream.socketWrite01961

SocksSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
4 frames hidden
java.net.SocksSocketImpl.connect
1936Web pages
ConnectExceptionSocksSocketImpl.connect1936

Socket.connect() has thrown a ConnectException

java.net.ConnectException
5 frames hidden
java.net.Socket.connect
1922Web pages
ConnectExceptionSocket.connect1922

SocketOutputStream.socketWrite() has thrown a SocketException

java.net.SocketException
1 frames hidden
java.net.SocketOutputStream.socketWrite
1909Web pages
SocketExceptionSocketOutputStream.socketWrite1909

SocketOutputStream.write() has thrown a SocketException

java.net.SocketException
2 frames hidden
java.net.SocketOutputStream.write
1896Web pages
1Solution
SocketExceptionSocketOutputStream.write1896

AbstractPlainSocketImpl.doConnect() has thrown a ConnectException

java.net.ConnectException
1 frames hidden
java.net.AbstractPlainSocketImpl.doConnect
1886Web pages
ConnectExceptionAbstractPlainSocketImpl.doConnect1886

AbstractPlainSocketImpl.connectToAddress() has thrown a ConnectException

java.net.ConnectException
2 frames hidden
java.net.AbstractPlainSocketImpl.connectToAddress
1871Web pages
ConnectExceptionAbstractPlainSocketImpl.connectToAddress1871

AbstractPlainSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
3 frames hidden
java.net.AbstractPlainSocketImpl.connect
1862Web pages
ConnectExceptionAbstractPlainSocketImpl.connect1862

SocksSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
4 frames hidden
java.net.SocksSocketImpl.connect
1836Web pages
ConnectExceptionSocksSocketImpl.connect1836

Java Runtime cannot connect a network socket

java.net.ConnectException
5 frames hidden
java.net.Socket.connect
1820Web pages
1Solution
ConnectExceptionSocket.connect1820

URLClassLoader.defineClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
3 frames hidden
java.net.URLClassLoader.defineClass
1668Web pages
UnsupportedClassVersionErrorURLClassLoader.defineClass1668

SocketInputStream.socketRead0() has thrown a SocketTimeoutException

java.net.SocketTimeoutException
java.net.SocketInputStream.socketRead0
1563Web pages
1Solution
SocketTimeoutExceptionSocketInputStream.socketRead01563

URLClassLoader.access$100() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
4 frames hidden
java.net.URLClassLoader.access$100
1346Web pages
UnsupportedClassVersionErrorURLClassLoader.access$1001346

URLClassLoader$1.run() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
5 frames hidden
java.net.URLClassLoader$1.run
1338Web pages
UnsupportedClassVersionErrorURLClassLoader$1.run1338

URL.<init>() has thrown a MalformedURLException

java.net.MalformedURLException
java.net.URL.<init>
1261Web pages
MalformedURLExceptionURL.<init>1261

Socket.connect() has thrown a ConnectException

java.net.ConnectException
6 frames hidden
java.net.Socket.connect
1230Web pages
ConnectExceptionSocket.connect1230

URL.<init>() has thrown a MalformedURLException

java.net.MalformedURLException
1 frames hidden
java.net.URL.<init>
1210Web pages
MalformedURLExceptionURL.<init>1210

SocketInputStream.read() has thrown a SocketException

java.net.SocketException
1 frames hidden
java.net.SocketInputStream.read
1163Web pages
1Solution
SocketExceptionSocketInputStream.read1163

URLClassLoader.defineClass() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
3 frames hidden
java.net.URLClassLoader.defineClass
1125Web pages
NoClassDefFoundErrorURLClassLoader.defineClass1125

SocketInputStream.read() has thrown a SocketTimeoutException

java.net.SocketTimeoutException
1 frames hidden
java.net.SocketInputStream.read
1123Web pages
SocketTimeoutExceptionSocketInputStream.read1123

PlainSocketImpl.socketBind() has thrown a BindException

java.net.BindException
java.net.PlainSocketImpl.socketBind
1083Web pages
BindExceptionPlainSocketImpl.socketBind1083

URL.<init>() has thrown a MalformedURLException

java.net.MalformedURLException
2 frames hidden
java.net.URL.<init>
1051Web pages
MalformedURLExceptionURL.<init>1051

AbstractPlainSocketImpl.doConnect() has thrown a ConnectException

java.net.ConnectException
2 frames hidden
java.net.AbstractPlainSocketImpl.doConnect
885Web pages
ConnectExceptionAbstractPlainSocketImpl.doConnect885

AbstractPlainSocketImpl.connectToAddress() has thrown a ConnectException

java.net.ConnectException
3 frames hidden
java.net.AbstractPlainSocketImpl.connectToAddress
882Web pages
ConnectExceptionAbstractPlainSocketImpl.connectToAddress882

AbstractPlainSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
4 frames hidden
java.net.AbstractPlainSocketImpl.connect
880Web pages
ConnectExceptionAbstractPlainSocketImpl.connect880

URLClassLoader$1.run() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
6 frames hidden
java.net.URLClassLoader$1.run
876Web pages
UnsupportedClassVersionErrorURLClassLoader$1.run876

PlainSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
5 frames hidden
java.net.PlainSocketImpl.connect
874Web pages
ConnectExceptionPlainSocketImpl.connect874

URLClassLoader.findClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
8 frames hidden
java.net.URLClassLoader.findClass
873Web pages
UnsupportedClassVersionErrorURLClassLoader.findClass873

SocksSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
6 frames hidden
java.net.SocksSocketImpl.connect
859Web pages
ConnectExceptionSocksSocketImpl.connect859

Socket.connect() has thrown a ConnectException

java.net.ConnectException
7 frames hidden
java.net.Socket.connect
856Web pages
1Solution
ConnectExceptionSocket.connect856

SocketInputStream.socketRead0() has thrown a SocketException

java.net.SocketException
java.net.SocketInputStream.socketRead0
844Web pages
SocketExceptionSocketInputStream.socketRead0844

Socket.<init>() has thrown a ConnectException

java.net.ConnectException
7 frames hidden
java.net.Socket.<init>
844Web pages
ConnectExceptionSocket.<init>844

Socket.<init>() has thrown a ConnectException

java.net.ConnectException
8 frames hidden
java.net.Socket.<init>
840Web pages
ConnectExceptionSocket.<init>840

URLClassLoader.defineClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
4 frames hidden
java.net.URLClassLoader.defineClass
837Web pages
UnsupportedClassVersionErrorURLClassLoader.defineClass837

URLClassLoader.access$000() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
5 frames hidden
java.net.URLClassLoader.access$000
833Web pages
UnsupportedClassVersionErrorURLClassLoader.access$000833

URLClassLoader$1.run() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
6 frames hidden
java.net.URLClassLoader$1.run
831Web pages
UnsupportedClassVersionErrorURLClassLoader$1.run831

URLClassLoader.findClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
8 frames hidden
java.net.URLClassLoader.findClass
828Web pages
UnsupportedClassVersionErrorURLClassLoader.findClass828

URI$Parser.fail() has thrown an URISyntaxException

java.net.URISyntaxException
java.net.URI$Parser.fail
824Web pages
URISyntaxExceptionURI$Parser.fail824

URLClassLoader.access$100() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
4 frames hidden
java.net.URLClassLoader.access$100
791Web pages
NoClassDefFoundErrorURLClassLoader.access$100791

URLClassLoader.defineClass() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
3 frames hidden
java.net.URLClassLoader.defineClass
778Web pages
NoClassDefFoundErrorURLClassLoader.defineClass778

URLClassLoader$1.run() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
5 frames hidden
java.net.URLClassLoader$1.run
768Web pages
NoClassDefFoundErrorURLClassLoader$1.run768

PlainSocketImpl.bind() has thrown a BindException

java.net.BindException
1 frames hidden
java.net.PlainSocketImpl.bind
734Web pages
BindExceptionPlainSocketImpl.bind734

Socket.connect() has thrown a ConnectException

java.net.ConnectException
6 frames hidden
java.net.Socket.connect
723Web pages
ConnectExceptionSocket.connect723
Package namePatterns foundSolution coverageSummary coverage
java.lang7927
java.util.concurrent4667
java.io4419
java.lang.reflect4019
java.awt2397
java.net2282
sun.reflect2209
java.util1921
javax.swing1636
java.security1033
javax.naming1017
java.sql803
sun.net.www.protocol.http740
sun.net.www.protocol.https718
sun.nio.ch466
sun.rmi.server381
sun.rmi.transport.tcp326
java.util.zip322
com.sun.jndi.ldap289
java.util.regex285
com.sun.org.apache.xerces.internal.impl269
sun.net.www.http261
java.nio.file257
com.sun.org.apache.xerces.internal.parsers247
javax.swing.plaf.basic240
sun.misc236
java.util.logging172
com.sun.org.apache.xerces.internal.jaxp168
java.util.jar162
java.beans160
javax.swing.text158
java.nio157
sun.rmi.registry151
java.util.stream143
javax.security.auth.login143
java.text143
javax.management.remote.rmi142
java.rmi137
javax.imageio135
sun.rmi.transport134
sun.nio.cs131
javax.net.ssl129
java.awt.event124
com.sun.org.apache.xalan.internal.xsltc.trax117
java.awt.image115
javax.security.auth115
java.nio.channels110
java.rmi.server92
java.util.concurrent.locks90
javax.naming.directory88
Package nameClass namePatterns foundSolution coverageSummary coverage
java.netSocket403
java.netURLClassLoader334
java.netURL286
java.netPlainSocketImpl157
java.netInetAddress154
java.netURLClassLoader$1152
java.netServerSocket117
java.netHttpURLConnection114
java.netDatagramSocket84
java.netSocketInputStream81
java.netURI60
java.netURLConnection49
java.netAbstractPlainSocketImpl48
java.netPlainDatagramSocketImpl32
java.netSocksSocketImpl27
java.netSocketOutputStream26
java.netMulticastSocket21
java.netURI$Parser21
java.netInetSocketAddress16
java.netNetworkInterface14
java.netInet6AddressImpl7
java.netURLDecoder7
java.netURLClassLoader$26
java.netURLStreamHandler6
java.netURLEncoder6
java.netInetAddress$15
java.netIDN5
java.netURLPermission5
java.netDatagramPacket4
java.netSocketPermission4
java.netAuthenticator4
java.netJarURLConnection3
java.netURLClassLoader$3$13
java.netCookieHandler2
java.netHttpCookie2
java.netURLClassLoader$42
java.netAbstractPlainDatagramSocketImpl2
java.netProxySelector2
java.netURLClassLoader$51
java.netHostPortrange1
java.netCookieManager1
java.netInet4AddressImpl1
java.netURLClassLoader$31
java.netInet6Address1
java.netSocketPermission$11
java.netMalformedURLException1
java.netSocketException1
java.netInetAddress$21
java.netSocket$11
Package nameClass nameMethod namePatterns foundSolution coverage
java.netSocketconnect201
java.netURLopenStream183
java.netURLClassLoaderfindClass154
java.netURLClassLoader$1run152
java.netSocket<init>125
java.netHttpURLConnectiongetResponseCode109
java.netURLClassLoaderdefineClass99
java.netSocketInputStreamread61
java.netPlainSocketImplconnect55
java.netInetAddressgetAllByName50
java.netServerSocket<init>49
java.netURLopenConnection42
java.netURL<init>34
java.netURLClassLoaderaccess$10029
java.netInetAddressgetByName29
java.netServerSocketbind29
java.netDatagramSocket<init>27
java.netSocksSocketImplconnect25
java.netServerSocketaccept25
java.netInetAddressgetLocalHost25
java.netPlainSocketImplsocketConnect23
java.netURIcreate23
java.netURI<init>22
java.netDatagramSocketreceive21
java.netDatagramSocketsend19
java.netURLConnectiongetContentLength19
java.netSocketOutputStreamwrite18
java.netAbstractPlainSocketImplconnect17
java.netURLClassLoaderaccess$00017
java.netAbstractPlainSocketImpldoConnect17
java.netURLConnectiongetContent12
java.netPlainSocketImpldoConnect12
java.netSocketstartupSocket12
java.netInetAddresslookupHostByName11
java.netDatagramSocketbind11
java.netSocketInputStreamsocketRead011
java.netInetAddressgetAllByName011
java.netInetSocketAddress<init>11
java.netURLgetContent11
java.netServerSocketimplAccept11
java.netURLClassLoaderfindResource10
java.netURI$Parserparse10
java.netPlainSocketImplbind10
java.netMulticastSocketjoinGroup9
java.netSocketsetSoTimeout9
java.netAbstractPlainSocketImplconnectToAddress9
java.netInetAddressgetAddressesFromNameService8
java.netSockettryAllAddresses8
java.netSocketbind8
java.netInetAddressgetAllByNameImpl8
Package nameClass nameMethod nameException TypePatterns foundSolution coverage
java.netSocketconnectConnectException51
java.netSocketconnectSocketException42
java.netInetAddressgetAllByNameUnknownHostException27
java.netSocket<init>SocketException27
java.netSocket<init>ConnectException26
java.netServerSocket<init>BindException26
java.netURLopenStreamFileNotFoundException25
java.netURLopenStreamConnectException24
java.netURLClassLoaderdefineClassNoClassDefFoundError23
java.netURLopenStreamIOException23
java.netHttpURLConnectiongetResponseCodeSocketException22
java.netHttpURLConnectiongetResponseCodeConnectException20
java.netURLClassLoaderfindClassSecurityException20
java.netURLopenStreamUnknownHostException19
java.netURLopenStreamSSLHandshakeException19
java.netServerSocketbindBindException19
java.netURLClassLoaderfindClassNoClassDefFoundError18
java.netInetAddressgetByNameUnknownHostException18
java.netSocketconnectUnknownHostException18
java.netPlainSocketImplconnectConnectException17
java.netInetAddressgetLocalHostUnknownHostException17
java.netURI<init>URISyntaxException17
java.netSocketconnectSocketTimeoutException17
java.netURLClassLoaderfindClassUnsupportedClassVersionError16
java.netURLClassLoader$1runNoClassDefFoundError16
java.netServerSocket<init>SocketException16
java.netDatagramSocket<init>BindException15
java.netHttpURLConnectiongetResponseCodeSocketTimeoutException15
java.netURLClassLoaderfindClassClassNotFoundException14
java.netURLClassLoaderdefineClassSecurityException13
java.netURLopenStreamSocketException13
java.netSocketInputStreamreadSocketException13
java.netURIcreateIllegalArgumentException13
java.netSocketconnectNoRouteToHostException12
java.netSocket<init>UnknownHostException12
java.netSocket<init>AccessControlException12
java.netURL<init>MalformedURLException12
java.netSocketInputStreamreadSocketTimeoutException12
java.netURLClassLoader$1runUnsupportedClassVersionError12
java.netDatagramSocket<init>SocketException11
java.netSocksSocketImplconnectConnectException11
java.netHttpURLConnectiongetResponseCodeUnknownHostException11
java.netURLClassLoaderdefineClassUnsupportedClassVersionError10
java.netURLClassLoader$1runSecurityException10
java.netURLClassLoaderfindClassClassFormatError10
java.netServerSocketacceptSocketException10
java.netAbstractPlainSocketImplconnectConnectException9
java.netDatagramSocketreceiveSocketException9
java.netURI$ParserparseURISyntaxException9
java.netSocketconnectBindException8