Java Runtime errors

Core environment and runtime library

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

Top patterns

  1. 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.

  2. 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.
  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

The class could not be found

java.lang.ClassNotFoundException
java.net.URLClassLoader.findClass
6684Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6684

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
6453Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6453

Java Runtime cannot connect a network socket

java.net.ConnectException
java.net.PlainSocketImpl.socketConnect
4739Web pages
1Solution
ConnectExceptionPlainSocketImpl.socketConnect4739

SocketInputStream.read() has thrown a SocketException

java.net.SocketException
java.net.SocketInputStream.read
1966Web pages
SocketExceptionSocketInputStream.read1966

SocketOutputStream.socketWrite0() has thrown a SocketException

java.net.SocketException
java.net.SocketOutputStream.socketWrite0
1820Web pages
SocketExceptionSocketOutputStream.socketWrite01820

Connection timed out while trying to read from a socket

java.net.SocketTimeoutException
java.net.SocketInputStream.socketRead0
1507Web pages
1Solution
SocketTimeoutExceptionSocketInputStream.socketRead01507

URL.<init>() has thrown a MalformedURLException

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

PlainSocketImpl.socketBind() has thrown a BindException

java.net.BindException
java.net.PlainSocketImpl.socketBind
1019Web pages
BindExceptionPlainSocketImpl.socketBind1019

URI parsing failed due to un-encoded url string

java.net.URISyntaxException
java.net.URI$Parser.fail
788Web pages
1Solution
URISyntaxExceptionURI$Parser.fail788

AbstractPlainSocketImpl.connect() has thrown an UnknownHostException

java.net.UnknownHostException
java.net.AbstractPlainSocketImpl.connect
614Web pages
UnknownHostExceptionAbstractPlainSocketImpl.connect614

SocketOutputStream.socketWrite() has thrown a SocketException

java.net.SocketException
java.net.SocketOutputStream.socketWrite
580Web pages
SocketExceptionSocketOutputStream.socketWrite580

PlainSocketImpl.connect() has thrown an UnknownHostException

java.net.UnknownHostException
java.net.PlainSocketImpl.connect
556Web pages
UnknownHostExceptionPlainSocketImpl.connect556

Unable to resolve hostname while performing DNS lookup

java.net.UnknownHostException
java.net.Inet6AddressImpl.lookupAllHostAddr
492Web pages
UnknownHostExceptionInet6AddressImpl.lookupAllHostAddr492

InetAddress.getAllByName0() has thrown an UnknownHostException

java.net.UnknownHostException
java.net.InetAddress.getAllByName0
366Web pages
UnknownHostExceptionInetAddress.getAllByName0366

PlainSocketImpl.socketConnect() has thrown a SocketTimeoutException

java.net.SocketTimeoutException
java.net.PlainSocketImpl.socketConnect
353Web pages
SocketTimeoutExceptionPlainSocketImpl.socketConnect353

PlainSocketImpl.socketConnect() has thrown a SocketException

java.net.SocketException
java.net.PlainSocketImpl.socketConnect
313Web pages
SocketExceptionPlainSocketImpl.socketConnect313

PlainSocketImpl.socketAccept() has thrown a SocketException

java.net.SocketException
java.net.PlainSocketImpl.socketAccept
282Web pages
SocketExceptionPlainSocketImpl.socketAccept282

PlainSocketImpl.socketConnect() has thrown a NoRouteToHostException

java.net.NoRouteToHostException
java.net.PlainSocketImpl.socketConnect
261Web pages
NoRouteToHostExceptionPlainSocketImpl.socketConnect261

InetAddress.getLocalHost() has thrown an UnknownHostException

java.net.UnknownHostException
java.net.InetAddress.getLocalHost
221Web pages
1Solution
UnknownHostExceptionInetAddress.getLocalHost221

URI.create() has thrown an IllegalArgumentException

java.lang.IllegalArgumentException
java.net.URI.create
206Web pages
IllegalArgumentExceptionURI.create206

SocketInputStream.socketRead() has thrown a SocketException

java.net.SocketException
java.net.SocketInputStream.socketRead
192Web pages
SocketExceptionSocketInputStream.socketRead192

Android DNS unable to lookup host by name

java.net.UnknownHostException
java.net.InetAddress.lookupHostByName
164Web pages
1Solution
UnknownHostExceptionInetAddress.lookupHostByName164

PlainDatagramSocketImpl.send() has thrown an IOException

