Java Runtime errors

https://java.com

Core environment and runtime library

Documented:

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. ClassLoader.loadClass() has thrown a ClassNotFoundException
    No solution
  3. 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.


DescriptionException TypeEntry MethodWeb pages
LifecycleExceptionFutureTask.run397
RuntimeExceptionFutureTask.run198
IllegalStateExceptionFutureTask.run175
LifecycleExceptionFutureTask.run147
IllegalStateExceptionFutureTask.run82
IllegalStateExceptionFutureTask.run74
RuntimeExceptionFutureTask.run67
IllegalStateExceptionFutureTask.run65
FailedDownloadExceptionFutureTask.run55
ClassNotFoundExceptionFutureTask.run50
ClassNotFoundExceptionFutureTask.run48
IllegalStateExceptionFutureTask.run45
IllegalStateExceptionFutureTask.run45
ResolveExceptionFutureTask.run44
ExecutionExceptionFutureTask.run42
IllegalStateExceptionFutureTask.run42
Shell$ExitCodeExceptionFutureTask.run41
ClassNotFoundExceptionFutureTask.run41
LifecycleExecutionExceptionFutureTask.run40
ClassNotFoundExceptionFutureTask.run36
TimeoutExceptionFutureTask.run35
IllegalStateExceptionFutureTask.run35
IllegalStateExceptionFutureTask.run33
ClassNotFoundExceptionFutureTask.run32
ExecutionExceptionFutureTask.run32
IOExceptionFutureTask.run29
IOExceptionFutureTask.run28
ResolveExceptionFutureTask.run28
GitExceptionFutureTask.run27
IllegalStateExceptionFutureTask.run27
IllegalArgumentExceptionFutureTask.run26
GitExceptionFutureTask.run25
ClassNotFoundExceptionFutureTask.run24
IOExceptionFutureTask.run23
IOExceptionFutureTask.run22
ServiceConnectionLeakedFutureTask.run21
IOExceptionFutureTask.run21
AbortExceptionFutureTask.run21
ExecutionExceptionFutureTask.run20
EJBExceptionFutureTask.run20
AbortExceptionFutureTask.run20
NoSuchBeanDefinitionExceptionFutureTask.run19
GitExceptionFutureTask.run18
BeanDefinitionStoreExceptionFutureTask.run18
ResolveExceptionFutureTask.run16
NullPointerExceptionFutureTask.run16
TimeoutExceptionFutureTask.run16
LifecycleExceptionFutureTask.run15
BeanCreationExceptionFutureTask.run15
IllegalStateExceptionFutureTask.run15
Package nameClass namePatterns foundSolution coverageDescription coverage
java.util.concurrentThreadPoolExecutor$Worker1629
java.util.concurrentFutureTask945
java.util.concurrentExecutors$RunnableAdapter516
java.util.concurrentThreadPoolExecutor179
java.util.concurrentConcurrentHashMap35
java.util.concurrentScheduledThreadPoolExecutor$ScheduledFutureTask30
java.util.concurrentForkJoinTask25
java.util.concurrentLinkedBlockingQueue21
java.util.concurrentScheduledThreadPoolExecutor19
java.util.concurrentCompletableFuture17
java.util.concurrentAbstractExecutorService15
java.util.concurrentCountDownLatch13
java.util.concurrentExecutors$DelegatedExecutorService12
java.util.concurrentArrayBlockingQueue12
java.util.concurrentForkJoinPool10
java.util.concurrentConcurrentLinkedQueue9
java.util.concurrentCopyOnWriteArrayList8
java.util.concurrentSemaphore6
java.util.concurrentLinkedBlockingDeque6
java.util.concurrentConcurrentSkipListMap5
java.util.concurrentForkJoinWorkerThread5
java.util.concurrentTimeUnit5
java.util.concurrentForkJoinPool$WorkQueue4
java.util.concurrentExecutors$DefaultThreadFactory4
java.util.concurrentExecutorCompletionService4
java.util.concurrentExecutors$DelegatedScheduledExecutorService3
java.util.concurrentCyclicBarrier3
java.util.concurrentDelayQueue3
java.util.concurrentCompletableFuture$UniApply3
java.util.concurrentCopyOnWriteArrayList$COWSubList2
java.util.concurrentCompletableFuture$AsyncSupply2
java.util.concurrentConcurrentSkipListSet2
java.util.concurrentPriorityBlockingQueue2
java.util.concurrentExecutors2
java.util.concurrentConcurrentHashMap$Segment1
java.util.concurrentForkJoinWorkerThread$InnocuousForkJoinWorkerThread1
java.util.concurrentThreadPoolExecutor$AbortPolicy1
java.util.concurrentCopyOnWriteArrayList$COWIterator1
java.util.concurrentSynchronousQueue1
java.util.concurrentConcurrentSkipListMap$Iter1
java.util.concurrentConcurrentSkipListMap$ValueIterator1
java.util.concurrentCompletableFuture$UniCompose1
java.util.concurrentCopyOnWriteArrayList$CowIterator1
java.util.concurrentConcurrentHashMap$ValuesView1
java.util.concurrentTimeUnit$31
java.util.concurrentConcurrentMap1
java.util.concurrentCompletableFuture$BiApply1
java.util.concurrentCopyOnWriteArraySet1
java.util.concurrentPhaser1
java.util.concurrentExecutors$PrivilegedCallable1
Package nameClass nameMethod namePatterns foundSolution coverage
java.util.concurrentFutureTaskrun846
java.util.concurrentFutureTaskget54
java.util.concurrentFutureTaskrunAndReset32
java.util.concurrentFutureTaskreport6
java.util.concurrentFutureTasksetException3
java.util.concurrentFutureTaskfinishCompletion2
java.util.concurrentFutureTaskawaitDone1
java.util.concurrentFutureTask<init>1
Package nameClass nameMethod nameException TypePatterns foundSolution coverage
java.util.concurrentFutureTaskrunNullPointerException91
java.util.concurrentFutureTaskrunRuntimeException58
java.util.concurrentFutureTaskrunIllegalStateException56
java.util.concurrentFutureTaskrunIOException49
java.util.concurrentFutureTaskrunLifecycleException36
java.util.concurrentFutureTaskrunSolrException24
java.util.concurrentFutureTaskrunExecutionException23
java.util.concurrentFutureTaskrunClassNotFoundException22
java.util.concurrentFutureTaskrunNoClassDefFoundError20
java.util.concurrentFutureTaskrunIllegalArgumentException20
java.util.concurrentFutureTaskrunBeanCreationException19
java.util.concurrentFutureTaskrunIOException212
java.util.concurrentFutureTaskrunSQLException12
java.util.concurrentFutureTaskrunAssertionError11
java.util.concurrentFutureTaskrunExternalSystemException11
java.util.concurrentFutureTaskrunArrayIndexOutOfBoundsException10
java.util.concurrentFutureTaskrunOfficeException10
java.util.concurrentFutureTaskrunOutOfMemoryError8
java.util.concurrentFutureTaskrunClassCastException8
java.util.concurrentFutureTaskrunThrowable8
java.util.concurrentFutureTaskrunFileNotFoundException8
java.util.concurrentFutureTaskrunLifecycleExecutionException7
java.util.concurrentFutureTaskrunGitException7
java.util.concurrentFutureTaskrunTimeoutException6
java.util.concurrentFutureTaskrunSQLiteException6
java.util.concurrentFutureTaskrunNoSuchMethodError6
java.util.concurrentFutureTaskrunIndexOutOfBoundsException6
java.util.concurrentFutureTaskrunEOFException6
java.util.concurrentFutureTaskrunException5
java.util.concurrentFutureTaskrunBeanDefinitionStoreException5
java.util.concurrentFutureTaskrunRackInitializationException4
java.util.concurrentFutureTaskrunResolveException4
java.util.concurrentFutureTaskrunUnsatisfiedLinkError4
java.util.concurrentFutureTaskrunJSONException4
java.util.concurrentFutureTaskrunVoldemortException4
java.util.concurrentFutureTaskrunLifecycleException4
java.util.concurrentFutureTaskrunSocketTimeoutException4
java.util.concurrentFutureTaskrunSecurityException4
java.util.concurrentFutureTaskrunFault4
java.util.concurrentFutureTaskrunNotSerializableException4
java.util.concurrentFutureTaskrunHttpResponseException3
java.util.concurrentFutureTaskrunJsonSyntaxException3
java.util.concurrentFutureTaskrunContainerException3
java.util.concurrentFutureTaskrunNameNotFoundException3
java.util.concurrentFutureTaskrunNoSuchBeanDefinitionException3
java.util.concurrentFutureTaskrunFlowException3
java.util.concurrentFutureTaskrunStringIndexOutOfBoundsException3
java.util.concurrentFutureTaskrunSVNException3
java.util.concurrentFutureTaskrunConcurrentModificationException3
java.util.concurrentFutureTaskrunUnsupportedOperationException3