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
6799Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6799

The class could not be found

java.lang.ClassNotFoundException
java.net.URLClassLoader.findClass
6302Web pages
1Solution
ClassNotFoundExceptionURLClassLoader.findClass6302

Java Runtime cannot connect a network socket

java.net.ConnectException
java.net.PlainSocketImpl.socketConnect
4901Web pages
1Solution
ConnectExceptionPlainSocketImpl.socketConnect4901

Launcher$AppClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
4 frames hidden
sun.misc.Launcher$AppClassLoader.loadClass
4433Web pages
ClassNotFoundExceptionLauncher$AppClassLoader.loadClass4433

NumberFormatException.forInputString() has thrown a NumberFormatException

java.lang.NumberFormatException
java.lang.NumberFormatException.forInputString
4388Web pages
1Solution
NumberFormatExceptionNumberFormatException.forInputString4388

Failed to load the class from current classpath

java.lang.ClassNotFoundException
5 frames hidden
java.lang.ClassLoader.loadClass
4387Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass4387

Launcher$AppClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
2 frames hidden
sun.misc.Launcher$AppClassLoader.loadClass
4221Web pages
ClassNotFoundExceptionLauncher$AppClassLoader.loadClass4221

ClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
3 frames hidden
java.lang.ClassLoader.loadClass
4206Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass4206

Launcher$AppClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
5 frames hidden
sun.misc.Launcher$AppClassLoader.loadClass
4180Web pages
ClassNotFoundExceptionLauncher$AppClassLoader.loadClass4180

Failed to load the class from current classpath

java.lang.ClassNotFoundException
6 frames hidden
java.lang.ClassLoader.loadClass
4165Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass4165

FileInputStream.open() has thrown a FileNotFoundException

java.io.FileNotFoundException
java.io.FileInputStream.open
3729Web pages
1Solution
FileNotFoundExceptionFileInputStream.open3729

AccessControlContext.checkPermission() has thrown an AccessControlException

java.security.AccessControlException
java.security.AccessControlContext.checkPermission
3668Web pages
AccessControlExceptionAccessControlContext.checkPermission3668

AccessController.checkPermission() has thrown an AccessControlException

java.security.AccessControlException
1 frames hidden
java.security.AccessController.checkPermission
3517Web pages
AccessControlExceptionAccessController.checkPermission3517

Integer.parseInt() has thrown a NumberFormatException

java.lang.NumberFormatException
1 frames hidden
java.lang.Integer.parseInt
3466Web pages
NumberFormatExceptionInteger.parseInt3466

FileInputStream.<init>() has thrown a FileNotFoundException

java.io.FileNotFoundException
1 frames hidden
java.io.FileInputStream.<init>
3352Web pages
FileNotFoundExceptionFileInputStream.<init>3352

SecurityManager.checkPermission() has thrown an AccessControlException

java.security.AccessControlException
2 frames hidden
java.lang.SecurityManager.checkPermission
3283Web pages
AccessControlExceptionSecurityManager.checkPermission3283

ClassLoader.defineClass1() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
java.lang.ClassLoader.defineClass1
3050Web pages
UnsupportedClassVersionErrorClassLoader.defineClass13050

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

Integer.parseInt() has thrown a NumberFormatException

java.lang.NumberFormatException
2 frames hidden
java.lang.Integer.parseInt
2676Web pages
1Solution
NumberFormatExceptionInteger.parseInt2676

String.substring() has thrown a StringIndexOutOfBoundsException

java.lang.StringIndexOutOfBoundsException
java.lang.String.substring
2410Web pages
1Solution
StringIndexOutOfBoundsExceptionString.substring2410

ClassLoader.defineClass1() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
java.lang.ClassLoader.defineClass1
2311Web pages
1Solution
NoClassDefFoundErrorClassLoader.defineClass12311

ClassLoader.loadLibrary() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader.loadLibrary
2261Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary2261

ArrayList.rangeCheck() has thrown an IndexOutOfBoundsException

java.lang.IndexOutOfBoundsException
java.util.ArrayList.rangeCheck
2140Web pages
IndexOutOfBoundsExceptionArrayList.rangeCheck2140