java.io.IOException
java.net.PlainDatagramSocketImpl.send
143Web pages
IOExceptionPlainDatagramSocketImpl.send143

SocketInputStream.socketRead0() has thrown a WebServiceException

javax.xml.ws.WebServiceException
java.net.SocketInputStream.socketRead0
137Web pages
WebServiceExceptionSocketInputStream.socketRead0137

PlainSocketImpl.read() has thrown a SocketTimeoutException

java.net.SocketTimeoutException
java.net.PlainSocketImpl.read
137Web pages
SocketTimeoutExceptionPlainSocketImpl.read137

Inet4AddressImpl.lookupAllHostAddr() has thrown an UnknownHostException

java.net.UnknownHostException
java.net.Inet4AddressImpl.lookupAllHostAddr
133Web pages
UnknownHostExceptionInet4AddressImpl.lookupAllHostAddr133

PlainDatagramSocketImpl.join() has thrown a SocketException

java.net.SocketException
java.net.PlainDatagramSocketImpl.join
117Web pages
SocketExceptionPlainDatagramSocketImpl.join117

PlainSocketImpl.socketBind() has thrown a SocketException

java.net.SocketException
java.net.PlainSocketImpl.socketBind
116Web pages
SocketExceptionPlainSocketImpl.socketBind116

Socket.createImpl() has thrown a SocketException

java.net.SocketException
java.net.Socket.createImpl
101Web pages
SocketExceptionSocket.createImpl101

PlainDatagramSocketImpl.bind0() has thrown a BindException

java.net.BindException
java.net.PlainDatagramSocketImpl.bind0
95Web pages
BindExceptionPlainDatagramSocketImpl.bind095

URLClassLoader$1.run() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
java.net.URLClassLoader$1.run
92Web pages
NoClassDefFoundErrorURLClassLoader$1.run92

URLDecoder.decode() has thrown an IllegalArgumentException

java.lang.IllegalArgumentException
java.net.URLDecoder.decode
91Web pages
IllegalArgumentExceptionURLDecoder.decode91

URLEncoder.encode() has thrown a NullPointerException

java.lang.NullPointerException
java.net.URLEncoder.encode
90Web pages
NullPointerExceptionURLEncoder.encode90

PlainSocketImpl.socketAccept() has thrown a SocketTimeoutException

java.net.SocketTimeoutException
java.net.PlainSocketImpl.socketAccept
89Web pages
SocketTimeoutExceptionPlainSocketImpl.socketAccept89

SocketOutputStream.socketWrite() has thrown an IOException

java.io.IOException
java.net.SocketOutputStream.socketWrite
89Web pages
IOExceptionSocketOutputStream.socketWrite89

URLClassLoader.defineClass() has thrown a SecurityException

java.lang.SecurityException
java.net.URLClassLoader.defineClass
79Web pages
SecurityExceptionURLClassLoader.defineClass79

URI.checkPath() has thrown an URISyntaxException

java.net.URISyntaxException
java.net.URI.checkPath
77Web pages
URISyntaxExceptionURI.checkPath77

InetSocketAddress.<init>() has thrown an IllegalArgumentException

java.lang.IllegalArgumentException
java.net.InetSocketAddress.<init>
71Web pages
IllegalArgumentExceptionInetSocketAddress.<init>71

URI$Parser.parse() has thrown a NullPointerException

java.lang.NullPointerException
java.net.URI$Parser.parse
70Web pages
NullPointerExceptionURI$Parser.parse70

URI.toURL() has thrown an IllegalArgumentException

java.lang.IllegalArgumentException
java.net.URI.toURL
69Web pages
IllegalArgumentExceptionURI.toURL69

SocketInputStream.socketRead() has thrown an InterruptedIOException

java.io.InterruptedIOException
java.net.SocketInputStream.socketRead
68Web pages
InterruptedIOExceptionSocketInputStream.socketRead68

PlainSocketImpl.socketConnect() has thrown a BindException

java.net.BindException
java.net.PlainSocketImpl.socketConnect
67Web pages
BindExceptionPlainSocketImpl.socketConnect67

URLClassLoader.findClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
1 frames hidden
java.net.URLClassLoader.findClass
63Web pages
ClassNotFoundExceptionURLClassLoader.findClass63

URLClassLoader.findClass() has thrown a Throwable