ClassLoader$NativeLibrary.load() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
java.lang.ClassLoader$NativeLibrary.load
2128Web pages
1Solution
UnsatisfiedLinkErrorClassLoader$NativeLibrary.load2128

SocketInputStream.read() has thrown a SocketException

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

ClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
1 frames hidden
java.lang.ClassLoader.loadClass
2043Web pages
ClassNotFoundExceptionClassLoader.loadClass2043

Runtime.loadLibrary0() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
1 frames hidden
java.lang.Runtime.loadLibrary0
2031Web pages
UnsatisfiedLinkErrorRuntime.loadLibrary02031

ClassLoader.loadClass() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
2 frames hidden
java.lang.ClassLoader.loadClass
2028Web pages
1Solution
ClassNotFoundExceptionClassLoader.loadClass2028

FileOutputStream.open() has thrown a FileNotFoundException

java.io.FileNotFoundException
java.io.FileOutputStream.open
2020Web pages
FileNotFoundExceptionFileOutputStream.open2020

System.loadLibrary() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
2 frames hidden
java.lang.System.loadLibrary
2016Web pages
UnsatisfiedLinkErrorSystem.loadLibrary2016

ArrayList.get() has thrown an IndexOutOfBoundsException

java.lang.IndexOutOfBoundsException
1 frames hidden
java.util.ArrayList.get
1965Web pages
1Solution
IndexOutOfBoundsExceptionArrayList.get1965

SocketOutputStream.socketWrite0() has thrown a SocketException

java.net.SocketException
java.net.SocketOutputStream.socketWrite0
1960Web pages
SocketExceptionSocketOutputStream.socketWrite01960

ClassLoader.defineClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
1 frames hidden
java.lang.ClassLoader.defineClass
1959Web pages
1Solution
UnsupportedClassVersionErrorClassLoader.defineClass1959

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
1908Web pages
SocketExceptionSocketOutputStream.socketWrite1908

SocketOutputStream.write() has thrown a SocketException

java.net.SocketException
2 frames hidden
java.net.SocketOutputStream.write
1895Web pages
1Solution
SocketExceptionSocketOutputStream.write1895

AbstractPlainSocketImpl.doConnect() has thrown a ConnectException

java.net.ConnectException
1 frames hidden
java.net.AbstractPlainSocketImpl.doConnect
1885Web pages
ConnectExceptionAbstractPlainSocketImpl.doConnect1885

AbstractPlainSocketImpl.connectToAddress() has thrown a ConnectException

java.net.ConnectException
2 frames hidden
java.net.AbstractPlainSocketImpl.connectToAddress
1870Web pages
ConnectExceptionAbstractPlainSocketImpl.connectToAddress1870

AbstractPlainSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
3 frames hidden
java.net.AbstractPlainSocketImpl.connect
1861Web pages
ConnectExceptionAbstractPlainSocketImpl.connect1861

SocksSocketImpl.connect() has thrown a ConnectException

java.net.ConnectException
4 frames hidden
java.net.SocksSocketImpl.connect
1835Web pages
ConnectExceptionSocksSocketImpl.connect1835

FileOutputStream.<init>() has thrown a FileNotFoundException

java.io.FileNotFoundException
1 frames hidden
java.io.FileOutputStream.<init>
1821Web pages
FileNotFoundExceptionFileOutputStream.<init>1821

Java Runtime cannot connect a network socket

java.net.ConnectException
5 frames hidden
java.net.Socket.connect
1819Web pages
1Solution
ConnectExceptionSocket.connect1819

SecureClassLoader.defineClass() has thrown an UnsupportedClassVersionError

java.lang.UnsupportedClassVersionError
2 frames hidden
java.security.SecureClassLoader.defineClass
1761Web pages
UnsupportedClassVersionErrorSecureClassLoader.defineClass1761

ClassLoader.loadLibrary0() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
1 frames hidden
java.lang.ClassLoader.loadLibrary0
1755Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary01755

ClassLoader.defineClass() has thrown a NoClassDefFoundError

java.lang.NoClassDefFoundError
1 frames hidden
java.lang.ClassLoader.defineClass
1750Web pages
NoClassDefFoundErrorClassLoader.defineClass1750

ClassLoader.loadClassInternal() has thrown a ClassNotFoundException

java.lang.ClassNotFoundException
6 frames hidden
java.lang.ClassLoader.loadClassInternal
1748Web pages
ClassNotFoundExceptionClassLoader.loadClassInternal1748

ClassLoader.loadLibrary() has thrown an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError
2 frames hidden
java.lang.ClassLoader.loadLibrary
1741Web pages
UnsatisfiedLinkErrorClassLoader.loadLibrary1741
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.lang.reflectMethod3218
java.langClassLoader2678
java.langClass2157
java.util.concurrentThreadPoolExecutor$Worker2093
java.langThread1300
sun.reflectNativeMethodAccessorImpl1262
java.ioObjectInputStream1201
java.util.concurrentFutureTask1108
javax.namingInitialContext1006
java.sqlDriverManager781
java.awtEventQueue727
java.util.concurrentExecutors$RunnableAdapter703
sun.net.www.protocol.httpHttpURLConnection635
java.lang.reflectConstructor617
java.securityAccessController612
java.ioObjectOutputStream600
javax.swingJComponent546
sun.reflectDelegatingMethodAccessorImpl455
java.awtEventDispatchThread447
java.netSocket403
sun.net.www.protocol.httpsHttpsURLConnectionImpl401
sun.reflectNativeConstructorAccessorImpl338
java.netURLClassLoader334
java.langString320
java.awtContainer318
java.ioBufferedInputStream287
java.netURL286
java.awtComponent284
java.langThrowable278
java.util.concurrentThreadPoolExecutor268
sun.rmi.serverUnicastRef252
sun.net.www.httpHttpClient245
sun.net.www.protocol.httpsAbstractDelegateHttpsURLConnection239
java.ioBufferedOutputStream234
java.nio.fileFiles203
java.ioFile202
java.utilArrayList188
java.ioBufferedReader187
java.ioDataInputStream179
java.langSystem172
java.utilArrays169
java.ioFilterInputStream161
java.netPlainSocketImpl157
java.netInetAddress154
java.netURLClassLoader$1152
java.langRuntime146
java.utilHashMap142
com.sun.jndi.ldapLdapCtx140
sun.rmi.registryRegistryImpl_Stub135
java.util.concurrentForkJoinTask126
Package nameClass nameMethod namePatterns foundSolution coverage
java.lang.reflectMethodinvoke3083
java.util.concurrentThreadPoolExecutor$Workerrun2067
java.langClassLoaderloadClass1833
java.langThreadrun1177
java.util.concurrentFutureTaskrun1007
sun.reflectNativeMethodAccessorImplinvoke0795
java.sqlDriverManagergetConnection760
java.langClassforName758
java.util.concurrentExecutors$RunnableAdaptercall703
java.lang.reflectConstructornewInstance609
java.securityAccessControllerdoPrivileged594
javax.namingInitialContextlookup586
sun.reflectNativeMethodAccessorImplinvoke467
sun.reflectDelegatingMethodAccessorImplinvoke455
java.ioObjectInputStreamreadObject409
java.langClassLoaderloadClassInternal378
java.ioObjectInputStreamreadObject0376
java.awtEventQueuedispatchEvent361
java.awtEventQueuedispatchEventImpl304
sun.net.www.protocol.httpHttpURLConnectiongetInputStream291
java.langClassnewInstance286
javax.swingJComponentpaint262
java.awtEventDispatchThreadpumpEvents245
javax.namingInitialContext<init>234
java.ioObjectOutputStreamwriteObject0227
sun.reflectNativeConstructorAccessorImplnewInstance0220
sun.net.www.protocol.httpsAbstractDelegateHttpsURLConnectionconnect212
java.util.concurrentThreadPoolExecutorrunWorker210
java.netSocketconnect201
java.ioObjectOutputStreamwriteObject198
java.langClassLoaderdefineClass186
java.netURLopenStream183
java.ioBufferedInputStreamread179
sun.rmi.serverUnicastRefinvoke179
java.netURLClassLoaderfindClass154
java.netURLClassLoader$1run152
java.awtComponentdispatchEvent146
java.ioFilterInputStreamread141
sun.net.www.httpHttpClientopenServer125
sun.net.www.protocol.httpsHttpsURLConnectionImplgetInputStream125
java.netSocket<init>125
sun.reflectNativeConstructorAccessorImplnewInstance118
java.util.concurrentForkJoinTaskdoExec117
java.awt.eventInvocationEventdispatch116
java.ioBufferedReaderreadLine113
java.langThrowable<init>112
java.langClassprivateGetDeclaredMethods110
java.netHttpURLConnectiongetResponseCode109
java.ioBufferedOutputStreamflush108
sun.net.www.protocol.httpsHttpsURLConnectionImplgetOutputStream103
Package nameClass nameMethod nameException TypePatterns foundSolution coverage
java.langClassLoaderloadClassClassNotFoundException531
java.lang.reflectMethodinvokeNullPointerException405
java.langClassLoaderloadClassNoClassDefFoundError349
java.sqlDriverManagergetConnectionSQLException273
java.lang.reflectMethodinvokeIllegalStateException264
java.langClassforNameClassNotFoundException254
java.util.concurrentThreadPoolExecutor$WorkerrunNullPointerException242
java.lang.reflectMethodinvokeRuntimeException217
javax.namingInitialContextlookupNameNotFoundException170
java.lang.reflectMethodinvokeIllegalArgumentException166
java.langClassforNameNoClassDefFoundError159
java.util.concurrentThreadPoolExecutor$WorkerrunIOException154
java.lang.reflectMethodinvokeInvocationTargetException153
java.ioObjectOutputStreamwriteObject0NotSerializableException144
java.ioObjectOutputStreamwriteObjectNotSerializableException138
java.util.concurrentThreadPoolExecutor$WorkerrunIllegalStateException123
javax.namingInitialContextlookupNamingException123
java.awtEventQueuedispatchEventNullPointerException122
java.util.concurrentExecutors$RunnableAdaptercallRuntimeException117
java.ioObjectInputStreamreadObjectClassNotFoundException114
java.langClassLoaderloadClassUnsupportedClassVersionError110
java.langClassLoaderloadClassInternalClassNotFoundException99
java.ioObjectInputStreamreadObject0ClassNotFoundException93
java.util.concurrentFutureTaskrunNullPointerException92
javax.swingJComponentpaintNullPointerException92
java.lang.reflectMethodinvokeNoClassDefFoundError91
sun.reflectNativeMethodAccessorImplinvoke0NullPointerException91
java.langClassLoaderloadClassSecurityException90
java.langClassnewInstanceNoClassDefFoundError83
java.langClassLoaderloadClassClassFormatError74
java.util.concurrentThreadPoolExecutor$WorkerrunIllegalArgumentException73
java.langClassLoaderloadClassInternalNoClassDefFoundError71
java.awtEventDispatchThreadpumpEventsNullPointerException71
java.langRuntimeexecIOException70
java.util.concurrentThreadPoolExecutor$WorkerrunRuntimeException69
java.lang.reflectMethodinvokeIOException66
java.langClassgetDeclaredMethodsNoClassDefFoundError65
java.langClassprivateGetDeclaredMethodsNoClassDefFoundError65
java.awtEventQueuedispatchEventImplNullPointerException64
java.util.concurrentFutureTaskrunIOException62
java.langThreadrunIOException62
java.util.concurrentFutureTaskrunIllegalStateException62
sun.net.www.protocol.httpsAbstractDelegateHttpsURLConnectionconnectSSLHandshakeException61
java.ioObjectInputStreamreadObjectInvalidClassException61
java.util.concurrentFutureTaskrunRuntimeException60
javax.swingJComponentpaintArrayIndexOutOfBoundsException60
java.lang.reflectMethodinvokeNoSuchMethodError60
java.lang.reflectConstructornewInstanceInvocationTargetException59
java.langThreadrunNullPointerException58
java.securityAccessControllerdoPrivilegedNullPointerException58