java.lang.Throwable
java.net.URLClassLoader.findClass
63Web pages
ThrowableURLClassLoader.findClass63

URLClassLoader$1.run() has thrown a Throwable

java.lang.Throwable
java.net.URLClassLoader$1.run
63Web pages
ThrowableURLClassLoader$1.run63

URLClassLoader.access$000() has thrown a Throwable

java.lang.Throwable
java.net.URLClassLoader.access$000
63Web pages
ThrowableURLClassLoader.access$00063

URLClassLoader.defineClass() has thrown a Throwable

java.lang.Throwable
java.net.URLClassLoader.defineClass
63Web pages
ThrowableURLClassLoader.defineClass63

SocksSocketImpl.connect() has thrown a SocketException

java.net.SocketException
java.net.SocksSocketImpl.connect
62Web pages
SocketExceptionSocksSocketImpl.connect62

SocksSocketImpl.readSocksReply() has thrown a SocketException

java.net.SocketException
java.net.SocksSocketImpl.readSocksReply
52Web pages
SocketExceptionSocksSocketImpl.readSocksReply52

PlainSocketImpl.socketSetOption() has thrown a SocketException

java.net.SocketException
java.net.PlainSocketImpl.socketSetOption
48Web pages
SocketExceptionPlainSocketImpl.socketSetOption48
Package namePatterns foundSolution coverageSummary coverage
java.lang40106
java.io3868
java.awt3604
java.util.concurrent3489
java.lang.reflect3445
sun.reflect2108
java.util2069
java.net2067
javax.swing1378
java.security851
javax.naming842
java.sql689
sun.net.www.protocol.http687
sun.net.www.protocol.https681
sun.nio.ch457
java.util.zip289
sun.rmi.server287
java.util.regex260
sun.rmi.transport.tcp259
java.nio.file257
com.sun.jndi.ldap243
com.sun.org.apache.xerces.internal.impl235
com.sun.org.apache.xerces.internal.parsers221
javax.swing.plaf.basic217
sun.net.www.http217
sun.misc179
java.util.stream179
java.util.logging153
com.sun.org.apache.xerces.internal.jaxp151
java.nio148
java.util.jar142
javax.swing.text141
sun.launcher138
java.beans137
java.text133
javax.imageio129
sun.rmi.registry127
javax.management.remote.rmi116
javax.security.auth.login115
javax.net.ssl114
java.rmi114
com.sun.org.apache.xalan.internal.xsltc.trax110
sun.nio.cs110
java.awt.image104
javax.security.auth98
sun.rmi.transport97
java.nio.channels95
sun.instrument92
java.util.concurrent.locks88
java.awt.event86
Package nameClass namePatterns foundSolution coverageSummary coverage
java.netSocket365
java.netURLClassLoader293
java.netURL259
java.netPlainSocketImpl158
java.netInetAddress153
java.netURLClassLoader$1114
java.netServerSocket110
java.netHttpURLConnection95
java.netDatagramSocket82
java.netSocketInputStream76
java.netURI53
java.netAbstractPlainSocketImpl48
java.netURLConnection47
java.netPlainDatagramSocketImpl30
java.netSocksSocketImpl24
java.netSocketOutputStream23
java.netMulticastSocket21
java.netURI$Parser17
java.netInetSocketAddress16
java.netNetworkInterface11
java.netInet6AddressImpl10
java.netURLEncoder6
java.netURLStreamHandler5
java.netURLClassLoader$25
java.netURLDecoder5
java.netInetAddress$15
java.netDatagramPacket5
java.netJarURLConnection3
java.netSocketPermission3
java.netIDN3
java.netSocketException2
java.netURLClassLoader$3$12
java.netHttpCookie2
java.netInetAddress$22
java.netAbstractPlainDatagramSocketImpl2
java.netURLPermission2
java.netInet4AddressImpl1
java.netProxySelector1
java.netURLClassLoader$41
java.netAuthenticator1
java.netURLClassLoader$31
java.netCookieHandler1
java.netHostPortrange1
java.netSocketPermission$11
java.netSocket$11
java.netInet6Address1
Package nameClass nameMethod namePatterns foundSolution coverage
java.netSocketconnect192
java.netURLopenStream162
java.netURLClassLoaderfindClass129
java.netURLClassLoader$1run114
java.netSocket<init>110
java.netHttpURLConnectiongetResponseCode91
java.netURLClassLoaderdefineClass86
java.netPlainSocketImplconnect59
java.netSocketInputStreamread57
java.netInetAddressgetAllByName52
java.netServerSocket<init>47
java.netURL<init>41
java.netURLopenConnection34
java.netURLClassLoaderaccess$10031
java.netInetAddressgetByName26
java.netServerSocketbind26
java.netDatagramSocket<init>25
java.netServerSocketaccept24
java.netInetAddressgetLocalHost23
java.netURIcreate22
java.netSocksSocketImplconnect22
java.netDatagramSocketreceive22
java.netDatagramSocketsend21
java.netPlainSocketImplsocketConnect20
java.netURI<init>20
java.netURLConnectiongetContentLength18
java.netAbstractPlainSocketImpldoConnect18
java.netInetAddresslookupHostByName16
java.netURLClassLoaderaccess$00016
java.netAbstractPlainSocketImplconnect15
java.netSocketOutputStreamwrite15
java.netURLConnectiongetContent13
java.netURLgetContent12
java.netInetSocketAddress<init>11
java.netPlainSocketImpldoConnect11
java.netServerSocketimplAccept11
java.netInetAddressgetAllByNameImpl10
java.netSocketInputStreamsocketRead010
java.netSocketstartupSocket10
java.netURLClassLoaderfindResource9
java.netMulticastSocketjoinGroup9
java.netInetAddressgetAllByName09
java.netAbstractPlainSocketImplconnectToAddress9
java.netPlainSocketImplbind9
java.netDatagramSocketbind9
java.netURI$Parserparse8
java.netURLClassLoadergetResourceAsStream8
java.netSocketsetSoTimeout8
java.netPlainDatagramSocketImplsend7
java.netInet6AddressImpllookupAllHostAddr7
Package nameClass nameMethod nameException TypePatterns foundSolution coverage
java.netSocketconnectConnectException57
java.netSocketconnectSocketException39
java.netInetAddressgetAllByNameUnknownHostException28
java.netPlainSocketImplconnectConnectException25
java.netURL<init>MalformedURLException25
java.netServerSocket<init>BindException25
java.netURLopenStreamFileNotFoundException24
java.netSocket<init>ConnectException23
java.netSocket<init>SocketException23
java.netURLopenStreamConnectException22
java.netHttpURLConnectiongetResponseCodeConnectException21
java.netURLopenStreamIOException21
java.netHttpURLConnectiongetResponseCodeSocketException20
java.netURLopenStreamUnknownHostException19
java.netURLClassLoaderdefineClassNoClassDefFoundError19
java.netURLClassLoaderfindClassSecurityException19
java.netURLClassLoaderfindClassNoClassDefFoundError18
java.netServerSocketbindBindException17
java.netSocketconnectUnknownHostException16
java.netInetAddressgetByNameUnknownHostException16
java.netSocketconnectSocketTimeoutException16
java.netURI<init>URISyntaxException16
java.netDatagramSocket<init>BindException15
java.netInetAddressgetLocalHostUnknownHostException15
java.netServerSocket<init>SocketException15
java.netURLClassLoader$1runNoClassDefFoundError14
java.netURIcreateIllegalArgumentException14
java.netSocketInputStreamreadSocketException13
java.netURLClassLoaderfindClassUnsupportedClassVersionError12
java.netSocket<init>UnknownHostException12
java.netHttpURLConnectiongetResponseCodeSocketTimeoutException11
java.netSocketInputStreamreadSocketTimeoutException11
java.netURLopenStreamSocketException11
java.netURLClassLoaderdefineClassSecurityException11
java.netSocketconnectNoRouteToHostException11
java.netServerSocketacceptSocketException11
java.netSocket<init>AccessControlException11
java.netURLClassLoaderfindClassClassFormatError10
java.netSocksSocketImplconnectConnectException10
java.netURLClassLoader$1runUnsupportedClassVersionError10
java.netURLClassLoaderfindClassClassNotFoundException10
java.netURLopenStreamStackOverflowError9
java.netDatagramSocketreceiveSocketException9
java.netDatagramSocket<init>SocketException9
java.netURLClassLoader$1runClassNotFoundException9
java.netURLClassLoaderdefineClassUnsupportedClassVersionError9
java.netAbstractPlainSocketImplconnectConnectException9
java.netAbstractPlainSocketImpldoConnectConnectException8
java.netURLopenStreamSSLHandshakeException8
java.netPlainSocketImplconnectSocketException8